So I’ve met a couple of people (who shall remain nameless) over the past few weeks who insist that C++ is better than Java. I am truly impressed by the stubbornness of these people. So here goes. I’m going to argue once & for all why …
OH NO! I’m not falling into that trap.
I’m just going to pose questions that any developer should ask before choosing either C++ or Java. NOTE: I’m not advocating just Java here. Mono has comparable features, or .NET if you don’t care about cross-platform.
Before I start I’d like to mention that I was once a die-hard
C++er. I started programming in C++ back when I was 11, but 5 years
after that I found .NET and never looked back. So I technically have 5 years of experience with nothing but C++, and I have used it off & on and will continue using it whenever I absolutely need to.
1. Ant vs “make”
What’s better? Ant or “make”? Would you rather write a Makefile (no extension) in a proprietary hard-to-read language, with a text editor like “vim”, or would you rather write an XML file (build.xml) which could easily be generated by a tool (perhaps with a GUI)?
Secondly, which one has more capabilities? Ant or “make”?
2. Pointers
Do you really need pointers? Do you really need to convert integers (memory addresses) to objects? Are you willing to put up with the hassle of manually collecting garbage (using “delete” statements)? How are you going to test that you don’t have memory leaks?
What if the architecture you’re working on uses 48-bit memory addresses and you want to port your program to an architecture that uses 64-bit memory addresses? Have you thought about how you’re going to do that? Because you know, in Java you don’t need to think about any of this.
3. CPU Architecture and OS
What CPU are you programming for? What OS? Do you need little-endian or big-endian integers? Are you going to use Unicode? Which kind? UTF-8 or UTF-16? With Java, you don’t need to think about it.
Suppose you are coding for multiple OSes/CPUs. Do you like having lots of preprocessor statements in your code? There is no need for preprocessor statements in Java. If you do want to check what OS or CPU you are running on, you can do so at runtime.
How are you going to know what libraries to link to on each OS? And how will you know that you have the right version? For the right architecture/OS? In Java, you have only one shared library: the JDK. In C++, you have a variable number of shared libraries.
4. JUnit
One question: Unit testing: how will you do it in C++? Or will you just rely on integration testing all the way through?
5. Graphical User Interface
Suppose you want a GUI for your application. What toolkit will you use? Gtk, Qt, Win32, MFC, .NET? Console is starting to look more attractive already, isn’t it? Will you use a different toolkit for each OS? At least in Java, SWT handles all that dirty work and you can get a native GUI on just about every OS.
6. Web Applications
What are you going to do for web applications? Make/use a CGI application? Use Perl/Python/PHP? Does the ugliness of those scripting languages bother you at all? Or the fact that you’ll have to learn yet another language? With Java, you can build a totally custom web server in about 300 lines of code. You also have JSP.
7. Dynamic Linking
Suppose you want to enable your application to have plugins, so that other developers can contribute parts of your application without seeing the core application’s source code. How exactly are you going to do this? In Windows, you can use DLLs. What about in Linux? How are you going to distinguish between the two?
What if somebody submits a plugin built for Linux and your application is built for Windows? Maybe you want to load that plugin anyway, because it technically shouldn’t have any OS calls. How will you do it? The plugin is an .so file and your application is an EXE. Feel like figuring that out?
8. Exceptions vs. Core Dumps
Think about this carefully: Would you rather receive a core dump (segmentation fault) if something goes really seriously wrong, or would you rather it be an exception?
Conclusion
This is it for now… I may add to this article if I come up with anything else.
February 10, 2009
0
Why C++ Sucks (Sort Of)
So I’ve met a couple of people (who shall remain nameless) over the past few weeks who insist that C++ is better than Java. I am truly impressed by the stubbornness of these people. So here goes. I’m going to argue once & for all why …
OH NO! I’m not falling into that trap.
I’m just going to pose questions that any developer should ask before choosing either C++ or Java. NOTE: I’m not advocating just Java here. Mono has comparable features, or .NET if you don’t care about cross-platform.
Before I start I’d like to mention that I was once a die-hard
C++er. I started programming in C++ back when I was 11, but 5 years
after that I found .NET and never looked back. So I technically have 5 years of experience with nothing but C++, and I have used it off & on and will continue using it whenever I absolutely need to.
1. Ant vs “make”
What’s better? Ant or “make”? Would you rather write a Makefile (no extension) in a proprietary hard-to-read language, with a text editor like “vim”, or would you rather write an XML file (build.xml) which could easily be generated by a tool (perhaps with a GUI)?
Secondly, which one has more capabilities? Ant or “make”?
2. Pointers
Do you really need pointers? Do you really need to convert integers (memory addresses) to objects? Are you willing to put up with the hassle of manually collecting garbage (using “delete” statements)? How are you going to test that you don’t have memory leaks?
What if the architecture you’re working on uses 48-bit memory addresses and you want to port your program to an architecture that uses 64-bit memory addresses? Have you thought about how you’re going to do that? Because you know, in Java you don’t need to think about any of this.
3. CPU Architecture and OS
What CPU are you programming for? What OS? Do you need little-endian or big-endian integers? Are you going to use Unicode? Which kind? UTF-8 or UTF-16? With Java, you don’t need to think about it.
Suppose you are coding for multiple OSes/CPUs. Do you like having lots of preprocessor statements in your code? There is no need for preprocessor statements in Java. If you do want to check what OS or CPU you are running on, you can do so at runtime.
How are you going to know what libraries to link to on each OS? And how will you know that you have the right version? For the right architecture/OS? In Java, you have only one shared library: the JDK. In C++, you have a variable number of shared libraries.
4. JUnit
One question: Unit testing: how will you do it in C++? Or will you just rely on integration testing all the way through?
5. Graphical User Interface
Suppose you want a GUI for your application. What toolkit will you use? Gtk, Qt, Win32, MFC, .NET? Console is starting to look more attractive already, isn’t it? Will you use a different toolkit for each OS? At least in Java, SWT handles all that dirty work and you can get a native GUI on just about every OS.
6. Web Applications
What are you going to do for web applications? Make/use a CGI application? Use Perl/Python/PHP? Does the ugliness of those scripting languages bother you at all? Or the fact that you’ll have to learn yet another language? With Java, you can build a totally custom web server in about 300 lines of code. You also have JSP.
7. Dynamic Linking
Suppose you want to enable your application to have plugins, so that other developers can contribute parts of your application without seeing the core application’s source code. How exactly are you going to do this? In Windows, you can use DLLs. What about in Linux? How are you going to distinguish between the two?
What if somebody submits a plugin built for Linux and your application is built for Windows? Maybe you want to load that plugin anyway, because it technically shouldn’t have any OS calls. How will you do it? The plugin is an .so file and your application is an EXE. Feel like figuring that out?
8. Exceptions vs. Core Dumps
Think about this carefully: Would you rather receive a core dump (segmentation fault) if something goes really seriously wrong, or would you rather it be an exception?
Conclusion
This is it for now… I may add to this article if I come up with anything else.
Categories: .NET, Commentary, History, Personal, Technology