Manage code yourself
Those who know me know it well that I am not a big fan of languages which produce managed code. In this article I would like to cover the reasons behind my skepticism. Also I would like to dispel the myths around such languages and try to prove them with facts (we will see how well I manage to achieve this). If you disagree with me, you’ll most probably hate me because of making this post but please, respect my personal point of view.
As I’ll mostly talk in this post in general about managed code I would like to emphasize that I have worthwhile experience only with Java and have barely used C# and other managed languages so my primary arguments maybe apply directly only to Java but still would like to present my arguments in general as they still apply in some way to all such languages.
Without the intension to insult anybody, I would like to start with a citation from one of my friends, who often says that “Java is just a pseudo-language”. Mostly I agree with him and it’s not just because I have my not so delightful experiences with the language but also because it introduced a brand new way of coding style that is a complete nightmare for an old-school coder like me. As I don’t want to start another religious war, I’ll stop my preposterous arguments here as I would like to prove my concerns with facts that nobody can disclaim.
“… nowadays Java is almost as fast as native code…”
This used to be a common myth in the last few years. For those who are still arguing by shouting this loud on forums and blogs, I would like to draw their attention to the fact that Java is still an interpreted language no matter if the latest JVM versions do some on-the-fly compilation of the code and as such it is inherently slower than any language that generates native code.
As my hobby is computer graphics I have to talk a bit about the case of PC games. Have anybody seen a game fully written in Java or any other interpreter based language that produces state-of-the-art graphics which competes with the best professional games and it also provides the same performance? I think not, and this is not a coincidence.
GPUs are getting more horsepower in a much faster pace than CPUs. That is what resulted in the batch crisis lately. It’s already happening for several years that the CPU is simply not powerful enough to feed the GPU with enough data in complex real-time rendering situations. There have been already tons of different software and hardware technologies which already targeted this issue a long time ago but as a perfect example that is the reason which resulted in the appearance of the completely redesigned DirectX 10 API and which emerged the need for a cleaner architecture for OpenGL as well. That’s why there are no advanced games written in interpreted languages as they waste those very valuable CPU cycles which would have great benefits otherwise.
“… Java has a much greater expression power…”
I tend to agree with this one. As these languages are interpreted by a virtual machine they provide great room for such features that would be impossible or simply very inefficient in a native language. That’s why one of my favorite programming language is PHP as an example. It is even more flexible then Java, for example, but never forget that PHP never meant to try to replace native languages as instead it is used in a totally different domain.
There are many language features that are not available in native languages but they weren’t left out unintentionally. Their lack is primarily justified by the fact that most of these features are rather inefficient and they simply not fit in the philosophy of a performance oriented language like C++. However, the most important ones like reflection, delegates and most OOP related facilities are present for example in Delphi, which is one if not the best OOP language that doesn’t make too much trade of between flexibility and run-time performance. Also, even if most of these features are not present in C++, Objective-C and other popular native languages, they can be made available with a little programming knowledge in the particular language (maybe not just little).
“… you don’t have to care about resource deallocation as there is the garbage collector…”
This is one of the most annoying “features” of managed code based languages. I understand that the prevention of memory leaks can have a great impact on development effort, however the unpredictable behavior of garbage collectors is simply unacceptable in certain situations. The issue of lost references has been already addressed in almost all native languages with the use of reference counted objects so I simply don’t get it why is this still an important feature. For efficient resource management you need much finer control over the time and way how resources are released.
“… you just have to care about the basics and Java will make you the rest…”
While I strongly support the idea of COTS, the way how Java and friends interprets this concept is simply unacceptable for me. Sometimes you need to know what is going on under-the-hood. This is basically the same issue like that of the garbage collector. Beside that, according to my personal taste, I don’t like if the compiler tells me how to do a particular thing. I rather do it in my way and even if I tend to agree that the compile time static analysis what the Java compiler does can be very valuable in some situations, simply denying code generation even in the case of a very minor semantic problem is simply makes me angry.
“… Java eliminated almost all unsafe features inherited from C++…”
This is one of the things that hurts me most. While Java really managed to achieve this, it sacrificed flexibility, ease of use and the fun of programming to make this possible. One such removed feature is operator overloading. I love them! As an example a linear algebraic library, which is often used in graphics programming, or the string library is not just makes the coding more natural, it eases the reading of code which is written with these in mind and that greatly effects the maintenance cost of a particular software as the code is read ten times more than modified. Java in this domain seems too verbose for me and it is much harder to read the long method invocation chains, that is not just used to be used by the developers, but is the recommended way how to code in Java.
This post already ran wildly long so I will close the topic for now. As a conclusion, I have to point it out that this article presented the subject from a rather subjective perspective at the end. Sorry for that, I will recap on the topic in a later post where I will try to be more detached and I’ll present actual use case examples but for now, this is all that came from my heart so please, don’t be very harsh with me if I was very biased. I hope you enjoyed the article anyway.
| Print article | This entry was posted by Daniel Rákos on January 11, 2010 at 4:41 pm, and is filed under General, Programming. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |


