Skip navigation.
KDE Developer's Journals

To byte code, or NOT to byte code? Is this really the question?

manyoso's picture

It seems Trolltech is continuing to wrestle with the problem of pesky developers clamoring for bytecode based (read: higher level) languages. I talked with him quite a bit about this at the recent LinuxWorld in New York, so I know it is on his mind. In his recent interview at aKademy, Matthias even identified this as the "next big thing" for KDE. But, is bytecode really the question? Read on.



Q: What do you think the "next big thing" in KDE will be?



MATTHIAS: There is one thing that will become increasingly important in the future, not just for KDE, but for all of Linux: a convincing answer to Microsoft's .Net. I'm not concerned about the server, I'm concerned about the client...



Still it would be nice to take advantage of JIT-compiled bytecode where it makes sense, and have the two worlds interoperate. Currently there are two technical options: integrating Mono and the CLR, or going for a Java Virtual Machine. Mono at present has several advantages: First, there is no free JIT-compiling JVM that is equally actively developed and it doesn't look like there will be one. Second, cooperating with Miguel and the Ximian group at Novell is probably a lot easier than cooperating with Sun. And third, it is easier to integrate native C++ code with the CLR than going through the JNI.




To me, the real thing TT should be concerned about isn't so much nativecode VS bytecode... it is how to satisfy those pesky developers clamoring for higher level language access to Qt/KDE API's. I *think* this is what TT had in mind creating QSA, but that is only a scripting language. Ultimately, there are three niches of development I think TT needs to cater to:

  1. A native systems programming language eg, C++. 'Nuff said.
  2. A modern high level programming language eg, Java, C#.
  3. Scripting support. TT does QSA and KDE does KJSEmbed.

Obviously, TT does a phenomenal job with the first one and the third seems adequately addressed. The big glaring hole is the mid-level option. I don't doubt that TT is feeling some pressure from customers interested in programming Qt against the .NET API's. Probably more so from the Windows world, but also from Linux via Mono/Portable.NET. I know TT responded with AWT bindings for java developers wishing to program to the qtopia mobile phone platform.



The existing options for the mid-level niche all royally *suck*, IMO. Let's take a look: pyqt, qtjava, Qt#...



First, they are all bindings and -- let's face it -- bindings *suck*. They suck for performance reasons, maintenance reasons and compatibility reasons. All the bindings require every virtual method in every library to be reimplemented. What's worse, they require an objects entire inheritance tree of virtual methods to be overridden, not just the ones declared by that object. Some require every method *period* to have a proxy C linkage. You have huge glue libraries, whether they be SMOKE, SWIG, QtC or libqtsharpglue.so. Mapping to and from the object heirarchies of the various languages can also be a pain. Q_PROPERTY VS C# style properties. Signals/Slots VS delegates/events. And then to add insult to injury, the various bindings seem like they are always behind. Second class citizens in a c/c++ dominated world.



Now, I do the Qt# stuff and I have a great time doing it. It is a fun project and we're making good progress. But, I won't kid myself into thinking this is a truly adequate solution to the problem. It is what works now, though, and I'll continue with it unless and until TT provides some direction towards moving to a truly useful mid-level niche. What might that direction look like? A few options that I can see:

  1. Build a c++ compiler targetting the CLR according to the proposed ECMA standard.
  2. Create a new high level language with transparent link compatibility with c++.
  3. Target the LLVM project and extend the frontends so they can link to and from each other via LLVM mid-level IR.
  4. TT could support and maintain one of the bindings themselves. Conditioned upon changes to Qt that would make the binding a first class citizen.

All of these have potentially significant problems and hurdles.



The first option has some potential legal/licensing questions and quite a number of technical hurdles. Managed c++ is quite different from the Standard c++ that we are all accustomed to. How would it work around moc and all its various goodies?? Q_PROPERTY, signals/slots etc, etc. Either way, this would require extensive modifications to the Qt library itself and probably couldn't even be considered until the Qt5 time frame.



The second option is one that I was persuing myself for a brief time earlier this year. I called the attempt 'k++' Smiling The idea was to build a java/c# like compiler that would have the binding 'built-in', so to speak. I was using a modified g++ frontend as the template and taking cues from gcj's CNI and Apple's Objective-C++ projects. Alas, mucking about with the internals of the gcc codebase was to much for me to stand. The entire compiler suite is using antiquated compiler technology and it's very difficult to modify without substantial changes. Still, I suppose TT could manage the resources -- if it had the will -- to pull off such a feat. The big drawback is that this is not a bytecode based solution. I'll get to that in a minute.



The third option is one I just thought about after seeing the recent slashdot article on LLVM. They seem to have a pretty intersting project. They already have extracted the g++ 3.4 frontend and retargetted it to produce their LLVM bytecode. They already have a jit. Now, if a java/c# like frontend were to come along and target LLVM bytecode then the remaining hurdle would be to provide a construct that the various frontends could use to parse the bytecode and provide syntax/linking information. Basically, recreating Microsoft's CLR idea by using the LLVM project as a jumping off point. I have no idea how feasible this is, but I just came across it and it seems interesting.



The fourth option is probably the easiest, but it is also the lousiest as far as technical solutions. If TT itself were to back and maintain one of the existing bindings projects... amd give it as much priority as the native c++ library, I suppose an adequate solution could be had. You'd still have large glue libraries and that'd make it less desirable for the embedded market. But, if it received the level of attention the regular c++ library gets...?? Of course, unlike the other solutions this wouldn't necessarily extend naturally to KDE API's.



