on September 20, 2009 by Wolf in Programming, Comments (0)
Why do you use C instead of C++?
Or just as reasonably, Why use C++ when C is perfectly good??
C is the older of the two and is a “functional” language. “Functional” is not here the opposite of “dysfunctional*” which means that something has abnormal functionality; nor is it the opposite of “non-functional”, which means the object is not in a useable state. In programming, Functional is set opposite to “Object-oriented.” Another way to characterize C is to say it is “procedural” in nature. This means that the entire program is set up around a series of procedures wnich can also be called modules, or functions.
A C program could be built around a single procedure (the main() function) or there could be several functions that are called at various places through the program. If you built a word processor application, you would expect your users to call the saveFile() function at least once per session, as it is how they would cause the program to write the file to a location onthe hard drive. You would only have to define the saveFile() function once, and the users could call it as many times as they want.
C++ is almost the same as C, but it uses the Object-Oriented Programming paradigm. OOP programmers design Object classes which are a sort of meta-object having the characteristics and methods accessible to an object of the sort defined. This is a little like an ideal in Platonic philosophy. The ideal table consists of a flat horizontal plane or surface with a slope approaching zero, and some sort of mechanism for holding the top surface some distance from the floor.
The parameters any table has are:
Height from floor
- Width
- Length
- Weight limit
- Materials
Now we can call any instance of our ideal table and define the size (Height, Length, Width), strength of construction and materials. Object-oriented programming might require a class to be constructed of which we would make instances within the program, or me might reuse existing classes in our program. Well-understood classes can make your program source code easier to read and understand, and that may make maintenance and enhancement of the application simpler as well.
Functional languages may make faster-running code, since you are not as likely to reuse very complicated multi-purpose functions or procedures, but you may use unneccesarilly complete classes (since you have them on hand) in your OOP applications.
Anything you can build in C can also be implemented in C++. C++ helps you to standardize the way code is created and managed (in classes rather than the more open to view C functions). C++ reduces, slightly, the numbers of ways a programmer might have contacts and internal methods of functions, since class methods and components are set at a higher level than procedural functions. C programmers have more choice when it comes to the implementation of design. C++ applications may be simpler to read and maintain, while C applications may run a little faster.
Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkListTags: C/C++, programming
No Comments
Leave a comment