about 2 years ago
I also have done C++ programming for quite a few years, but nowadays I spend most of my time with managed languages.
And I am old enough to remember reading similar rants with languages that you maybe never used and are now dead.
If you had paid attention on your compiler design classes, you would know that Java and .Net on their current offering, are *compiled* languages.
Many game companies are now developing hibrid games where only the performance sensitive part is written in C/C++/Assembly, with most of the game being scripting in a “managed” language.
Just to name a few examples:
http://www.handy-games.com
http://www.gameloft.co.uk/
http://www.kongregate.com/
http://na.blackberry.com/eng/developers/
http://www.android.com/
http://creators.xna.com/en-GB
http://www.torquepowered.com/products/torquex-3d/
http://www.nordgame.com/
http://www.runescape.com/
http://www.banghowdy.com/
http://www.wowwiki.com/Lua
http://developer.nvidia.com/object/fx_composer_home.html
http://www.sodiumone.com/
http://en.wikipedia.org/wiki/Civilization_IV#Python
http://unity3d.com/unity/features/scripting
So yeah, you might not like managed languages, but many people in the games industry are getting their salary with managed languages.
You are entitled to your opinion but not everyone needs to be writing the next Crysis.
about 2 years ago
I agree that the Java and .NET specific languages are compiled but in a JIT manner. Also the GNU compiler collection provides a Java compiler that actually produces native code.
However, as you also mentioned, the performance sensitive parts are still written in more efficient languages.
The slowdown inherently present in Java applications is coming from two sources, to be more accurate:
First, the fact that it is still interpreted on the fly, even if some code parts get actually compiled.
Second, the language features and library facilities provided by the corresponding Java or .NET based technology are actually not designed to be the most efficient but they rather designed for flexibility.
Yes, game developers do use these languages but primarily to implement game logic, but this is not necessarily part of the core game engine.
I knew that this post won’t be my most liked one but I totally accept your opinion and somewhat I agree with you and really thanks for the comment. As I mentioned it in the article several times, what I’ve presented here is much more my private opinion rather than a scientific proof why not to use managed code languages.
By the way, I plan to talk more about the topic and next time I will try to come up with actual use cases to have some performance comparison and I will talk about when the trade off between performance and flexibility makes you choose whether to use native languages or managed code.
about 2 years ago
Nice to know that you are aware of such issues.
You know that you are repeating history, right?
Around 20 years ago, the programming magazines, ArpaNet and BBS were full of similar articles, but another languages.
Just replace C++ by C, and managed languages by C++ or Pascal. Oh the amount of flames discussing the performance issues of using a class or a virtual method call, or even array bounds checking.
And if you go even a few yeas back, you can replace native by Assembly and managed by C, PL/I, Algol.
And there are many native languages that offer the same amount of flexibility as Java or .Net and are not interpreted on the fly as you say.
Research a bit about D, Oberon, Modula-3, Eiffel, just to name a few.
And how the .Net JIT works as well, because contrary to usual JVM implementations, there is no interpretation phase in the CLR.
So have these issues in mind on your next topic about this issue.
I may be a very humble hobby graphics programmer, but I know my way around compiler development.
about 2 years ago
I wouldn’t call the situations the same, maybe with the exception of assembly contra C, PL/I, Algol. E.g. C++ haven’t introduced too much overhead compared to C. Actually it’s almost nothing.
The fact why the need for e.g. C had to replace assembly as writing big projects in assembly is very hard and it’s hard to maintain. However, I don’t see that huge difference between C++ and Java as an example. C++ suits well also for enterprise applications, especially because the huge user base of C/C++ and the many different libraries that are available for them.
Maybe I’ll have to get more experience with .NET as I’m not really competent in that topic, but I mentioned it also in the article. My bad experiences are mostly related to Java.
Anyway, I would try to do some research and performance measurements to compare the performance of Java and C# for example, because maybe I’m totally wrong and my concerns are totally irrelevant for .NET.
about 1 year ago
In my opinion Java and .NET are a whole different story. Considering current usage areas of Java, i tend to believe that its primary target sooner or later will be Java EE which emphasises modularity, maintainability and reusability way over performance, while J2SE will be there for small-scale stuff like tools, etc where performance is also secondary.
.NET? Not sure where MS tries to go with that one… But i believe that they ultimately want to have .NET as “the” primary way of development for PC/XBox/RandomHandheldGadgetDevice.
Btw with hardware performance going crazy these days, the performance cut between for example C++ and C# is less an issue with each passing moment. If you want to argue with this, consider decision makers in huge companies: they rather buy more horsepower (hardware) once, instead of employing an extra number of experienced (and thus, expensive) programmers because the sourcecode is harder to maintain due to low-level parts.
about 1 year ago
Okay, I don’t want to get further with this argument until I have a closer look on .NET technologies, as already said several times I was primarily tried to blame Java and I simply assumed that .NET is not different from it.
However, if you are so convinced that C# is fast enough then I’ll have to check it out.
I promise that I will do some research and come up with an article where I will compare the performance of C++, Java and C# in some common use case scenarios providing actual measurements.
Btw, I would be happy to see that C# is far more fast than Java because at least that would mean that only the guys at Sun made it go in the difficult and messy way.
about 1 year ago
I haven’t said that C# is as fast as C++ – it’ll never be on the same hardware i think.
I just wanted to say that for the average Joe coder the performance cut is almost negligible with hardware performance going upwards…
Best practice at the moment as i see – especially for game development – is mixing the two as Paulo has written it already. E.g. code your rendering engine and your AI library in C++ and the rest in C#. This is good especially that with C# you can do funky things like providing scripting interface which also uses C# as its script language. (So long, Lua!)
So in my opinion don’t bother comparing performances, many tried before but i’ve yet to see any useful comparison. Most probably you’ll end up with something like this:
C++ > .NET > Java
The point is: the area where these technologies shine is different for each one. From my point of view:
C++ – high performance, semi-multiplatform (hello conditional compilation)
.NET – efficient development and prototyping, excellent tools
Java – truly multiplatform with a big freaking community
about 1 year ago
I totally agree with you, and I also think that the performance comparison would end up like you expect it.
However, even if we know that the order is the one you’ve mentioned from point of view of performance, it would be nice to see exact numbers so one can choose that for a particular use case which language is the best, taking into account the efficiency and the obvious flexibility differences.