Transition from c to c++ , difficulty.

Started by
13 comments, last by deathtrap 21 years, 1 month ago
If you think of it as a ''transition'', it will be more difficult than if you think of it as learning a new language.

[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
1. Learning C++ is not *just* learning OO. C++ is a multi-paradigm language, not only OO.

2. See C++ as a new language. Stop learning C as fast as you can. Learn C++ instead. C is bad. There are far better languages than C+ + out there, but none as made it to mainstream.

3. You should buy two books (the most popular ones). Bjarne Stroustroups "The C++ programming language". Great book to learn C++. Later you need the "C++ FAQs". The online lite version is a good start.

4. C sucks.

5. Accept that it will take a looong time to master C++. Impossible without the C++ FAQs.

6. Stop learning C.

7. When you are quite familiar with C++: Learn how and when to use the features of C++. Learn about Design Patterns. This will help you getting a clue what one can do with OO and the other C++ stuff. This is an important part. You have to understand the paradigms, the priciples.

8. Concentrate on C++.


4., 6. and 8. want to talk to your subconscious mind. Let them in.
I learned C++ from a book written for people moving from C to C++. The guy who wrote it had also moved from C to C++ but actually didn't get it . This set me back for years.

C++ contains C (pretty much). So it is quite possible to program solely in C and use a C++ compiler and call your file .cpp or .cxx or whatever your compiler expects. I suppose you could call that programming in C++ and in some ways that is almost the level that the guy who wrote the book was still at. To use C++ fully you have to learn to think differently.

The extra things that C++ brings you, the keywords and semantic additions, they actually mean you can do things differently. What this means is that you can think about problems in new ways. Learning to think in new ways can be difficult because you have to give up thinking in other ways that you are used to (this applies to all life learning - changing your view of the world). There are things that can help though.

I would recommend learning something like ruby or python (or even java) to help get into one of these new mindsets, which is the object oriented approach. There is also another aspect to C++ which is it's generic abilities. Python again would be a great help I think. The language's concepts can be learned quickly and the language itself can be learned within a few months or even weeks.

Another thing that C++ brings to the table, as Alpha_ProgDes alluded, is a library of useful objects and functions. C obviously has a library of its own and C++ is perfectly capable of using it. But with the shift in C++'s capabilities which came with objected oriented programming and generic programming, a whole load of new posibilities presented themselves. There are containers which will store a linked list (you'll never have to design your own again... you can spend your time thinking about what that list really represents in your larger design). It won't just be a load of void pointers that you need to cast. It will adapt to whatever type you want to store (at compile time, ie you have to make the decision while you're programming, not while the program's running). This is generic programming and means you can write code once and have it vary with type. Imagine a simple function that takes two parameters and adds them togther and returns the value. You could write one for doubles one for ints one for floats maybe. If you write it as a generic template you write it onece and then when you use it the correct version will be called. It would work with strings, that is C++ strings, not C strings. You could specialise it for C strings to do all the memory management. That's getting a bit too involved for now. This is only scratching the tip of the iceburg. There are algorithms which do a wide variety of repeated functions on containers which you can extend in various ways. This means you may never have to write a loop again (does that scare or excite you?) The c++ standard library makes use of all kinds of language features which enable you to think and do things in very different ways to C.

A problem that people have coming from java or python to c/c++ is the freedom they have to abuse the machine. Memory management isn't much of an issue in java, python or ruby but it is in C++. It can be a shock to the system. You won't have that problem because you've gotten a good dose of that with your C background. However there are ways to deal with it, beyond just the language, in the standard library and other libraries such as boost. These methods can make memory management issues far simpler.

I hope you enjoy learning C++ as it is an amazing and frustrating language.

Pete

[edited by - petewood on March 3, 2003 4:45:03 AM]
!

Wow, now i''m more confused than ever...
Thanks for your responces though.
Go not unto Gamedev for advice, for you will be told both yea and nay (and quite a few things that just have nothing at all to do with the question).


"If there is a God, he is a malign thug."
-- Mark Twain
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]

This topic is closed to new replies.

Advertisement