Re: OT: Why is C so popular?
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?
(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?
:)
This has been one of the funniest threads I've read in months. Thanks :)
I don't have any theory, history or humor (unfortunatly) to add to this
discussion, so I'll just add my experiance and reasons.
I know C fairly well. I haven't written my own operating system or
anything but I can accomplish the tasks I set out to do with it. I know
C++ and have about the same level of skill. Why do I ever use C over C++
since I'm not writing kernels or drivers or anything?
Lots and lots of documentation, code examples and libraries are in C. I
wonder how less works. Hmm. C code. How about a gtk? C examples have
been around longer. What about the source code for that MUD I use to
play? C. dpkg? C. Hmm. Well how are chgrp, chmod, cp, mkdir, mkfifo,
rmdir, and touch coded? ____ (yes, C).
Ok, well I've been told how cool I'll be if I program OO, and I'm going
to be a purist for my little CLI program. I start hacking away and boom
first puzzle. Isn't there a class for getopt? I can read all about
getopt(3) in man, but Google isn't lighting my path for CGetOpt.cpp. So
I either roll my own class around getopt(3), put the C code into a non
class function (or just in main) or re-invent that wheel. (There's
probably a better solution out there, the point is I couldn't find it.)
The program grows, and I've got someone interested in helping me. OO ==
cOOl remember? Only they like to indent one way and I like to indent
another. No problem! That's what indent(1) is for? What's this garbage.
It hates my class definition and does wierd things to my object
formatting. Oh, it's for C. (I know, there are other programs for C++,
but the point is indent was installed with gcc, they weren't installed
with g++.) Well, we'll just use the same IDE like Anjuta. That will keep
us straight. Oh no, problems again. It still fights us on how we like to
indent our class definitions. I'm still lookig for CGetOpt.cpp and now
I'm also looking for CSignal.cpp, CSocket.cpp and CErrNo.cpp. I would
_hate_ to think that 'icky' globals are floating around just because I
wanted to get the error from some C call that didn't return a success value.
I do use C++ a lot when coding for windows using VisualStudio and as
much as I loath the MFC documentation for lacking in details, I am
comparing that lack to my C API documentation in man, not to C++ on
Linux. I suppose that isn't fair and if I were to purchase some C++
library for use on Linux it may be very well coded. I just expect it to
be 'free as in C'. I have only dabbled in GUI programming in Linux.
Maybe if I did more I would learn more is out there.
In summary on why I sometimes use C over C++ on Linux, it's because the
documentation, tools and examples are there for C. I'm fine with C++
classes using printf() and select(), but some people I collaborate with
aren't OK with it. I am very aware of the STL documentation on sgi.com.
I use it _very_ frequently, but STL doesn't cover every aspect of
programming to enable me to avoid C calls. It's no (sorry) MFC. I think
if there was a C++ version of CPAN, a collection of 'free as in C' (I
liked that one) documentation and classes, it would really be helpfull
to me, and possibly others, for using C++ more. I thought the Dinkumware
site was annoying. It was more 'free as in Windows Media Player' or
'free as in Yahoo Groups'...
Now, onto other languages.
Perl! :)
I know it's weird, but it does make it easier to write poetry in perl. :-)
--Larry Wall in <7865@jpl-devvax.JPL.NASA.GOV>
man sed; let $there 'be'; perl -e 'and: $life = "great";'
Neil Archibald
- /dev/IT -
#!/usr/bin/perl
package I;
sub m {print "I'm $_[0]\n";}
sub AUTOLOAD {print "$AUTOLOAD $_[0]\n";}
1;
package He;
sub s {print "He's $_[0]\n";}
sub AUTOLOAD {print "$AUTOLOAD $_[0]\n";}
1;
package main;
sub AUTOLOAD {our $AUTOLOAD=~s/main:://;print "and $AUTOLOAD $_[0]\n";
+}
sub Wednesday {print "On Wednesdays ";}
I'm("a lumberjack") && I'm("OK");
I::sleep("all night") && I::work("all day");
I::chop("down trees"),I::eat("my lunch");
I::go("to the lavatory");
if (Wednesday()) {I::go("shopping") && have("buttered scones for tea")
+;}
He's("a lumberjack") && He's("OK");
He::sleeps("all night") && He::works("all day");
He::chops("down trees"),He::eats("his lunch");
He::goes("to the lavatory");
if (Wednesday()) {He::goes("shopping") && has("buttered scones for tea
+");}
...etc.
Cheers, Ben
Come on! If that's not fun, what is??? Oh, and I love this quote by L. Wall:
Perl is ugly because people wanted it that way.
Why do I use perl? Again because it's so prolific. There are tons of
examples, a few good books, and CPAN. I can't even begin to count the
number of times I've thought 'I wonder if someone's already coded this,'
and found it on CPAN.
Why don't I write in other languages even though others say it's vastly
better and are willing to start holy wars on the matter?
There are a few reasons.
I may not have tried them out long enough to form an opinion (python,
ruby, scheme/lisp).
I did try them (took classes even) and was glad when the experiance was
over (COBOL, pascal, BASIC).
I have used them but when I think of a problem they infrequently come to
mind as the solution (Java).
Maybe I suffer from the hammer syndrome; "When all you have is a hammer,
everything looks like a nail." I try to broaden my program language
horizons, but it can often be a frustration. Ever typed $i in C and
forgot to decorate your variable in Perl? My outlook (and collection of
languages) might be different if I had started programming today instead
of 16 years ago. I know I don't suffer from the 'sheep syndrome.' I
don't write in C because everyone else does, I write in C because
someone else left instructions on how to write in C, and being able to
get help and code something (C) for me is better than not finding the
answer and writing nothing (C++).
I am glad that for people who hate C, but love Pascal, there is Pascal
(and any other combination that fits you.) Some days I have thought of
how /usr has grown over the years by adding C++ (and oo libraries like
ACE) then Perl then Python then Ruby etc. and how that at times seems to
be a 'waste of space' (mutter, if only they'd all use C and Perl I
wouldn't have to download all these packages...) :P, but thinking of the
choices it gives everyone and the extra software that might get written
because some group's 'cup of tea' language is there it doesn't seem like
a waste at all.
Jacob
Reply to: