PDA

View Full Version : Progammers: C++ or Java?



Ivius
2008-07-26, 06:18 PM
((I would've posted this in "Programmers in the Playground, but I don't get Animate Thread for three more levels.))

In a few days I'm going to be going to be going to a programming camp (Oxymoron? You decide!). They have courses for both C++ and Java. Which one should I pick?

Currently, I'm leaning towards the former. I've recently switched from Linux to FreeBSD, on which building Java is hell.

C++ is also faster, has better libraries (There's exactly one library for java), and, most importantly, won't force the people who use my programs to install any proprietary junk (Yes, there's a free/open source/libre version of all the java stuff, but it's flaky, in my experience). And C++ isn't tied to any specific company or organization (This isn't too bad for, say, The Perl Foundation, but I honestly don't trust Sun very much). Plus as mentioned in the Programmers in the Playground thread, Java is an OO nazi.

Of course, C++ has it's cons, too. It's incredibly baroque (The PL/I of a new gneration). It has the hand memory management of C. And it's hard to debug (Why does your function return 0xa45fb7? Who knows!). But this paragraph is much smaller than the last one.

SMEE
2008-07-26, 06:30 PM
Go with C++.

You'll have little trouble getting on Java if you know C++. And once you know both, C# will be just so easy to use.

So, C++ is clearly the best option. It'll give you skills that you can apply at other languages.

Ivius
2008-07-26, 06:35 PM
Go with C++.

You'll have little trouble getting on Java if you know C++. And once you know both, C# will be just so easy to use.

So, C++ is clearly the best option. It'll give you skills that you can apply at other languages.

Make sense; I think it'd be easier to go to Java from C++ than vice versa, as the former took a lot from the latter. But C# is not gonna happen. I avoid Microsoft like the plague (C# is a classic example of a (failed, it looks like) Embrace, Extend, and Extinguish).

EDIT: Maybe I shouldn't have said all that, but either way, everyone please try not to derail the thread any more than it is by bashing or evangelizing about Microsoft.

Tirian
2008-07-26, 08:00 PM
I agree. My impression of much of the Java side of the Java/C++ war is that a modern programming language shouldn't give you enough rope to hang yourself and that you're better off with a language that will try to prevent you from designing bad classes and that allows you to be lax with memory management. I don't buy it; I think that if you learn proper OO design and testing principles then your code will be better for it even if you decide that you want to write something in Java for the more natural cross-platform distribution.

Ultimately, you should probably know both and should ideally know your way around even more esoteric languages like Smalltalk.

valadil
2008-07-26, 10:22 PM
I'm not a fan of Java. It seems good or adequate at everything, but excellent at nothing. If you plan on taking classes taught in Java it might be nice to get ahead in the language but other than that I'd say go with C++.

adanedhel9
2008-07-26, 11:39 PM
First thing: keep your task in mind. Are you learning to program, or learning to use a language? The two tasks - though quite interrelated for the beginner - become more and more distinct as your experience grows. A good programmer can usually pick up the essentials of a new language in a few hours and can do nifty things within a few weeks of study. Someone who just knows how to use a language well will likely be stuck in that language even while the industry moves on.

If you're studying programming, between the two I'd pick Java (though given the whole gamut of languages I'd pick something completely different, like Python). In Java you don't have to worry so much about the nitty-gritty-low-level stuff that just gets in the way if you're not 100% sure what you're doing. And that leaves you with more mental resources to spend on real programming. Worry about the language details later.

If you're studying the language, though, it's just a matter of taste.


There's exactly one library for java

I'm not quite sure what you mean by this. There are plenty of non-Sun - even open source - libraries available for Java, for everything from GUIs to VUIs to SOAP to logging.

Ivius
2008-07-27, 12:18 AM
First thing: keep your task in mind. Are you learning to program, or learning to use a language? The two tasks - though quite interrelated for the beginner - become more and more distinct as your experience grows. A good programmer can usually pick up the essentials of a new language in a few hours and can do nifty things within a few weeks of study. Someone who just knows how to use a language well will likely be stuck in that language even while the industry moves on.

If you're studying programming, between the two I'd pick Java (though given the whole gamut of languages I'd pick something completely different, like Python). In Java you don't have to worry so much about the nitty-gritty-low-level stuff that just gets in the way if you're not 100% sure what you're doing. And that leaves you with more mental resources to spend on real programming. Worry about the language details later.

If you're studying the language, though, it's just a matter of taste.

I probably will be here to learn to program better in general more than learning the specific language. But better is the key word. I know about variables and loops and recursion and all that. I just don't know what the heck to do with them.

I think the nitty-gritty low level stuff is pretty appropriate at the level I'm at. You have to learn it at some point; it will be frustrating and distracting when you're an absolute beginner, and you'll never be able to reach any real level of knowledge without it.

Ashtar
2008-07-27, 05:17 PM
Well, from my personal experience, I find C++ to be frustrating in the sense that I have to go and find a new library every time I need a function. Need advanced maths? Go and get Boost and IMSL C Numerical Library[/URL]. Need DB access? Go for another library. GUI ? Hey yet another library.

Java has most of it in one library and the rest is usually quite easy to find and especially all documented in the same format (thanks javadoc). Numerics ? COLT (http://acs.lbl.gov/~hoschek/colt/), DB access ? Included, GUI ?
Well java GUI is really not too hot, but it does exist.

But in the end, if you stick with small scale stuff programming, you usually don't see the difference between Java and C++. It's only when you start going to A*, Matrix spectral decomposition, graph optimizations and Monte Carlo simulations on data stored in a DB that you start to see an advantage in a language that doesn't need a new library every time.

((And anyway, learn Ada or Fortran!))

Ivius
2008-07-27, 06:00 PM
((And anyway, learn Ada or Fortran!))

I might eventually, but this is only about the class.

About the library thing, I never do anything mathematical in my programs besides adding one, and I pretty much leave databases alone. And in C++, you have a couple very good choices for GUIs, and can use all of C's libraries too.

I think I'm starting to see a trend here: C++ puts the responsibility on the programmer, and Java takes the responsibility upon itself. This is evident in the memory management, the libraries, and the syntax. In other words, C++/Java is the same as C/Pascal or Perl/Python. In all three cases, I think I favor the one on the left.

Tirian
2008-07-27, 08:05 PM
I think I'm starting to see a trend here: C++ puts the responsibility on the programmer, and Java takes the responsibility upon itself. This is evident in the memory management, the libraries, and the syntax. In other words, C++/Java is the same as C/Pascal or Perl/Python. In all three cases, I think I favor the one on the left.

The other two comparisons you make are slightly different. I wouldn't mind advising someone to learn Pascal before C if it were their first language. It's essentially the same language except that Pascal's compiler will catch your newbie mistakes whereas C's will assume that you are doing something amazingly deep and so you will have to debug your syntax errors in runtime. Of course, there is no reason to look back once you are in the habit of using proper syntax, just like there is no reasons to put training wheels back on your bicycle.

The Perl/Python debate is thorny if only because the Pythonistas make so many bogus claims about their superiority. The claim that there is only one way to do something in Python is laughable; it is just as easy and common to write obfuscated one-liners in Python. But it is true that there are fewer than six ways to write an "if" statement and only one of them belongs in your code. The one that I find the most curious are things like this (http://www.xkcd.com/413/)from ex-Perlers; not only does Perl have the same power but downloading, installing, and upgrading that library are a part of the environment, so you don't even have to do a Google search on "Perl library soul". All the same, I prefer Python and if someone asked me which of the two languages they should learn I would say Python instead of "both".

Lord Tataraus
2008-07-27, 11:53 PM
I'd cast my vote for C++. I learned that first and I must say I just prefer how it does somethings to how Java does some things, yeah, I'm being vague mostly because I don't really have a good reason. The weird thing is that my college teaches Java first then C++ (I'm going to breeze through that course).

I would also suggest python, I don't know much about perl except from a friend who learned it and from what I hear, python is better....unless you like llamas.

Aereshaa_the_2nd
2008-07-28, 01:13 AM
I would definitely go for C++, because it's faster, there are more libraries, and its syntax, while horrible, is at least better than java's.
Really, neither are very good languages to start with, an easier path would be shell scripting > perl > C++/C. (That's the one I took)

Ivius
2008-07-28, 06:35 AM
A few people have said that these are bad languages to start with, and I agree. But this isn't going to be my first language (I'd guess it's the seventh or eighth off the top of my head).

In any case, it's today and I'm going with C++.

Ivius
2008-07-29, 09:27 PM
I actually got how this works wrong. I thought that there would be two different classes, one Java, one C++. Nope. There was one class, which could've been C++ or Java. It ended up being Java.

Which, to be honest, I'm now glad about. I admit I'm a huge hypocrite for saying this, but I really like this language. I haven't seen any problem with speed, and the library is superb. We've been working in Eclipse (I half expected we'd be using Visual Studio or something, so that was a relief), which is really helping. Though the problem over Sun's control over it, and the proprietary code, remains, Sun is suppose to GPL the whole thing soon, which will fix both.

(Also, sorry for the late post, having hardware problems, and I know next to nothing about hardware. Sigh)