From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII From: Aharon Robbins Message-id: <201211192002.qAJK21GB003157@skeeve.com> Date: Mon, 19 Nov 2012 22:02:01 +0200 To: 9fans@9fans.net References: <7a746291161fe83e1df0401af21f6ce4@quintile.net> In-reply-to: <7a746291161fe83e1df0401af21f6ce4@quintile.net> User-Agent: Heirloom mailx 12.5 6/20/10 Subject: Re: [9fans] c++ Topicbox-Message-UUID: da45abea-ead7-11e9-9d60-3106f5b1d025 Hello Steve, 9fans. > I need to learn c++ for work - people have strong opinions on > languages I know, and not everyone likes c++ but its a requirment for me. > > I really want to develop a good sence of c++ style, I learnt C at the feet of > K&R and then the plan9 sourcecode so I learnt how to write clean elegant code > (I think :-). The problem I am finding is there are many c++ styles and I have > yet to find a clean and elegant one. > > anyone sugest a project that I could look at that contains well written code? > failing that is there a book that teaches good style? This letter may end up being a bit long, and will be contrary to the popular wisdom on 9fans. So be it. I have over 30 years of C and Unix experience and ~13 years of C++ experience. For whatever that's worth. I will try to offer practical advice on the assumption that you want to keep your job and therefore you want to learn C++ and learn it well. First, realize that C++ is a MUCH bigger language than C. There's more to C++ style than just naming conventions. You should work to understand the language features, first, and in particular understand that they often interact in somewhat strange ways. For learning the language, you should probably go with the C++ Primer by Lippman, Lajoie and Moo. I see that a new edition just came out: http://www.amazon.com/Primer-5th-Stanley-B-Lippman/dp/0321714113/ref=sr_1_1?s=books&ie=UTF8&qid=1353353296&sr=1-1&keywords=c%2B%2B+primer Write some code, get a feel for things. Work your way up slowly, since there's a lot to learn. To understand the intricacies of C++, you can't do better than Scott Myers "Effective C++", "More Effective C++" and "Effective STL": http://www.amazon.com/Effective-Specific-Improve-Programs-Designs/dp/0321334876/ref=sr_1_1?s=books&ie=UTF8&qid=1353353626&sr=1-1&keywords=Scott+Myers+C%2B%2B http://www.amazon.com/More-Effective-Improve-Programs-Designs/dp/020163371X/ref=sr_1_4?s=books&ie=UTF8&qid=1353353626&sr=1-4&keywords=Scott+Myers+C%2B%2B http://www.amazon.com/Effective-STL-Specific-Standard-Template/dp/0201749629/ref=sr_1_3?s=books&ie=UTF8&qid=1353353626&sr=1-3&keywords=Scott+Myers+C%2B%2B In addition, a book that I found really helpful was Stanley Lippman's "Inside the C++ Object Model": http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545/ref=sr_1_1?s=books&ie=UTF8&qid=1353353699&sr=1-1&keywords=C%2B%2B+object+model Lippman worked with Stroustrup on cfront at Bell Labs, he's been involved since the beginning. Also, he's a great writer. Despite the scorn expressed here for Design Patterns, they have value. The canonical reference is the book by the Gang of Four: http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612/ref=sr_1_1?s=books&ie=UTF8&qid=1353353825&sr=1-1&keywords=Design+Patterns Not all the patterns see the same amount of use in C++, but a few are critical for understanding and working with everyday C++: Factory, Singleton and Visitor come to mind, there are some others. In any case, the book is worth having as a reference. Java and C# provide large "frameworks" out of the box (vendor supplied), making programming in them a much more "pick the parts and stich them together" practice. C++ does not have this, although the Qt framework goes a long way towards filling the gap. The Qt classes are well designed and make for clean code that also avoids your having to reinvent certain wheels yet again. C++ is far from a perfect language. It tries to be many things to many people. Using it well requires discipline on the part of the programmer, as opposed to newer languages where the compiler imposes much of the discipline. The Myers books will help with that. And it's possible to do awful things with it. I think template metaprogramming is the work of the devil and regular programmers shouldn't even consider going anywhere near it. And yes, there's a lot of miserable C++ out there. There's also a lot of miserable C and shell and even awk code out there. This just proves that there are lots of crappy programmers. However, having worked on a project containing over 4 Million lines of C++ code, I can say that there are things you can do with object oriented design and code in C++ that you simply could not do were you trying to do them in C. Some of the cleanest and most elegant code I have ever seen, as well as some of the best code I have ever written, was in C++. There is much, Much, MUCH more that could be said, for and against C++. I'm probably aware of most of it, so don't bother flaming me. I do think that C++ is worth learning, knowing, and using well. (I think that Walter Bright's D is an even better language, but that's another story.) So Steve, look upon this as an adventure and keep an open mind. You may find that you are doing new, different, and maybe even enjoyable things as your horizons open up. I think the books I've listed will give you a good start if you're serious about working in C++. There are others I can name also. Feel free to ping me (probably best off list - remove the 9fans from the subject header so that it doesn't get sent to the wrong mailbox). Thanks, Arnold Robbins