Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 24th, 2006, 5:54 PM   #1
hush
Programmer
 
hush's Avatar
 
Join Date: Feb 2006
Location: 127.0.0.1
Posts: 35
Rep Power: 0 hush is on a distinguished road
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
hush is offline   Reply With Quote
Old Feb 25th, 2006, 3:48 AM   #2
ivan
Professional Programmer
 
ivan's Avatar
 
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 3 ivan is on a distinguished road
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.
ivan is offline   Reply With Quote
Old Feb 25th, 2006, 4:30 AM   #3
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Feb 25th, 2006, 6:33 AM   #4
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,208
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Old Feb 26th, 2006, 4:07 AM   #5
Polyphemus_
Expert Programmer
 
Polyphemus_'s Avatar
 
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4 Polyphemus_ is on a distinguished road
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.
Polyphemus_ is offline   Reply With Quote
Old Feb 26th, 2006, 4:42 AM   #6
java_roshan
Professional Programmer
 
Join Date: Mar 2005
Location: Student of University of Mumbai, Maharashtra State, India
Posts: 344
Rep Power: 4 java_roshan is on a distinguished road
Quote:
Originally Posted by hush
Is it simply a matter of learning a little extra code or is it a paradigm shift?
hush
It's not just a matter of learning a little extra code. The code that you will write will be based on objects that have some attributes (properties) and functions (roles).

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...
java_roshan is offline   Reply With Quote
Old Feb 26th, 2006, 5:15 PM   #7
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by grumpy
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.
Hmm yeah I use C++ as an extended C, also because I haven't done any large (more than 10 thousand lines, which is probably medium-sized for you ) 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
nnxion is offline   Reply With Quote
Old Feb 27th, 2006, 12:06 PM   #8
White-Hat`
Programmer
 
Join Date: Sep 2005
Location: Oopland
Posts: 36
Rep Power: 0 White-Hat` is on a distinguished road
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.
White-Hat` is offline   Reply With Quote
Old Mar 6th, 2006, 8:55 AM   #9
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Mar 7th, 2006, 1:09 AM   #10
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,208
Rep Power: 5 grumpy is on a distinguished road
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.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:13 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC