[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Why is C so popular?



Frank Gevaerts wrote:

On Wed, Aug 27, 2003 at 01:11:08AM -0500, Alex Malinovich wrote:

The recent COBOL discussion has gotten me to thinking. Some languages
seem to be very popular in some situations. C is easily the dominant
language for most things Linux. So therein lies the question. Why,
exactly, is C so popular? Especially in comparison to C++. I can't think
of a single reason to use C instead of C++ for most of the coding that I
would do. I generally only write user applications. I don't get anywhere
near the kernel which is where I'd imagine most of the reason for using
C comes in. Yet I see people writing 'modern' GUI applications and using
C when I would think C++ would be a much better choice. Is there
something that I'm missing? Something that C actually does better than
C++ in regards to higher-level functions?


First convince me that object oriented programming results in
maintainable and debuggable code,

Object oriented analysis and design produces nothing more than an Object model of the problem space. A good Object model will allow you to find the Classes you will need to create, and the use-cases these Classes should provide. The use-cases will in turn allow you to identify your test-cases. None of this has anything to do with any programming language.

Whether or not the resulting code is maintainable and debuggable depends not only on a good Object model but on how well the chosen programming language allows you to implement the model, and the skill of the programmer. If your model is good, and the language allows you enough flexibility, then the resulting code should be merely a compiler-friendly version of the Object model, and just as maintainable.

then convince me that C++ is a good implementation of OO, and then I might consider C++ instead of C. (I know not all the features of C++ are related to OO, but OO seems to be the main selling point of C++ vs C)

C++ is C with some OO-like features added to it. It is not a pure OO language, but a hybrid, and there is nothing in the language that forces you to use Classes and Objects. It does allow you to do a fair bit of OO implementation, but you will still have to switch between Objects and primitive types from time to time, do the odd type cast, and take care of all the memory management and garbage collection by yourself. Then there is the dreaded pointer arithmetic, which has absolutely nothing to do with OO, but is pure C.

I think that the popularity of C has more to do with "what's out there", when newcomers want to teach themselves programming. There's so much to look at, both good and bad, and it's easy to find examples that you can try out and modify. Hands up, how many people have written new C code by using old C code as a template?

Sure, there are performance reasons for choosing C, but they only really come in to play in those few applications that have real-time constraints. I would say it's better to learn good OO analysis and design, choose your favourite language for normal use, then make exceptions from this language if and when you need the extra performance.

(Note that I tend to gravitate towards higher level languages by nature.
I use Perl religiously, and I love Java. If not for some of the speed
limitations and, more importantly, the fact that it's non-free, I would
say that Java is the perfect language. Hmm... is that gasoline I smell?
:)


Have you ever looked at an operator precedence table for Java ? One line
says : "+, -, +" (the last + is for string concatenation). Add to this
the principle of strong typing and giving compilation erros whenever you
omit an explicit cast, except of course if the first variable might be a
string and strings are so cool so we convert everything else to a
string... Whoever thought that was a good idea should be shot.
Java makes strings expensive and easy to use at the same time, and that
is not a good idea. And it is OO ;-)

LOL :-) Java isn't pure OO either - there are plenty of things in Java that aren't Objects. Sure it's much better at doing OO than either C or C++, but you still have to make compromises. Also, it's non-free, as Alex pointed out (not that this affects the suitability of Java per se), which means that it will probably not spread so fast in the Linux world. I think we're stuck with C and C++, so why not try to use them as well as possible, and choose the one you really need depending on what you want to do...

--
Cheers,

  .~.
  /V\
 // \\
/(   )\
 ^`~´^
< hugge >

"I'll give up Smalltalk when they pry the browser from my cold, dead fingers!"



Reply to: