Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why C++ ???

Status
Not open for further replies.

isaisa

Programmer
May 14, 2002
97
0
0
IN
Hi All,

I am coding in 'C' for last 2 years. I am comfortable in using the procedural approach. People talk about OOAD and C++ to greater extent. I am interested to know how OOAD OR C++ style , infact approach , of coding have upper hand on 'C' style of coding.

This question is out of curiocity. I read some material on C++. Not yet touched Stroustroup book. If anybody knows the links for the same, kindly tell me. I am interested to know about advantages of C++ approach in perspection of ease of coding, ease of problem solving and any additional fetures.

Thanks in advance.

Sanjay
 
Hi Sanjay,

I think that C++ allows you to structure your program better. It allows the data and functions within the same code {class}. In C the data is created in a structure and you may or maynot create a file to contain the related functions. When you are looking at the code in c++ your know the functions(members) act on the data within the class. Know what the data is know what the functions are. You can still create utility classes ie a buch of functions which do stuff.

It also allows you to use virtual functions. This is basically an interface. All the calling code remains the same but you can swap the immplementation of the code. Useful if you are writing for different operating systems.

Also if you are encapsulating properly then you can re-use the code. That or use the code someone else has created. e.g. Create an open file dialog same as all the other windows programs.

This is a pretty simplistic, if you have been writing C for a while, you won't have too many problems with C++, the design side of it is probably the hardest to figure out. Keep reading.


Cheers
MJ




 
If you have been coding C for a long time (I have), it's difficult to start thinking in another way. Quite often I find that I am coding/designing C (in a c++ project), where a proper C++ design could have improved things a lot.

Somehow this can be considered an advantage : You can do C programming in a C++ program - meaning that you don't have to learn a lot before being productive.

This makes it possible to start very slowly coding C++, slowly picking up some of the nice features that the language has.

One of these features is STL (Standard Template Library).
It's container classes alone justifies the use of C++. It really saves you from doing a lot of error-prone code (And doing it over and over again).
When you have done your first C++ program and been using one or more of these classes, I am sure you will agree with me.

When it comes to books : I am not sure I would start with Stroustrup. It's a good book, but I (still) find it hard to read.

If you already have a C++ compiler, you should change the extension of your current projects sourcefiles to .cpp right away !

Have fun !

/JOlesen
 
Using C++ without first understanding Object Oriented Design will be of some small benefit but not much. You can’t begin to tap the power without OOAD skills. Java is probably much better suited to learning concepts of Object Oriented Programming and then later Design.

"But, that's just my opinion... I could be wrong."

-pete
 
There could really be two questions here: Why should I use C++ over C? and Why should I use OOAD over structured design techniques?

1)
C++ offers some nice features not available in (standard) C, such as tail comments ("//"), default function parameters, and references. Exception processing, when used correctly, can simplify the handling of unusual events.

2)
OOAD allows you to organize your program in ways that actually help you understand it better. By letting different types of data possess their own methods for dealing with that data, you can concentrate on the larger picture.

Polymorphism as a part of OOAD is an effective way of dealing with similar types of data with generic operations by allowing each specialization to define how those operations actually work.

It has already been mentioned in this thread that you can code procedural C using C++. It should also be noted that you can write object-oriented programs using procedural languages. (The C++ compiler generates native machine code; you can't get much more procedural than that.) However, languages that support the object-oriented paradigm make that particular task much easier.

I have to agree with palbano that learning object-oriented concepts is probably easier using a language that forces you to organize your programs in that manner. Java is the most accessible (availability and cost-wise), but Eiffel and SmallTalk are also available.

Good luck,
OffByOne

Nine months, two weeks, five days, 11 hours, 29 minutes and 4 seconds. 5264 cigarettes not smoked, saving $855.50. Life saved: 2 weeks, 4 days, 6 hours, 40 minutes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top