![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Feb 2006
Location: 127.0.0.1
Posts: 35
Rep Power: 0
![]() |
moving to C++
I code in C and am looking to move to an object orientated language. The logical step seems C++.
How easy is it to move to this respective language? Is it simply a matter of learning a little extra code or is it a paradigm shift? hush |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3
![]() |
I did that and it was not very hard. Basically, all code that compiles on C it will compile on C++. It is interesting that the C++ compiler will sometimes find errors in your C code that the C compiler was unable to find.
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
It's very easy. C++ unlike C, is a big language though. You can do much more with it then C. Operator overloading is one, for example. So there are some more techniques to learn. OO can be a paradigm shift for some, it was not for me, since it made sense (which is a reason why it was 'invented' in the computer programming area).
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,208
Rep Power: 5
![]() |
The difficulty in transitioning from C to C++ depends on whether you want to treat C++ as an "extended C" (for want of a better description) or if you want to use C++ as it is intended.
Treating C++ as an extended C essentially means continuing to use the C language and library, but making use of features of C++ like better typechecking (the underpinning of why a C++ compiler will find errors that a C compiler won't in C code), function overloading, default argument values, using operator new/delete as an enhanced malloc()/free(), and (if you want to push things a little) starting to use classes to define new types and maybe using templates in some basic way. If all you want to do is this, then moving from C to C++ is fairly simple. Using C++ as it is intended means a paradigm shift (and OO is only part of it; C++ is a multi-paradigm language). If you go down this route, you will be more rigorous about encapsulating data into classes, using C++ rather than C I/O, using the STL, and using advanced features of templates (the template mechanism within C++ is a Turing complete programming language in it's own right), make use of exceptions, etc etc. All of these areas take time to learn and (in fact) learning to use them well is probably a life-long endeavour. Not even experts like Bjarne Stroustrup, Scott Meyers, Herb Sutter, Robert Martin, or Andrei Alexandrescu claim to be complete masters of C++. Most people who move from C to C++ initially treat C++ as an extended C. So, for most people, the transition is not that tough. Late on, however, a fair few people learn that there is a lot more to C++ and that takes longer. BTW: I disagree with nnxion's characterisation of C++ as a big language and C as not. I would characterise C as a large and complex language on it's own. C++ is just larger and more complex than C. |
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
I switched from C to C++ too (doesn't mean I never use C anymore, I still use it). When I started I treated C++, like many others, like an extended C. When continueing using the language, it became for me a language on its own, instead of an extended C.
I used streams first, then I started using simple classes, after that I began using inherited classes and operator overloading, etc. |
|
|
|
|
|
#6 | |
|
Professional Programmer
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4
![]() |
Quote:
It is easy to learn the syntax if you have programmed in C! i.e. You will be able to understand what you are using for input, how you declared variables and..so on... |
|
|
|
|
|
|
#7 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
) projects in C++.Well there is a difference between "small" and "not big". Even Kernighan and Ritchie say on the back of their book: "We have tried to retain the brevity of the first edition. C is not a big language, and it is not well served by a big book." Your points on C++ are excellent, I'm glad you are there to educate us (read: me). On a side note: I took the liberty of talking about projects like lines of code were the only indication of how large projects are.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#8 |
|
Programmer
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0
![]() |
Very good posts above.
Personally, I fit into the category of using C++ in it's own right. I initially treated the language as an extention, but found it much easier to treat it as it's own. When I need C, I use C. When I need C++, I use C++. I seldom ever mix and match the two. Although, I tend to like C more than C++. Not because of it's abilities, complexity, or anything that would technically matter, but I love the nostalgia behind the language. C++ just seems to large and complex for me at times, but C always fits just right. That, and most people who begin their journey as a programmer in this day and age almost immediately disregard C and shoot straight to C++, considering it an obsolete or even an inferior language. In some ways it is, and in some ways it can blow C++ out of the water; it all depends on how you use it and how well you do so. My two cents. |
|
|
|
|
|
#9 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
I reread this thread, and have to add that I did not use C in any of my C++ programs. When using C++ I use its I/O, the STL, use classes and make use of exceptions and overloading operators when I need them. If this is what you meant Grumpy by "using C++ in its own right" then I do.
Although I haven't worked with templates yet.Though I thought you meant something else, as I haven't totally switched paradigms, perhaps I have, due to starting out with C++ (had used some version of BASIC before C++) and went back to C while I was in the middle of using Java. Could you recap what meant Grumpy?
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
#10 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,208
Rep Power: 5
![]() |
Not quite sure what you want me to recap. All I really said is that the difficulty learning C++ depends on how far you delve into it. From what you describe, you're closer to the extreme of using "C++ as intended" than you are to using "C with a few extensions". Nothing wrong with that: few people alive will go to the extreme (and, no, I'm not one of the few). The important thing is that you can do the tasks you intend reasonably effectively, not achieving some nebulous "C++ perfectionist" status.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|