SG said:
Hi everyone,
I am a complete novice at computers and programming and right now, all
i need to know is that why do many people prefer C to C++? Is it just
because they are used to using C and are conservative about switching
over to C++ or is there some other reason?
The usual reasons people tout in answer to this question are: speed,
portability, and closeness to the machine. Whilst those are important
factors, the difference between C and C++ isn't actually very significant
in those terms. C is undoubtedly a smaller and simpler language, though,
and for some that is rather important.
But I think the most compelling reason is a general point to do with
language, and it has the advantage of explaining why many people prefer C++
to C, or indeed language <foo> to language <bar>.
Language both reflects and shapes the way we think. Those who think about
programming in a particular way will tend to prefer languages that
facilitate the conversion of that kind of thinking into source code. The
opposite side of that coin is also relevant - those who have favoured a
particular language for a fair amount of time will find that their approach
to programming has been shaped by that language. That doesn't mean they
can't use other languages, but it does mean that they will tend to reach
*first* for the language that - for *them* - sits easily with the way they
think about constructing programs.
My principal language for a good seven years or so was BASIC (ouch, right?).
When I first started learning C, I was constantly comparing it
(unfavourably) to BASIC. But then, on one particular day, I learned about
structs (which I had been trying to invent by myself in BASIC for quite a
while) and the file-handling functions. I had been dreading learning about
file-handling, since I knew what a pig it is in BASIC - but in C, WOW, this
was easy! And from that point on, C started to shape up in my mind as a
decent language after all.
In 1990, I came across a language/expert-system combination called Guru. It
was like a cross between BASIC, C, and SQL (if you ignored the complicated
bits), and although I'd never come across SQL before, I found Guru very
easy to learn and use. Within a month or so of beginning it, I was winning
technical arguments against old hands - the language sat well with me, and
I ended up writing some very elegant and powerful programs in it. In fact,
I miss Guru. It's like an old friend that I hope (but do not expect, alas)
to meet again some day. The reason I mention it is that it shares certain
similarities with C++ - that is, it's as if someone had taken C and added
huge chunks to it - database access, built-in spreadsheet, expert system,
graphics, all kind of stuff - and messed with the syntax until it was
almost unrecognisable - and yet the way they'd done it still matched the
way I think about programming.
I started learning C++ (on and off) in about 1991, and it baffled me. I've
largely got over that now, of course, and certainly I find the STL to be
rather attractive, but I look at some people's C++ programs and they just
look completely alien to me. I have to *work* at understanding such
programs, because they seem positively to rejoice in using a particular
kind of rather weird syntax. Guru used weird syntax too, but it was *my
kind* of weird syntax, so I didn't mind. But C++ as written by a C++ wizard
doesn't just look weird - it looks *bizarre*!
And yet a C++ wizard will look askance at me for such a reaction, because he
or she will consider such syntax to be perfectly normal. C++ wizards'
thought processes have been shaped by C++ to some extent, and I would also
argue that their initial affinity with it stemmed in many cases from the
fact that it reflected the way they already thought about programming.
So - it's horses for courses. Or lanes for brains, if you prefer.
Secondly, could you please tell me how the knowledge of C will help me
later on?
Even assuming that you don't want to be "a C programmer" (in the sense of
making it your language of choice, getting paid for writing in C, etc etc),
there are several reasons why knowing it will be beneficial to you:
Firstly, C will give you insight into the work other languages have to do
"under the hood", because there ain't much hood where C is concerned.
Secondly, many important books on general programming use C for their
example code. The classic example is the "Dragon Book", which teaches you
how to write compilers, but there are many others too. And the W Richard
Stevens books on Unix form, all by themselves, a whole series of compelling
reasons to learn C. Being able to read the language is therefore invaluable
in general terms.
Thirdly, almost all platforms (I know of no serious exceptions) have a C
compiler available for them, and for some it's the only realistic choice.
If you want to write code for a platform that only supports C, then you
either write in C or write your own translator for that platform - in C!
HTH. HAND.