Sams Teach Yourself C in 21 Days

(singke) #1

Procedural and Object-Oriented Languages ......................................................


C is generally considered to be a procedural language. This was discussed on Day 1,
“Getting Started with C.” A procedural language is one that starts at the beginning and
executes each line, one after another. Program flow might switch to other parts of the
code listing; however, this switch is based on redirection from the previous line of code.
In a procedural language, program design is based on the use of procedures or functions.
Over the past couple of decades, several object-oriented languages have been developed;
the most commonly used ones are C++ and Java. As the name implies, an object-oriented
language makes use of objects. You’ll learn more about objects throughout today’s les-
son; but, defined briefly, an object is an independent and reusable section of software
code that can perform a specific task and store specified data related to that task. Object-
oriented languages can also use procedures, but they have additional features for defining
and using objects.
Why were object-oriented languages developed? The main reason is the increasing com-
plexity of programs. Despite the power of procedural languages such as C, they were not
well suited for creation and maintenance of large complex applications. A large program,
such as a word processor or spreadsheet, was difficult to maintain, modify, and debug
when it was written in a procedural language. Object-oriented languages were developed
mainly as a solution to this problem.
Although C can be used to create object-oriented programs, the object-oriented features
that make this possible are not built into the language. This makes C difficult to use in
this manner. Languages such as C++ and Java have been created specifically to make
object-oriented programming easier. Before you look at some details of C++, Java, and
C#, you need to understand what makes a language object oriented.

630 Bonus Day 1

Object-oriented programming is often simply referred to as OOP. The OOP
Note acronym is now very common.

Although C++ is an object-oriented language, it can be used to write proce-
Note dure code—although this is not recommended!

36 448201x-Bonus1 8/13/02 11:18 AM Page 630

Free download pdf