As for the bytecode question, I see only a few reasons for its existance. In order of significance:

  1. A basis for a Common Language Runtime. It's either this or you can build the binding into the compiler.
  2. Sandboxing is the big one. As geiseri would say, "This should be done in hardware!", but it isn't.
  3. "Write once, blah blah." I can get all the cross-platform I need through careful coding and the gcc compiler suite.
  4. Finally, some theoretical performance optimizations over nativecode that no one (so far) has been successful in delivering.

I can't think of any other reasons. The first two are legitimate if you are looking for that kind of functionality. The last two I don't have any concern for.



Bytecode or not, I do think Matthias is correct in identifying these various issues as particularly prominent for the future of KDE/Qt. I don't know how or when TT will respond with some solutions or guidance... I don't know if they think it is worth the hassle... but, I'm very excited and curious to find out. In the meantime, I'll continue with Qt# so clee can write dotNET in .NET Eye-wink



Next up? An update and a history for those who want to know what is going on with c# language bindings for KDE/Qt.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
segedunum's picture

Please - No Paranoia

Really, the worst Trolltech and KDE can do is get paranoid about managed environments.

Yes, I certainly think Trolltech is under some pressure to make Qt easier to use at a higher level (C#, Java, desktop level) and a managed environment is an interesting way of doing this, but I worry about statements such as "an answer to .Net". I don't think getting worried about this is the answer, as this should be seen as a challenge and a pleasure to do. As a toolkit, Qt has everything required to make people productive at a higher, desktop level, over and above any version of .Net - version 2.0 or otherwise (have you tried to do any kind of layout or text management in .Net?) This will open up a great deal of possibilities for Trolltech, Qt and KDE. It would extend the range of Qt way beyond how it is currently used.

Now, how to do it. I have yet to be convinced about managed code and how easy it makes things. I also want to see real world benchmarks of how fast managed code is, and how much resources it takes up. Running a simple algorithm and benchmarking it is one thing, running six or seven applications with thousands of lines of code in them together is quite another.

People have had Visual Basic for development at this level for years, and have never needed a managed runtime environment for anything (Java was created to solve cross-platform difficulties). Through good tools and programmer support, native code is still the mainstay of any desktop environment - no matter how cool I think managed code is, or how cool having a compiler written in C# compiling itself is. Having a C++ compiler targetting the CLR is pointless - what would programmers or end users get out of it, apart from some hype?

Matthias Ettrich's comments just sounded like fear and a reaction to something else, rather than a pragmatic think about how the joys of Qt programming could be introduced to higher level programmers. If they think about it in those terms, rather than a clamour to .Net, then I think they'll really have something.

manyoso's picture

Spot the paranoia!

There is no paranoia in the above. Matthias just recognizes that this is an up and coming issue for Qt and KDE. For sure, Qt/KDE already provide a wonderful desktop development environment, but it could be made better. A mid-level option for high level programming languages like Java and C# is one such way to improve it, at least for developers who wish to use such languages.

I suggest you reread the post as you've fallen for the whole bytecode question when it isn't really the issue. The problem I would like addressed is options for higher level languages. Managed or not.

As for the efficacy of a C++ compiler targetting the CLR, it seems you've missed the point entirely. The value of such a compiler would be the ability to use the produced library from other languages supported by the CLR such as C#.

segedunum's picture

For sure, Qt/KDE already prov

For sure, Qt/KDE already provide a wonderful desktop development environment, but it could be made better. A mid-level option for high level programming languages like Java and C# is one such way to improve it, at least for developers who wish to use such languages.

That's what is currently missing.

I suggest you reread the post as you’ve fallen for the whole bytecode question when it isn’t really the issue.

Couldn't care a less about bytecode, as that's not what I wrote. When other people talk about constantly about how good managed code is, at times, I question how useful it really is.

The problem I would like addressed is options for higher level languages. Managed or not.

Wouldn't we all. I think Qt would be an even more fantastic toolkit if targetted fully to a good higher level language like C#. I don't think we'd have too many problems with .Net if that happened. However, with bindings, as you've pointed out, things are never going to be that great.

As for the efficacy of a C++ compiler targetting the CLR, it seems you’ve missed the point entirely. The value of such a compiler would be the ability to use the produced library from other languages supported by the CLR such as C#.

Mmm, nice in theory, but in practice it never works out like that. The vast majority of people will be using C# and VB within a .Net environment, Mono or otherwise. They are the languages best suited for the environment. C++ is a language best suited for native compiling (and Trolltech will still have to bridge native and managed code, however great the cross-language possibilities are with the CLR). The value seems great in theory, but in practice it always works out to be less so with these things.

jas's picture

whirl2il

Have you heard about the whirl2il project. it is simulair to your llvm idea. But he uses the Open64 compiler and whirl instead of llvm .

manyoso's picture

Actually

The whirl2il project is similar to option #1. Creating a Free managed c++ compiler for Linux systems. From their homepage:

"Final project is adding support for managed C++ to the Open64 compiler, so we get a fully open source managed C++ compiler."

This is different from the LLVM option because with that I was suggesting a full fledged alternative to the CLR itself. A lot of work, but it looks as if much of it has already been accomplished by the LLVM folks.

jpraher's picture

CLR alternative

hi manyoso,

i am very interested in an alternative to the clr.
what i'd like to see is a common vm for different bytecodes, where we share the core infrastructure among all bytecode frontends.

i've a little experience using llvm, but it would be interesting to see how many people would join such an effort Smiling

-- jakob

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.