13 ms·
The New C++: Lay down your guns, knives, and clubs
- SamReidHughes 15y ago<tl;dr> C++0x is pretty nice. </tl;dr> But ultimately, as long as it lacks memory safety, it lives in a mostly parallel universe from Java and everything else. It's not really becoming more Java-like. It's becoming more C++-like. C++0x goes in the direction of having better support for existing C++ idioms.
- lutorm 15y agoit lives in a mostly parallel universe from Java and everything else So the top 3 programming languages are Java, C, and C++, with C/C++ together larger than Java. Maybe it's Java that lives in a parallel universe?
- kleiba 15y agoI don't get your point. If A lives in a parallel universe from B, then B lives in a parallel universe from A. I think what the grandparent wanted to say is that memory management is a defining difference between the paradigms of both languages. There are some people who value the fact that they have full control over allocation and de-allocation and others who think that these are things the programmer shouldn't (have to) care about, because they're known to be error prone.
- joe_the_user 15y agoThe original parent said "Java and everything else", leaving an implication that unmanaged memory stuff was marginal. I think that's what the gp is addressing.
- SamReidHughes 15y agoNope, kleiba correctly interpreted my comment :)
- cageface 15y agoI've always imagined Herb Sutter as a Gandalf-like figure and here he is looking like a partner in a New York law firm. I guess it is possible to achieve guru status without a beard. I can't wait to get support for the "auto" keyword in XCode.
- jpr 15y agoApparently he has had a mustache, so no guru status without facial hair yet: http://www.xb360info.com/images/herb_sutter.jpg http://www.xb360info.com/images/herb_sutter.jpg
- Luyt 15y agoHa, you should have seen Alex Martelli while he still had a moustache: http://images-mediawiki-sites.thefullwiki.org/05/3/0/3/3237892484320994.jpg http://images-mediawiki-sites.thefullwiki.org/05/3/0/3/32378...
- nl 15y agoInterestingly, C++ was ratified as an ISO standard just as Java failed to get ISO pick-up after a campaign by Sun Actually, even more interestingly, Java failed to become an ISO standard because Sun didn't want it (at the time they were worried about the potential influence of Microsoft).
- reedF211 15y agoGarbage Collection, Garbage Collection, Garbage Collection, where is garbage collection?
- yonilevy 15y agoC++0x introduces a bunch of smart pointers to the standard library (and boost provides them externally for previous versions). What are the advantages of garbage collection over these?
- barrkel 15y agoThe mere fact that you have to use smart pointerS is enough of a drawback; not only do you need to start decorating various types explicitly, but you must choose which smart pointer types are appropriate, and avoid issues of circular references (in the case of refcounting) and persistence of references (in the case of scope-guarded objects tied to a stack frame); worry about logical ownership hand-off from one smart pointer container to another, etc. The real power of GC, though, is freedom to use idioms that are simply impractical, or especially, not exception safe, in its absence (see my comment earlier).
- Rexxar 15y agoIt's really not such a big deal if you use "new" parsimoniously and use containers and RAII as much as you can. I can count on my hands the number of new and delete I have written in my code in the last three years.
- barrkel 15y agoIt's rather harder to count the number of times there were idioms you could have used but didn't because using them in C++ wouldn't have been practical or efficient. I'm thinking in particular of closures which captured state, and functional/monadic style chained method calls each building on the previous function's return value (think: something like .NET LINQ).
- 15y ago
- hendler 15y ago"... the Apache MapReduce clustered data-processing architecture ..." I'm not very familiar with internals of Hadoop - but thought this was mostly Java.
- DannoHung 15y agoDoesn't change the fact that the C++ design is a giant ball of mud.
- CountHackulus 15y agoCare to back up that statement? Can you explain how objects and patterns in C++ make the design worse than objects and patterns in another language?
- cousin_it 15y agoHere's a list of what seem to me, in hindsight, to be the biggest mistakes in the design of C++: 1) Header files. They don't improve your code or your build process in any way, they just make you retype everything twice and make the compiler reprocess everything as many times as it's included. There's no reason why even a low-level language today can't have a module system like Java's, where everything is typed in and compiled only once. 2) Having exceptions without having garbage collection. Having both of these, or none of these, would have been OK, but having one and not the other makes writing exception-safe code unnecessarily difficult. It took people years to write the first correct exception-safe container class and understand all the tricky leaks that can happen. See Tom Cargill's 1994 article: http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/aw/meyerscddemo/DEMO/MAGAZINE/CA_FRAME.HTM http://ptgmedia.pearsoncmg.com/imprint_downloads/informit/aw... and Herb Sutter's failed answer in 1997: http://www.gotw.ca/gotw/008.htm http://www.gotw.ca/gotw/008.htm . 3) The template mechanism is too general and not a good fit for many of the tasks that people are trying to solve with it. Easy tasks like parameterized container types would've been better solved with a simpler mechanism like Ada generics (no specialization, no implicit instantiation, only one copy of object code, possible to compile separately). Harder tasks should be solved with purpose-built mechanisms, e.g. if you really need lambda, build it into the language. Faking lambda with templates isn't much better than faking it with preprocessor macros. 4) Strings should've been built in, and done right. There must be only one string type (Unicode). All string literals must be instances of that type. No null-terminated strings anywhere, they're a very bad default. If your application demands shaving a couple cycles from operations on character buffers, you can always use custom code. I'm not asking for garbage collection, multithreading, GUI toolkits or any other fancy features. C++ could've gotten these five things right and still be a very good fit for all the bare metal speed hackery that people want.
- nuttendorfer 15y agoCan somebody recommend a good C++ book without all the new to programming parts?
- CountHackulus 15y agoIf you really want to dive straight into the deep end, I'd recommend Modern C++ Design by Andrei Alexandrescu. But if you want just a gentle introduction to C++ I'd suggest The C++ Programming Language by Bjarne Stroustrup. Both of these authors are staples in the C++ world and so their advice is usually worth their weight in gold.
- btilly 15y agohttp://www.cplusplus.com/doc/tutorial/ http://www.cplusplus.com/doc/tutorial/ is surprisingly useful. And free.
- kenjackson 15y agoYes, the following I recommend: Advanced C++. http://www.amazon.com/Advanced-C-Programming-Styles-Idioms/dp/0201548550 http://www.amazon.com/Advanced-C-Programming-Styles-Idioms/d... Any and all Herb Sutter books. Effective C++, More Effective C++, and Effective STL ... all by Scott Myers. With those you're 90% set. What you'll need to supplement with thoough is something that covers the 0x standard.
- ajays 15y agoFTA: "the Apache MapReduce clustered data-processing architecture, ... is written in C++" Really? Hadoop is pure Java.
- deleted 15y ago[deleted]
- deleted 15y ago[deleted]
- hello_moto 15y agoCorrect me if I'm wrong, HDFS is written partially in C.
- revertts 15y agoYeah, that caught my eye too. I assume they just got Hadoop mixed up with Google's C++ MapReduce implementation.
- wglb 15y agoI have a lot of respect for Herb Sutter--his articles on difficulty of multiprogramming are worth study by all. But there is an element of Kool-aid in his comments about other languages. Hadoop is written in Java; much of the world is written in C, and in very restricted versions of C++. I say this as one who did 10 years in industrial-strength C++ programming. If you look at C++ without rose-colored glasses, it is a pretty frightening prospect. Modern C++ Design by Andrei Alexandrescu is a very awesome book, but the fact that there are surprises in it for Scott Meyers should give the student pause. And to all of you who are beginning programming, you will be better off in the long run if you become proficient in several languages. I predict that in your successful career you will be ahead if you are able to pick up new languages rapidly. Time spent mastering C++ might not be the best use of your learning budget.