Jump to content

Why is C not an object oriented programming language?

Recommended Posts

  • Active Members

In order to answer this, you need a definition of Object-oriented programming. A few things that C does not have:

It doesn't have any concept of Inheritance.

While you can embed function pointers in C structs, they aren't proper classes in the OO sense, and such embedded function pointers don't represent Methods.

There is no notion of "private" or "public" members in C structs, which otherwise are the closest thing to "classes" in object oriented languages.

C doesn't have operator or function overloading, which is also a pretty fundamental part of OO methods: Polymorphism.

With sufficient macro cleverness, you can manufacture stuff that kinda sorta does something like the above, and the early C++ "compilers" did something like that, but C as normally used is not an object oriented language.

When Ritchie wrote C, he was not trying to create a language that was well-suited to creating programs that could use objects to describe real-world problem domains. He was trying to create a higher-level language than assembly which could still have very fine-grained control of the system's hardware.

Object-oriented languages are handy for creating applications that involve discrete entities which send messages to one another to get work done. C is good at efficient memory usage (if you know what you are doing) and direct communication with physical hardware, like disk drives and network ports.

You could just as easily ask, "Why wasn't the Ford Mustang a hovercraft?" When the Mustang was first produced, hovercraft technology had already been figured out. The Mustang could have been a hovercraft - but the hovercraft solved problems (travel over variable terrain & amphibious travel) that Ford wasn't trying to address.

C is not an object oriented programming language because software objects are neither desired nor useful in the problem domains where C is used.

If you have a problem where object oriented programming would be useful, then you use a language other than C. For example, C++, Java, C#, Delphi, Scala, Smalltalk, Eiffel, Python and Perl. There are lots of good choices for object oriented programming.

So which problem domains were C created for?

Problems where the resultant program had to be small and compact;

Problems where the resultant program had to be deterministic;

Problems where the programmer (and V&V team) had to be able to predict and understand the machine code that the source code would generate;

Problems where all function calls (subroutines) were explicit;

Problems where stack and heap usage were explicit;

Problems where memory use is very efficient;

Problems where memory use could be anticipated and predicted;

Problems where timing indeterminacy is absolutely minimized;

Problems where timing could be predicted;

Problems where only relevant code is compiled into the program;

Problems where you can only use libraries if they come with source code, (and even then, can only be used if they follow the same specific set of rules used to create the source code).

In short, the sort of problems where you get the fastest response to hardware events, the smallest possible program to service those events, and the greatest amount of predictability. The sorts of things that you need for controlling hardware and interfacing between hardware and other software; which, for example, is what an operating system does.


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...