Archived

This topic is now archived and is closed to further replies.

deathtrap

Transition from c to c++ , difficulty.

Recommended Posts

Good day, For those of you who have learned or worked with both languages, how easy of a transition is it to go from working with c to c++? Should I continue to learn C or should I drop it and concentrate on C++ ? Thanks,

Share this post


Link to post
Share on other sites
IMO the transition isn''t that hard.
you''ll have to learn for example:
to print something on the screen you''ll have to use

cout << "Hello World" << endl; // C++ version

printf("Hello World\n");/* C version */


little things like that.
to know both is a benefit to yourself.

Share this post


Link to post
Share on other sites
Going from C to C++ is 1000% more complicated than learning to use cout instead of printf ! That''s the very tip of the iceberg ! It''s not just about learning new syntax, it''s learning the concepts of the language which really are quite different from C. The best way I found to transition was to read lots of programming books, each one explains each concept in a slightly different way and overall that helps you to understand better.

Share this post


Link to post
Share on other sites
You *only* need to learn the principles of OO in order to move to C++.

Personally all I (and most other programmers I know) take from C++ is the OO approach. Once you know how to work with objects you can still use C syntax within them. Apart from swapping malloc for new and free for delete using C syntax within C++ is perfectly valid.

I for one see very little point in using c++ commands such as cout etc when printf, fopen etc work perfectly well.

Share this post


Link to post
Share on other sites
The reason C++ programmers use cout is because you can do something like this:

cout << myObject; 


and it will print out the state of myObject any way you want. This is impossible with printf, etc., since you can''t define your own insertion operators for use with those functions.

Firebird Entertainment

Share this post


Link to post
Share on other sites
Transitioning to C++ from C can be difficult, likely in part due to the fact that C++ tries to introduce concepts to the C language which it wasn''t inherently designed for, both in terms of purpose and structure.

By extending C to C++, it seems the designers handicapped themselves with a paradigm not suited for the concepts which C++ tries to provide, thus making the realization of C++ a complicated product that doesn''t have an elegant or streamlined paradigm.

Share this post


Link to post
Share on other sites
Full c++ is very hard to learn and put to practice. Using a subset of c++ is pretty doable. If you''re doing strict gfx stuff then the choice of the lang. is even less important. If you''re doing data management app then c++ will be more handy. I''m into gfx at the moment and all you need is ''c'' from within ''c++''. I''m spending much more time doing maths and geometry related stuff then strictly programming lang. related stuff. Getting the hang of gfx api and hw is not easy, the least you need is to fight the language at the same time.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I suggest you stick with C for now until you are very comfortable with it. And then pick up "C++ Primer" (Lippman) and "The C++ Standard Library" (Josuttis), forget everything you know about C, and concentrate on the new style of programming. You will benefit from thoroughly knowing both languages. Plus, all too often, people using C++ are only using C with some limited C++ functionality, like classes, etc. Learning both will help you greatly.

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites