Learning C++ for Java Programmers? 99
The Real Joe Faith asks: "The O'Reilly book 'Java in a Nutshell' used to include a really handy introduction to Java specifically aimed at C++ programmers. It meant an experienced programmer could re-use their knowledge and get up to speed quickly. But what about going the other way? I know a fair amount of Java but, for my sins, have always avoided C++. Now I need to learn it. Fast. Not just the syntax, but also about the various standard libraries out there. Now that Java is the standard language on most computer science courses I guess there will be a few people in the same boat. Can anyone recommend a good book (or any other information source)?" For those Java programmers among us who have gone this route, what books did you use to assist you in the transition to C++? How well did these books work for you?
My advice, take it or leave it... (Score:1, Informative)
Switch jobs fast. You do not want to get into C++. It's a freaking mess. Remember Alan Kay, father of OO? Here's a quote:
I invented the term 'object-oriented' and I can tell you I did not have C++ in mind.
-- Alan Kay
Re:My advice, take it or leave it... (Score:2, Insightful)
computer science 101: pick the right tool for the job.
Re:My advice, take it or leave it... (Score:1)
I totally agree. Too often people get so wrapped up in what's cool about their language of choice that they refuse to see that no single language or programming model is always the right choice.
For building large, web based apps with multiple back-end legacy and database systems, thousands of simultaneous users, and dozens shared components, J2EE has been a godsend. It has gotten rid of a hundred headaches with development, maintenance and administration. But that doesn't mean that there's not a place
Re:My advice, take it or leave it... (Score:3, Insightful)
Anyway, if you want to learn C++ fast, I suggest getting a couple good books, a lot of coffee, and a compiler. It'll take a short year or so, but it's completely worth it.
This is not a flame - I'm a C++ fan. It's my favorite language. But if you think you can learn it well in less than a year, you're kidding yourself.
Re:My advice, take it or leave it... (Score:2)
You're right. It should take 10 years. Because 10 years is the time it takes to go from picking something up, to being really really good at it.
-Start golfing today, in 10 years you might be good.
-Pick up a guitar today, in 10 years you might be good.
-Start C++ today, in 10 years you might have mastered all of it.
Re:My advice, take it or leave it... (Score:3, Informative)
LOL. You know he won the Turning Prize for SmallTalk.
Re:My advice, take it or leave it... (Score:1, Funny)
Really? In what direction was it turning?
Re:My advice, take it or leave it... (Score:2)
Re:My advice, take it or leave it... (Score:2)
Re:My advice, take it or leave it... (Score:1, Insightful)
"With great power, comes greater responsibility".
Didn't ANY of you ever read Spider-Man ?
Part of why the current crop of developers has so much "faith" in j
Re:My advice, take it or leave it... (Score:1)
STL is important (Score:4, Informative)
Good luck!
Re:STL is important (Score:4, Insightful)
Re:STL is important (Score:2)
I still have nightmares.
Re:STL is important (Score:2)
My thought was to make the beginner do everything without STL at first, to learn, and to increase their desire for something like the STL to make their lives easier.
no API (Score:3, Informative)
However, might I recommend this [sgi.com] for the STL?
I think that in searching for a book, you should probably look for one that highlights the differences between the languages. That helped me when I was learning Java, and it's probably the quickest way you can pick it up. Have a look at Amazon [amazon.com] and just search under books for "java c++". The first few entries are aimed at this. I can't vouch for these books, but hey, that's what I found.
C++ is better for... (Score:2, Offtopic)
I learned C++ first and I found it easy to learn. Then I learned java, and i find it similar. The only difference that might be hard to grasp is the difference pointers and references have between the two. Just look up a website listi
book we use for 15-113 (Score:4, Informative)
Do us all a favor (Score:5, Insightful)
Trollish? True! (Score:5, Funny)
Re:Do us all a favor (Score:4, Informative)
Learning C++ for any practical use will take time and practice to learn all of the nuances, especially the copy constructors, operator overloading, and all of that junk.
Re:Do us all a favor (Score:2, Insightful)
If the guy has been writing code for a while, he can make the switch. I'm guessing he's working in C++ shop, thus there will be some senior coders around to help him out.
Re:Ask Slashdot: where Google Morons ask questions (Score:2)
But, if he had typed in "C++ for Java", as I did, here's a useful link. [umass.edu]
Re:Ask Slashdot: where Google Morons ask questions (Score:3, Informative)
Re:Ask Slashdot: where Google Morons ask questions (Score:2)
On the other hand, as many point out, it really takes at least a year or more to learn C++. Isn't that true with any complex language?
Re:Ask Slashdot: where Google Morons ask questions (Score:1)
No. If the grandparent is right (I didn't check, of course) then it's not a good start. It teaches you things about the language that are actively wrong (that it has no string type) and doesn't teach you things th
Re:Ask Slashdot: where Google Morons ask questions (Score:3, Informative)
Ok, now having actually read the link, here is a list of things that are either actively wrong or totally unhelpful:
instead of
Re:Ask Slashdot: where Google Morons ask questions (Score:1)
Re:Ask Slashdot: where Google Morons ask questions (Score:2)
#define should NEVER be used for anything except to protect headers from being included multiple times or to separate non-portable code. As mentioned, const variables and inline functions provide the exact same functionality and performance(on a good compiler), but also have type checking. If you don't want type checking, use an inline template.
Unions are the most useless feature of C++. I find void pointers easier to deal with in the rare circumstance that som
Re:Ask Slashdot: where Google Morons ask questions (Score:1)
Consider:
While internally to the compiler a and b may be (and often are) pointers, that fact is hidden from the programmer and is in no way guaranteed. Howev
Re:Ask Slashdot: where Google Morons ask questions (Score:2, Informative)
The link in the above post (see parent) seems to be broken for me. I don't know if this [amazon.com] happens to be the same book as the one above...
This is the book that my Survey of Programming Languages professor suggested for those of us who came in knowing Java but not C++.
It's nice in that it compares and contrasts many features of both languages (including quite a bit on the STL and writing templates in C++), but I found myself wishing it would have gone into more detail several times - my one gripe is that it
Re:Ask Slashdot: where Google Morons ask questions (Score:2)
The original poster may or may not have done some of this research themselves, but many people would much rather get advice from experienced users than rely on a resource they find on the web which may or may not be accurate.
Also, you can't tell the worth of a, say, book without reading. It's helpful if someone else says "I've read this book an
Lying during job interviews (Score:1, Flamebait)
Now about c++. Boot linux, bring up kdevelop, create a console project and start writing.
What's that? You need to program windows apps! OMG!! You are a big liar!
Re:One word: Don't. (Score:2)
now if you're in the position of starting a project/company yourself, obviously avoiding c++ is a good thing from the start.
Re:One word: Don't. (Score:2, Insightful)
Most of those languages are scripting lanugages and aren't really what you'd program a major application in. I know I user perl for sys admin tasks and quick hacks to just 'get things done'
If you're going to beat up on C++ tell them to move away give a decent language to mov
Re:One word: Don't. (Score:1)
Get in touch with reality, just because you CAN do something, doesn't mean you should, or weren't the rest of your l
Re:One word: Don't. (Score:1)
To VHLLs, of course. I thought I was clear on that point.
> The only other languages you mentioned where[sic] Perl, Python, Ruby, or
> Scheme. I have yet to use Ruby or Scheme, but I did look up some things
> on them.
Try learning one of them.
> Most of those languages are scripting lanugages and aren't really what
> you'd program a major application in. I know I user perl for sys admin
> tasks and quick hacks to just 'get things done'
A good langu
Re:One word: Don't. (Score:1)
In reponse to writing code, and debugging it. Well if written well and I try to keep good practices, I usually don't have a problem debugging C. As programs get larger eventually CPU consumption becomes a problem. And using Perl or another scripting language just looses practicality
Re:One word: Don't. (Score:1)
"ML, OCaml, Haskell, Lisp etc, are all compiled languages, with runtime speeds comparable to compiled C/C++."
If you read from the introduction to Haskell itself, even THERE it clearly states that in cases where "In applications where performance is required at any cost" ( direct quote ) C( and by inference C++ ) is the better choice, and since I've yet to see a Lisp compiler generate code anywhere NEAR what a C/C++ par
Re:One word: Don't. (Score:1)
Wouldn't you be better off choosing a language which is more expressive, flexible, and lets you produce a solution sooner? You can always change algorithms, or call out to lower level code if you need better performance.
These benchmarks [dada.perl.it] compare many languages. OCaml and Lisp do quite nicely vs C/C++.
It comes down to using the best tool for the job. It
Re:One word: Don't. (Score:1)
Whomever in the python newsgroup got the impression that C++ was premature optimization obviously show little mature of character, much less of programming, or application much less algorithmic design. It's not meant as a personal affront to them, but in general. In college you have it droned into you that things be generalized as this, or that, when in reality, you'll hardly ever truly run across generalizations when developing solutions f
Re:One word: Don't. (Score:1)
You are talking as if C/C++ are the last wo
Re:One word: Don't. (Score:1)
Writing Perl is easy. Reading Perl, that's hard. (/Scotty)
Re:One word: Don't. (Score:1)
Use a Typical C++ Programming Book (Score:1)
C++ THEN Java (Score:2)
One thing that seems apparent to me is that it is much more inherently difficult to go from a higher level language like Java to a lower level language like C++, because starting with Java the programmer becoms accustomed to not having to think about things which become major problems in a C++
Re:C++ THEN Java (Score:2, Informative)
The change was so welcome that now I use C++ with wxWin almost exclusively, even if somethimes I have to use Java (because someone pays me to use it).
It has not only GUI classes but several data structures and system functions that make very easy to leverage the operating system API without actually going down and using it. Try to make a nice screensaver in Java.
There is something I miss from Java, because I have to implement similar thing
My Opinion (Score:4, Insightful)
Re:My Opinion (Score:3, Insightful)
Re:My Opinion (Score:1)
Re:My Opinion (Score:2)
What does any of that have to do with learning C before C++? C++ includes pretty much everything that's in C, but renders some of those things obsolete because it has better features. All one does by learning C first is learn the bad / old way of do
You don't need a Java to C++ book (Score:5, Insightful)
Overall, coming from Java, you won't expect or know how to use fancy language features. That's Ok. Write C++ like you would Java (mmm, careful about that memory leak though). This assumes you're doing app development where you can afford to make every function virtual, every object a reference, and have accessor functions for every member variable. If that's not what you're up to and you need write tight C++, well, forget Java while you learn C++. Make sure you get your memory models straight--stack vs heap, by value and by reference, pointers vs reference, iterators vs pointers, reference counted, and on and on. You have to get the now classic "Effective C++" books by Scott Meyers. That's the best way to avoid classic stupid C++ mistakes. You'll find it a bit heavy going at first, but until it makes sense to you, you're probably writing bad C++. Good luck.
Re:You don't need a Java to C++ book (Score:3, Informative)
You'll Miss the API (Score:2, Informative)
Also check out www.cpprefe [cppreference.com]
Re:You'll Miss the API (Score:3, Informative)
Anyway, a few posters seemed to mention the Java API -or the SE part in J2SE, which to me seemed to be an alright compilation when I toyed around with Java. One should remember that C++ has all the libraries Java does, usually more and in various forms for one to pick and choose from. Google is one's friend for library-hunting aside from the nigh-obligatory boost.org libraries.
zerg (Score:4, Informative)
You will spend the rest of your life learning C++, anyone who says they "know" the language is either lying or deluding yourself. After you're done w/ Accelerated C++, pick up Modern C++ Design by Alexandrescu. Also get a subscription to C/C++ Users Journal.
Sympathy (Score:2)
After ten years of C++ programming, I'm underwhelmed with C++. It's broken, and Strostrup is in denial about its flaws. If C++ wasn't broken, we wouldn't have needed Java or C# or Objective-C, which, after all, look a lot like C++.
The basic problem with C++ is that, alone amongst major programming languages, it has hiding without safety, which is a terrible combination. C has neither hiding nor safety. Java, Perl, Python, Ada, and LISP have hiding with safety. This has nothing
Re:Sympathy (Score:2)
Microsoft never used MFC for their own development of code. It's all C. Nor was C++ ever really a priority at Microsoft until Visual Studio .NET; the Visual C++ 6.0 standard library was considered a sick and cruel joke, almost gratuitously incompatible with the real C++ standard library.
You obviously
Re:Sympathy (Score:2)
A lot of people don't seem to realize this, but ObjC was created around the same time as C++. It wasn't made as a response to C++, but rather they were both responses to the idea of gluing OO onto C. Just a minor nitpick to a very good post.
C++ for Java Programmers, (Score:2, Informative)
some source suggestions (Score:1)
For syntax:
C++ in a Nutshell
by Ray Lischner
OR
Sams Teach Yourself C++ in 10 Minutes
by Jesse Liberty, Mark Cashman
For examples:
The C/C++ Users Journal (from the publishers of Dr. Dobbs)
http://www.cuj.com/
Effective C++ Cd: 85 Specific Ways to Improve Your Programs and Designs
By Scott Meyers
Frankly, there are a ton of similar books out there...
At some undisclosed site (Amazon.com) their data miners|web age
The three needs of Java2C++ programmers (Score:4, Informative)
For getting into the STL, I chose Accelerated C++ by Koenig and Moo. It is very basic at the beginning. However, it's not a 700-page behemoth (a Good Thing), it approaches C++ as OOP from the outset, and it starts using the STL from chapter 1. I'm sure you'll need a full STL reference after this book, but it serves as a decent starter. (I also have "The C++ Programming language" by Stroustrup and it's a bit too close to a language definition... good reference, bad primer)
For the tips, Scott Myers books can't be beat. Enough people have heaped praise on them that I won't bother with it here.
That leaves the last part of my education: "how do C++ programmers organize code". Unfortunately, the C++ world doesn't seem nearly as unified as the Java world. I started out doing things very Java-like, but decided that probably wasn't going to work if I eventually start coding with other people. Accelerated C++ has some tips. The C++ Programming Language also has a lengthy discussion on how to organize your code. Being the completely anal guy I am, I wanted to get it right the first time. Unfortunately, that's not possible. My style is still changing frequently as I see elements I like. I'm sure it will calm down if I ever get a job in a C++ shop.
Re:The three needs of Java2C++ programmers (Score:1)
Things to consider when coming to C++ from Java (Score:4, Insightful)
Here's (on the top of head) what comes to mind when I think ab out moving from Java to C++:
In C++ you can place objects on the stack with no need to allocate an object on the heap.
Re:Things to consider when coming to C++ from Java (Score:2)
You are incorrect about Java.
In Java, everything is passed by value. You never pass objects by reference, you pass references to objects by value.
Re:Things to consider when coming to C++ from Java (Score:1)
http://www.javaworld.com/javaworld/javaqa/2000-
Re:Things to consider when coming to C++ from Java (Score:1)
The object *reference* is passed by value, but it's still only a reference.
Later, he says:
"Java copies and passes the reference by value, not the object."
But, you're right -- I could have read the article more closely. I would have linked one of the other hits.
Re:Things to consider when coming to C++ from Java (Score:1)
Re: You are incorrect about Java.
In Java, everything is passed by value. You never pass objects by reference, you pass references to objects by value.
You are incorrect, well, not really as you just said the same thing as the original poster did but in
Re:Things to consider when coming to C++ from Java (Score:2)
I'm not incorrect. The OP said
while I said
That's not the same and there's quite a semantic difference between those two.
The way I told it is correct. And even you yourself say:
Re:Things to consider when coming to C++ from Java (Score:1)
In C++ where you can access an object directly, though a pointer, or by a reference there is a difference.
Therefore, you are incorrect to state that the original poster was incorrect, thougth as you say... you just rehashed the view of the original.
You might w
Accel C++ (Score:3, Insightful)
after c++ learn c# (Score:1)
Why hasn't anyone recommended Thinking in C++? (Score:3, Informative)
free book online (Score:2)
(disclaimer: one of my livejournal interests is "informed dislike of c++". ;))
Bruce Eckel has written some fairly good (IMHO) books on c++ and Java. You can download them for free from here [mindview.net]. The thing I like best about his approach is that it tries to teach you more than just the syntax, also (as the titles suggest) how to think in that language. The only con to his writting style is that his examples are sometimes a little contrived...
As other posters have said, do try to learn the STL as soon as po
I've done exactly that ... (Score:1)
Also, this [brown.edu] tutorial is full of useful information. However, you have to ignore the occasional bitter remarks about Java from the author, such as these gems:
Unlike Java, C++ is a fast, powerful, and flexible programming language.
Java was built as a simple-to-learn subset of C++ for set-top boxes and drooling AOL users. Now, it's time to play in the big leagues.
What I used.... (Score:2)
The C++ Programming Language [amazon.com] is of course the gold standard if you need to go deeper.
I have also heard good things about Accelerated C++, but haven't looked at it myself.
Thoughts from a java convert (Score:1)
Things I wished I'd realised sooner:
1) Learn how to use (or write, if you're brave) STL iterators with containers.
2) Learn the difference between the stack and the heap.
3) Use memory leak checkers (eg. valgrind), as you WILL get memory management incorrect.
4) Realise that destructors in c++ are actually useful, in that you know (more or less) when they'll be run.
I've read so