• Quick note - the problem with Youtube videos not embedding on the forum appears to have been fixed, thanks to ZiprHead. If you do still see problems let me know.

C/C++ vs. Java vs. C#

Wowbagger

The Infinitely Prolonged
Joined
Feb 2, 2006
Messages
15,660
Location
Westchester County, NY (when not in space)
Here is a thread for discussing the merits of various computer languages. I am starting this as an attempt to continue a discussion I was having with a fellow TAM member, that was cut off much too soon. I hope she joins us, but if not, at least I should have someone else to argue with, about these things.

Here are my thoughts, to start with:

C++ was basically the C language, with object-oriented stuff shoe-horned into it. And, as a relatively low-level language, it is still useful for developing applications where performance matters most. As a side effect of its age, though, almost all other modern language features have to continue getting shoe-horned into it, rendering it rather unwieldy to write for. Especially when they are all added in rather inconsistent ways. Writing COM components is like pulling teeth, and managed classes are sometimes even worse.

Java was a substantial improvement over C/C++ in that regard: Everything was implemented consistently (for the most part), and modern features were included from the ground up. It used syntax and semantics very similar to C++, so that older programmers could get into it, right away. However, it has a history of being a performance sloth, and it originally missed out on a few important, classic features, (such as structs). Though, much of that changed over the years (some of it inspired by C#, when it was released). One of its huge selling points is the compile-once, run anywhere attitude, which I can appreciate.

C# (pronounced C-Sharp) is an elegant language contender. Like Java, it has all of the important modern features of computer languages built into it, from the ground up. But, since it is newer than Java, it was able to be constructed with a bit more hindsight. The .NET Framework provides a one-stop-shop for almost all of your standard API needs. And, for what it's worth: its IDE (Visual Studio) is the best, most productive one in the world, as far as I can tell. It's a bummer that it is only officially supported for Windows, though.

I happen to use C# the most (when I am not stuck with VB). But, perhaps that is mostly due to historic accident. I have always been a Microsoft-platform developer, in my professional career, and I suppose there is little chance of that changing, any time soon.

What do you think?
 
Sort of a side note: sometimes the available IDE also should be part of the equation when comparing languages. While a language itself may be more burdensome than another when actually trying to implement and maintain a system, IDE features can make up for that, and even give it an advantage over another choice.

But, a little more on target to the OP, I also tend not to give the resource-hog criteria quite the weight I did at the beginning. All things being equal, I'd rather use a language that was, for instance, more CPU intensive now, if it means easier portability and maintenance over time. Plus, depending what I mean by 'over time', the program may automatically get faster as the cpu is upgraded, whereas complex code will not get simpler over time. But ok, that may be more of a coding issue than a language one.

So anyways... I need to go back and read the OP.
 
We used a book in my high school programming class called "C++ for You++".
 
In my view, the language you choose for a program is heavily influenced by what you're developing it to do. Most of my day-to-day stuff tends to be done in C#, but if I'm writing a website I'd actually use PHP rather than C# (with an ASP.NET front-end) unless that's what's required of me by whichever client is paying me for my code.

I must admit, I don't really give much weight to the resource intensiveness of a language since nowadays computers are (by and large) powerful enough to mostly mitigate that problem. Add to that decent garbage collection in the newer languages and I think nowadays the language one uses is (in most cases) a moot point. I would, obviously, have a completely different viewpoint if I was programming for different devices or for different situations.
 
Well, I mostly adore C++, for the reasons others criticize it. Bjarne's book on how and why he designed C++ the way he did is very instructive for those who disparage the language. Much like in the OP, people complain that it contains a hodge podge of features. Rather than a hodge podge, he built the language over a number of years, adding features that were needed, and not adding, or removing, features that didn't add a lot. His guiding principle through all of this was empericism. Study what features use and how they use it, and then support that usage. The language, for example, is OO neutral. You can use OO if you want, and not use it if you don't. You can write functional programming (such as STL), or not. You can write very close to the metal, or you can write at a very high abstraction level. Sure, it has warts due to his desire to remain compatible with C, but all in all it works. The result is definitely a "professional" language - you need to study and work hard to become conversant in it, you need to use modern tools (a strong IDE, debugger, and runtime memory and resource leak detector. But given that, you can be amazingly productive in it. I recall a few guys at my place of work who for some reason decided they were going to rewrite an application I did using more "modern" tools. They spent the next several months fighting these tools because the high level of abstraction and reliance on prewritten APIs meant you had to do things 'their way'. One guy would spend hours on the phone to Microsoft support. He found quite a few bugs in their code in the process. But mostly he fought the tools we was working with, while extolling their virtues, and talking about how much more flexible the code would end up being. Meanwhile I turned the app into a production system, quickly added features when asked, etc. All that other work got scrapped. Dumb. I still don't understand why my boss allowed that - the guy that was hired and made the argument to do it had a high opinion of his own skills, and I think he managed to paint me as a reactionary or something, while promising a magic bullet.

If someone was only interested in programming casually, I'd definitely point them to another language. Super heavy COM work might point to using another language for the main work, sticking to C++ for some heavy duty processing.

People complain about things like pointers in C++, but then it turns out they are using them wrong. Things like pointers to functions are very useful when you are writing things like state machines and event driven models. In the normal course of things, references are far safer and easier to use and keep track of. I don't tend to use pointers often, but when I use them, I really need them. I remember fighting Ada to do some things that would be easy,and perfectly safe, to do with pointers in C or C++. It takes understanding of a feature, and when to use it. I do a lot of hardware level things, so I'm likely to be writing near pure C for device drivers, using pointers and such to handle events, state machines, etc. Then I'll be using OO to help me with interface design, and then functional programming to do STL-type algorithms to manipulate the data coming from the devices. I can do all that easily with one language, and am not forced into an OO straightjacket when it is not the right tool for the job. Do you need to be on the top of your game to write like that? Sure. But being at the top of your game means being at the top of the salary range for your career - not a bad thing, IMO, though it does make it harder to apply for a new job when they hear what you make and seem dubious that you are worth it. I do worry one day I'll end up being a 'COBOL programmer' - maintaining hopelessly outdated legacy systems, but for now I'm trying to stick with C++ for my career.
 
I've spent a lot of time in both C++ and C# (and a few other languages along the way), and I've read an awful lot of the language wars on Java vs. C#.

With some effort, I'm resisting the urge to write pages and pages about the pros & cons of, say, Java's enums and C#'s Properties.

So I'll generally concur with the OP. C++ is nearly self-encrypting and encourages a lot of (IMO) bad practices. ETA: Gonna guess that Roger (post #5) has a different perspective on that.

C# and Java are extremely similar; I prefer C#.

My recommendations: Use C++ if someone makes you use C++.

Use C# if you're targeting Windows ONLY

Use Java if any other OS may get involved.

------------------------
All of that is for 'typical' medium-to-large programming projects. For low-level stuff (like drivers), use C. Bear in mind that I've never written a driver, so don't take me too seriously here. And there are programmers who I respect a lot who say that everything should be done in Lisp. I haven't spent enough time in Lisp to have a real opinion.

For smaller, quicker, less formal things, Python or Ruby.
For smaller, quicker, less formal networky things, Tcl.

Now, many kids today seem to think that, for example, C++ and Java are completely different languages. That's because they haven't seen any really different languages. Sort of like French seems really different from Spanish if all you know are French and Spanish, but learn a little Russian or Swahili, and suddenly French and Spanish look very similar. With that perspective, I'd recommend that any budding programmer should spend some time fooling around with Lisp and Forth just so they see how different things really are. And code up some routines in x86 assembly- it will give you some insights into how the computer really works.
 
Last edited:
So I'll generally concur with the OP. C++ is nearly self-encrypting and encourages a lot of (IMO) bad practices. ETA: Gonna guess that Roger (post #5) has a different perspective on that.
Well, I wouldn't say "encourages". I definitely would say "allows". Should a irresponsible person drive a 550HP, 9" raised rock crawler on the street? Probably not. They'd tip it over in a serious corner, it makes it easy to pull shenanigans in a parking lot (who hasn't seen some idiot driving their truck over a table sized rock or something to park someplace stupid and illegal), drag race at lights, etc. In the hands of somebody who knows what the tool is for, it's perfect for it's job, and nothing else works as well. "But it's so easy to drive to fast for a corner, and the CG is so high it'll tip over!" bewails the reader. Um, ya. It's a tool for going over a house size boulder at 2mph, and perhaps drive carefully at the speed limit on public roads. Not for beginners.

If you are writing a typical GUI application that takes some user input, stores it somewhere, processes it a bit, and displays the result, there's no real need for C++ these days. OTOH, if you are trying to do something serious (control a tank or airplane, write an OpenGL or DirectX application), fold proteins, write ocean current models, etc., Skinny help you if you try to do this in JAVA or .NET. Use the right tool for the job. My job requires a swiss army knife, your's needs a folding knife, doc's needs a scapel.
 
What do you think?

That of the four languages you mention, I only like C. C++ (and likewise Objective-C) has two orthogonal feature sets layered on top of one another, procedural and OO, which haven't been integrated together very well. C++ has the misfortune of neither being the simple, clear system-level programming language that C is, or possessing any of the advanced abstractions high level languages provide. Linus Torvalds summarized it quite well after a rather (in)famous rant against C++:

And if you want a fancier language, C++ is absolutely the worst one to choose. If you want real high-level, pick one that has true high-level features like garbage collection or a good system integration, rather than something that lacks both the sparseness and straightforwardness of C, and doesn't even have the high-level bindings to important concepts.
http://thread.gmane.org/gmane.comp.version-control.git/57960

Nonetheless, I think there are places where C++ is the correct choice, but it's much smaller than what it is used for, and it's not somewhere I feel particularly comfortable.

Regarding Java / C#, my dislike comes mostly from a personal bias against static typing in high-level languages. Of the two, Java has a much nicer ecosystem surrounding it, the VB/C# CLI is not a particularly judicious idea, making the languages effectively interchangeable, rather than capitalising on any strength either could have on it's own, especially compared to the way Java bytecode enables both Groovy and Clojure, two quite interesting languages so far as I can tell. Groovy I've now used on one project, with another coming up, and it's been a pleasant experience. Clojure I'm still merely toying with.

Also, the part of .NET I'm familiar with (ASP.NET) is simply ghastly. I don't know if it's true for the rest of it, but I don't have much motivation to find out.
 
Also, the part of .NET I'm familiar with (ASP.NET) is simply ghastly. I don't know if it's true for the rest of it, but I don't have much motivation to find out.
Today, I am inclined to think that ASP.NET 1.1 was rather ghastly. Have you seen the newer versions? They are substantially less ghastly, since the advent of partial classes, Master pages, generics, improved @page properties, and other things.
 
Every language has it's application. However, personally i think that if you want to write fast applications that run cross-platform, you are best served with C++.

C/C++ is a well standardized and widely used language set. As others have said, C can get as close to the bare metal as is possible using a high-level language. Some say that C is a high-level assembler. You can inline assembly code if you really need the last percent of speed available. You can do nice OO programming with C++, and you can nicely glue all that together.

Yes, C++ may have some shortcomings, but with stuff like the Boost libraries and the QT toolkit you can do a hell lot of things very nicely.

Java is nice, sure. But it also is a resource-hog, and most of the time rather slow. Yes, you can compile Java code into a pure binary nowdays, and many Java-VM's can use a JIT compiler to speed up as it executes. But compiling the code takes away the benefit of Java's "run everywhere directly" approach. I mean, if you are going to compile Java, why not compile C++?

JIT compilers are nice but can introduce nasty bugs. In any case, as soon as you need something with a GUI, Java is virtually a no-go. The AWT/Swing framework may or may not work the same on different machines, it may not even be the same between different Java VM's. I have seen nasty stuff with that, like buttons/sliders working fine in one VM, but were unusable in another. Or font's, or, or, or. Also, AWT/Swing is horribly slow, because it is completely unaccelerated. Everything is done pixel-by-pixel, and in Java code for most of the stuff. Maybe that changes somedays, maybe it already started to change, dunno. Haven't used it for quite some while now.

Can't say much about C#, since i never used it. However, i'm skeptical about it. You are definitely going to depend on the good will of Microsoft. There are "free" implementations like Mono, but there is always the patent threat which may void it one day. Microsoft may decide to take royalities from programmers that commercially distribute applications written in C#, simply for using their framework/libraries. Don't get me wrong, i'm not about to bash Microsoft, i'm just sceptical because of their behavior in the past.

Greetings,

Chris
 
10 REM FORUM POST
20 OPEN THREAD "http://www.internationalskeptics.com/forums/showthread.php?t=148152" /NP
30 PRINT "I had a huge gap in my computer interactions. I grew up programming in BASIC, with some work in CoBOL, and a little exposure to FORTRAN.

Then, I went into the military and had little time to learn much of what was going on in the computer world.

I came out, and suddenly it's Java and C++ and LISP... I'm way behind. Took the Visual Basic class at college - it's like programming for people who don't know how to program. I mean, you get in to some of the basics of a program, like For...Next loops and such, but so much of it is written for you, behind the scenes... and I'm totally lost now. I can still whip up a good program in BASIC, but I don't know now what you do to translate that into a good common language.

I've looked into the simple route - __program language of choice__ for Dummies (hey, it worked great for HTML and Flash), but there are so many language and language variants out there, that I honestly don't know where to start.

I'll be lurking on this thread to get a good idea where to start - so far, it seems like the three top contenders are C++, C#, and Java. I'm primarily interested in Windows program writing, because that's what I'm using myself... so please, carry on with the debate."
35 CLOSE THREAD
40 END
 
Well, I wouldn't say "encourages". I definitely would say "allows". Should a irresponsible person drive a 550HP, 9" raised rock crawler on the street? Probably not. They'd tip it over in a serious corner, it makes it easy to pull shenanigans in a parking lot (who hasn't seen some idiot driving their truck over a table sized rock or something to park someplace stupid and illegal), drag race at lights, etc. In the hands of somebody who knows what the tool is for, it's perfect for it's job, and nothing else works as well. "But it's so easy to drive to fast for a corner, and the CG is so high it'll tip over!" bewails the reader. Um, ya. It's a tool for going over a house size boulder at 2mph, and perhaps drive carefully at the speed limit on public roads. Not for beginners.

I have some sympathy for that line of thought, but it seems to me that C/C++ include features that you should never use. That, in turn, means that things that should be compile errors become hard-to-track bugs. For example, on one occasion, I spent hours time tracking down a bug that stemmed from the fact that the function declaration in the header file used different variable names than the function's implmentation (x, y vs. y, x - d'oh!). But that's a "feature?"

If you are writing a typical GUI application that takes some user input, stores it somewhere, processes it a bit, and displays the result, there's no real need for C++ these days. OTOH, if you are trying to do something serious (control a tank or airplane, write an OpenGL or DirectX application), fold proteins, write ocean current models, etc.,.Skinny help you if you try to do this in JAVA or .NET.

I'm curious on that last one. I've done DirectX programming in C#, and I'm not clear on why it would be significantly easier (or harder, for that matter) in C++.

Use the right tool for the job. My job requires a swiss army knife, your's needs a folding knife, doc's needs a scapel.

No argument there.
 
Can't say much about C#, since i never used it. However, i'm skeptical about it. You are definitely going to depend on the good will of Microsoft. There are "free" implementations like Mono, but there is always the patent threat which may void it one day. Microsoft may decide to take royalities from programmers that commercially distribute applications written in C#, simply for using their framework/libraries. Don't get me wrong, i'm not about to bash Microsoft, i'm just sceptical because of their behavior in the past.

C# is my language-of-choice for a lot of things, but I definitely share your misgivings.
 
I'll be lurking on this thread to get a good idea where to start - so far, it seems like the three top contenders are C++, C#, and Java. I'm primarily interested in Windows program writing, because that's what I'm using myself... so please, carry on with the debate."

If you're just doing Windows, the Microsoft Express editions of C++ and C# have good IDEs without any fiddling around to get the various pieces assembled and playing nicely; I haven't had that experience with Java yet. And if you're used to the VB IDE, the C++ and C# IDEs should look very familiar.
 
If you're just doing Windows, the Microsoft Express editions of C++ and C# have good IDEs without any fiddling around to get the various pieces assembled and playing nicely; I haven't had that experience with Java yet. And if you're used to the VB IDE, the C++ and C# IDEs should look very familiar.

That's fairly encouraging.

I guess one of my problems with computing today - much like my problem with website building - is that so much of it is done for me that I feel like I really don't know what I'm doing, exactly. I know it's much more complex than it was in the days when you POKE'd and PEEK'd your memory addresses, and that it's probably a lot nicer to have all those DATA elements pre-done for you... but it's still weird to me to just slap the elements together, write a few pieces of code to tie it all up, and claim I programmed it.

I'll still open NotePad and write web pages by hand sometimes, and then go in to Expressions Web or Dreamweaver and tweak them up a bit; but I'm so far behind the curve on programming I can't really do that with programs any more. I'm re-learning How It's Done Today, but what I really need is some way to fill in the gap from writing graphics programs on Apple II GS and video games on C-128s to the stuff done today...

OTOH, it's easy to make applications in just a few minutes. One thing I can't figure out - what are the usual methods for randomization? I remember in BASIC we had a way to do it that looked something like:

A = INT(RND(1)*100)+1

that would produce a random integer from 1 to 100 - how on earth do we do that now?

Well... back to lurk for me.
 
Hello dasmiller,

For example, on one occasion, I spent hours time tracking down a bug that stemmed from the fact that the function declaration in the header file used different variable names than the function's implmentation (x, y vs. y, x - d'oh!). But that's a "feature?"

may i ask you what compiler you used? Because i never ever had that problem. What matters in the declaration is that the type(s) of the argument(s) match the implementation. The names are completely irrelevant usually. I know that _some_ compilers can generate, if instructed to do so, empty implementations of a function if there is no implementation given in the source, but only the declaration.

If you really had that bug because of only the names, i would tend to say that this is a severe bug in the compiler instead.

On a sidenote, you don't need to give any variable names in the declaration at all. Something like "int myfunc(int, int);" should be enough.

Greetings,

Chris
 
Well, I mostly adore C++, for the reasons others criticize it. Bjarne's book on how and why he designed C++ the way he did is very instructive for those who disparage the language. Much like in the OP, people complain that it contains a hodge podge of features. Rather than a hodge podge, he built the language over a number of years, adding features that were needed, and not adding, or removing, features that didn't add a lot. His guiding principle through all of this was empericism. Study what features use and how they use it, and then support that usage. The language, for example, is OO neutral. You can use OO if you want, and not use it if you don't. You can write functional programming (such as STL), or not. You can write very close to the metal, or you can write at a very high abstraction level. Sure, it has warts due to his desire to remain compatible with C, but all in all it works. The result is definitely a "professional" language - you need to study and work hard to become conversant in it, you need to use modern tools (a strong IDE, debugger, and runtime memory and resource leak detector. But given that, you can be amazingly productive in it. I recall a few guys at my place of work who for some reason decided they were going to rewrite an application I did using more "modern" tools. They spent the next several months fighting these tools because the high level of abstraction and reliance on prewritten APIs meant you had to do things 'their way'. One guy would spend hours on the phone to Microsoft support. He found quite a few bugs in their code in the process. But mostly he fought the tools we was working with, while extolling their virtues, and talking about how much more flexible the code would end up being. Meanwhile I turned the app into a production system, quickly added features when asked, etc. All that other work got scrapped. Dumb. I still don't understand why my boss allowed that - the guy that was hired and made the argument to do it had a high opinion of his own skills, and I think he managed to paint me as a reactionary or something, while promising a magic bullet.

If someone was only interested in programming casually, I'd definitely point them to another language. Super heavy COM work might point to using another language for the main work, sticking to C++ for some heavy duty processing.

People complain about things like pointers in C++, but then it turns out they are using them wrong. Things like pointers to functions are very useful when you are writing things like state machines and event driven models. In the normal course of things, references are far safer and easier to use and keep track of. I don't tend to use pointers often, but when I use them, I really need them. I remember fighting Ada to do some things that would be easy,and perfectly safe, to do with pointers in C or C++. It takes understanding of a feature, and when to use it. I do a lot of hardware level things, so I'm likely to be writing near pure C for device drivers, using pointers and such to handle events, state machines, etc. Then I'll be using OO to help me with interface design, and then functional programming to do STL-type algorithms to manipulate the data coming from the devices. I can do all that easily with one language, and am not forced into an OO straightjacket when it is not the right tool for the job. Do you need to be on the top of your game to write like that? Sure. But being at the top of your game means being at the top of the salary range for your career - not a bad thing, IMO, though it does make it harder to apply for a new job when they hear what you make and seem dubious that you are worth it. I do worry one day I'll end up being a 'COBOL programmer' - maintaining hopelessly outdated legacy systems, but for now I'm trying to stick with C++ for my career.

QFT. Exactly my toughts on this. Of course, much more eloquently than I could ever put it. Thank you, roger.

I love C/C++ because it does what I tell it to do, however braindead it may be (and it usually isn't :D). Doesn't get in the middle. Of course, it is also very hard to beat performance-wise in most applications.
 
That's fairly encouraging.

I guess one of my problems with computing today - much like my problem with website building - is that so much of it is done for me that I feel like I really don't know what I'm doing, exactly. I know it's much more complex than it was in the days when you POKE'd and PEEK'd your memory addresses, and that it's probably a lot nicer to have all those DATA elements pre-done for you... but it's still weird to me to just slap the elements together, write a few pieces of code to tie it all up, and claim I programmed it.

Ahhh - I remember turning down the volume with POKE 53281, 64 (or was it 53280? one was pitch, the other was volume).

(some snipping)
OTOH, it's easy to make applications in just a few minutes. One thing I can't figure out - what are the usual methods for randomization? I remember in BASIC we had a way to do it that looked something like:

A = INT(RND(1)*100)+1

that would produce a random integer from 1 to 100 - how on earth do we do that now?

Well... back to lurk for me.

C# and Java each have a Random class for just that sort of thing. C++ has rand, which (IIRC) works something like that RND function you mentioned.
 
Hello Z,

One thing I can't figure out - what are the usual methods for randomization? I remember in BASIC we had a way to do it that looked something like:

A = INT(RND(1)*100)+1

that would produce a random integer from 1 to 100 - how on earth do we do that now?

Well... back to lurk for me.

in plain C that would be

A = (rand() % 100) + 1;

to get a value between 1 and 100 (both inclusive). I think your example has a bug, it would give you numbers from 1 to 101 (101 in the case that RND(1) returns 1).

However, in C you also need to seed the random number generator using something like:

srand(time(NULL));

Instead of time(NULL) you can use a fixed value instead, if you need reproducible streams of random numbers upon each startup.

Greetings,

Chris

Edit: in case you wonder, % is the modulo operator. It gives you the remainder of a division. So, 136 % 100 = 36, 593 % 100 = 93, etc...
 
Last edited:
I'm curious on that last one. I've done DirectX programming in C#, and I'm not clear on why it would be significantly easier (or harder, for that matter) in C++.
Okay, I'm probably wrong on that. I wrote a OpenGL program in straight C++, and then my boss wanted to see if we could switch to a commercial product that used Java, all kinds of third party libraries, all on top of OpenGL. As you might imagine, they had huge performance issues - I'd pop up and start running in a second or two, they'd take a minute to two minutes. And they were hamstrung, having no way to tune all the compenents they were using. But that is more an issue of using third party libraries, not the language. I stand corrected.
 

Back
Top Bottom