tags:

views:

326

answers:

7

C++ has too many features, and I can't see how any programmer is able to remember all these features while programming. (We can see how this affected the design of newer languages, such as Java)

So, what I need is a list of features that are enough to know, disregarding all the others, to create c++ programs, perhaps created by someone who thought the same way as I did.

Hope I was clear enough.

+11  A: 

Learn Resource Acquisition Is Initialization.

The technique was invented by Bjarne Stroustrup, to deal with resource deallocation in C++.

[...]

RAII is vital in writing exception-safe C++ code: to release resources before permitting exceptions to propagate (in order to avoid resource leaks) one can write appropriate destructors once rather than dispersing and duplicating cleanup logic between exception handling blocks that may or may not be executed.

C++ is an object-oriented language with features like inheritance, encapsulation and polymorphism that is also found in popular languages like Java, C# etc. C++ also features generics via templates. However, in C++ you have to explicitely handle memory deallocation (ie. no garbage collection). This makes it very important to be able to release resources and deallocate memory in a controlled manner, and that is why I believe RAII is a very fundamental concept in C++. You will have a hard time understanding a "smart pointer" unless you understand RAII.

Martin Liversage
That's not a feature. That's a convention and good practice.
Matt Kane
@Matt how is it not a feature? A language either *supports*, *enable* or *disallow* the use of a particular practice. C++ supports RAII explicitly with the required mechanism not just back-doors to hack the thing, thats why it is a feature.
AraK
Agreed with this one. This is the single one idiom that makes robust C++ code *possible*. Screw virtual functions, OOP, templates, functors and everything else in the language. Those can be learned on an ad-hoc basis when needed. If you don't understand and use RAII, your code will be a buggy, leaky, error-prone mess.
jalf
@jalf: Amen, brother!
Drew Hall
+7  A: 

This is really an impossible to create list. Every place I work has a different acceptable subset of C++. So its going to be different depending on what you're developing on. I've seen C++ that truly is just C with occasional use of the "class keyword" to very run-time polymorphism oriented code to template meta-programming heavy code. Then the practices are going to change based on what frameworks/libraries/platforms you are targeting.

The best I could suggest is reading various coding standards and seeing the how they suggest you ought to write code using C++.

Doug T.
"Google's Coding Standard" seems like what I am looking for, thanks a million!
Lawand
Since Google and Sutter differ notably in several places. I would go with the Sutter standard as he is pretty much the C++ man (Head of the C++ standards comitee (or was last time I checked)).
Martin York
Well, in that case I'll check both before deciding
Lawand
Yes I would default to Sutter, but you might decide you want to program using, say, wxWidgets. Then you'd probably just probably program like they program.
Doug T.
+6  A: 

You learn and remember them by having a need for them. I'm not sure what sort of "features" you're looking for. "virtual functions" are definitely something you want to learn, but I don't really know your background. Should I be suggesting polymorphism/class inheritance too? Template classes/functions?

Mark
A: 

I think templates are such a feature...

Jochen Hilgers
Templates is a nice feature and saves a lot of time. But you don't need tolear it first. Its somthing you add when you understand the language.
Martin York
A: 

I think the chapter 4 of Stroustrup's "Learning Standard C++ as a New Language" is the answer to your question.

Nemanja Trifunovic
+1  A: 

Do you have a tool box containing too many tools? Then don't use them all? Use the ones you need.

Read a good book with C++ best practices and design patterns.

Magnus
A: 

Don't be in too much of a rush to master a language. Peter Norvig (of Google) argues that it takes about 10 years to gain a mastery at anything.

Phillip Ngan
Maybe my question wasn't so clear. I am not in rush to master C++. I just want to master a sub-set of the language first, then later go into other details.
Lawand