C++ ( Computer Language )
Even though it's old, I really liked the treatment that Allen Holub gave to the subject in his book, "C + C++: Programming With Objects in C and C++." Back when he wrote the book, C++ was a strict superset of C. You might see him mention that. That is not true today. What I'd say is important about his treatment is he shows you what the C++ compiler does under the covers, conceptually, so you'll understand what each C++ expression does for you, and what it doesn't.
Program Designing
You won't need to read the first third of the book, which teaches the basics of C. After C basics, it starts you off building some object-like structures in C. You realize you can only go so far with it, and then he shows you what C++ does to take the idea to the next level. It's a gradual introduction to C++ re. classes, instances, and inheritance. He also covers operator overloading, polymorphic functions and methods, references (or aliases), and what the different positions of "const" mean in variable declarations.
The only significant subject he leaves out entirely is templates, which is not a minor omission. The reason for this is that templates didn't exist in the language at the time he wrote it. Despite this deficiency, I think it's a great introduction to the essential concepts of C++. Once you get through this book, you can learn about templates, and how C++ departs from C's ancestry, from other sources.
Edit 5-4-2015: After answering C++ questions for a while on here, it's been gradually dawning on me that C++11 has changed a lot of things in the language. The syntax looks the same as I remember, but the semantics have changed significantly. This is making me think that it's likely many of the examples Holub used in his book will no longer work as-is on a modern compiler. You'd have to use a compiler that's roughly from the era in which he wrote it. I'm thinking that a C++98 compiler might work with the examples, but I cannot confirm that. This is disappointing, since it makes it harder for beginners to C++ to use what I think was a great book for beginners, but I understand that languages need to improve with time, and that is likely going to break old code.
Either Bjarne Stroustrup's book, mentioned earlier, or C++ Primer by Stanley Lippman (also Addison Wesley) to get you started.
Then, regarding best practices, I have found Scott Meyers' Effective C++ books (Addison Wesley) to be of enormous benefit. Nearly all the advice given by Scott in his books has been relevant to my work (can't say that for a lot of other books I have read, which sometimes tread into waters that, while interesting, may not be particularly useful to the average C++ programmer).
The original Design Patterns (Gang of Four book) covers important best practices regarding how to design object oriented code which will help to separate you from being a C++ programmer who codes mostly in C, and a C++ programmer who is using the language to its advantage.
the most important aspect for me is
- “ C is not a subset of C++ (anymore). Over the time both C and C++ have evolved and diverged substantially.
- Although C++ is not truly object oriented, get a feeling of object oriented design patterns.
- Dont use a C++ compiler as a C compiler. Explore the unique features of C++ in your code and don't get your work done with a C style work around. Eg: if you are using a pointer chain, instead of a reference to a pointer, then most likely you are doing it wrong.
- Understand the existence and importance of vTable in the context of inheritance and the power of operator overloading.
- All the Scott Meyers’ C++ books are absolutely brilliant. And as mentioned in “Effective C++ “, treat C++ more as a union of different languages. (Aka. Don't try to use template, STL/ Boost, all at the same. Do it incrementally).
- Eventually try to stay current and updated with C+11, C++14 standards and may be even C++17 recommendations.
I've come from much the same way as you and as far as I know many current C++ programmers. First I did 3/4 years of C programming and then switched to C++ and been working with it for 15 years.
I agree with Robert Love in the incremental approach but you have to keep in mind that C++ is a whole new language and that a correct approach would be to treat it as such and to aim to end up programming in a completely different way than C.
Essentailly C can be described as a high level assembly language while C++ can be
described as a high level language programming in terms of concepts and abstacions rather than hadware implementation.
With that in mind you should aim at forgetting about void *, malloc/free, explicit type casting, resource identifiers, even pointers in general as much as you can and focus on the expressiveness of the language. Specially in basic features like const, references and the resource adquisition is initialization RAII idiom.
I hope this helps since it did take me some time to learn all this as I kept using the techniques I used in C and they still worked. It was a true epifany when I realized that C++ is much much more than C with classes.
It also is a great help to learn about general object oriented programming aside from specific language features like the GoF Patterns.
I agree with Robert Love in the incremental approach but you have to keep in mind that C++ is a whole new language and that a correct approach would be to treat it as such and to aim to end up programming in a completely different way than C.
Essentailly C can be described as a high level assembly language while C++ can be
described as a high level language programming in terms of concepts and abstacions rather than hadware implementation.
With that in mind you should aim at forgetting about void *, malloc/free, explicit type casting, resource identifiers, even pointers in general as much as you can and focus on the expressiveness of the language. Specially in basic features like const, references and the resource adquisition is initialization RAII idiom.
I hope this helps since it did take me some time to learn all this as I kept using the techniques I used in C and they still worked. It was a true epifany when I realized that C++ is much much more than C with classes.
It also is a great help to learn about general object oriented programming aside from specific language features like the GoF Patterns.
More interesting for you from Computer Science Department ......Computer science Vs Stastics
No comments:
Post a Comment