New to Programming

S

SG

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?

Secondly, could you please tell me how the knowledge of C will help me
later on? I have a teacher here who just shrugged at this question and
replied that the knowledge of C will help me learn the other advanced
languages later on... Is this true?

Thank You for your help in advance,

Regards,
SG.
 
G

Glenn Hutchings

SG said:
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?

I'd guess there are many reasons, but for me, if I want to program in
an "object-oriented" style, I'll choose a small language that does it
properly (e.g. python), not some big bloated monstrosity with
everything including the kitchen sink thrown in. Or, in
wikipedia-speak: "Many people think that C++ has been extended to the
point of inelegance."
Secondly, could you please tell me how the knowledge of C will help me
later on? I have a teacher here who just shrugged at this question and
replied that the knowledge of C will help me learn the other advanced
languages later on... Is this true?

Yes, to a certain extent. But it will certainly give you insight into
what's going on internally when your program's being run, which many
other languages try to hide from you (with varying degrees of success).

Glenn
 
J

J. J. Farrell

SG said:
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?

A strangely worded paragraph. Do many people prefer C to C++? If they
do, perhaps they find it better suited to what they want to do. I use C
and I don't use C++, but I don't think I "prefer" C to C++; I don't use
a chain saw either, but I don't prefer C to a chain saw.

Are people who prefer C++ to C just conservative about switching over
to C or is there some other reason?
Secondly, could you please tell me how the knowledge of C will help me
later on?

It will likely help you get jobs which require you to know C, for
starters.
I have a teacher here who just shrugged at this question and
replied that the knowledge of C will help me learn the other advanced
languages later on... Is this true?

Very likely; the more languages you know, the easier it's likely to be
to learn others (as long as you can avoid getting them confused).
 
R

Richard Heathfield

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.
 
R

Richard

J. J. Farrell said:
A strangely worded paragraph. Do many people prefer C to C++? If they
do, perhaps they find it better suited to what they want to do. I use C
and I don't use C++, but I don't think I "prefer" C to C++; I don't use
a chain saw either, but I don't prefer C to a chain saw.

Prefer C to a chain saw? What a ridiculous analogy. You cant program
a computer in a fairly low level,optimised, compiled manner with a
chainsaw.

To the op : which every way you want to cut it, C is easier than C++ in
that its generally far simpler to understand. With C++ you can end up
with incredibly complex code with operators overloaded, generic
packages, obscure object library incantations, multiple inheritance etc etc
Are people who prefer C++ to C just conservative about switching over
to C or is there some other reason?

Huh? Most of the switch over happened the other way : most C++
compilers will compile C but no vice versa. It is rare for someone to
move back to C from C++ IMO.
It will likely help you get jobs which require you to know C, for
starters.

Are you trolling? Damn. You are. You must be.
 
H

Hallvard B Furuseth

SG said:
Secondly, could you please tell me how the knowledge of C will help me
later on? I have a teacher here who just shrugged at this question and
replied that the knowledge of C will help me learn the other advanced
languages later on... Is this true?

Partly, but personally I'd say he's got the sequence wrong. It's good
to learn a low-level language so you can see what's going on and so you
won't expect a language to protect you from your mistakes, but learn a
high-level one as well and learn _programming_ from that one.
E.g. Python which was mentioned elsethread. (High-level doesn't mean
harder - quite on the countrary for a good language, because you don't
need to fiddle with details and with bugs you can only make in the
low-level language.)

I learned programming starting at low-level languages (Basic, Pascal,
assembly). So I've had to try to unlearn a lot of bad habits I learned
along the way - because too much of my programming consisted of fiddling
with details instead of getting on with the job, so to speak. In
particular "premature optimization" is a tempting error to make in C.
That is, you spend a lot of time to optimize some part of the program
whose speed might not actually be important at all, and complicate your
program all to hell in the process.
 
C

CBFalconer

SG said:
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?

Secondly, could you please tell me how the knowledge of C will help
me later on? I have a teacher here who just shrugged at this
question and replied that the knowledge of C will help me learn the
other advanced languages later on... Is this true?

One aspect is that C does not hide much in abstractions, as does
C++. Thus programs written in C give you a much better idea of
what is really going on in the machinery. Of course assembly will
do that even better, but is not portable. Without that fundamental
knowledge you cannot have any idea if you are consuming excess
resources, either hardware or time.
 
R

Richard Heathfield

Richard said:
Prefer C to a chain saw? What a ridiculous analogy. You cant program
a computer in a fairly low level,optimised, compiled manner with a
chainsaw.

Wrong. You can program a computer to an extremely low level with a chainsaw.
Not only that, but you can use one to decompile just about anything.


It was a rhetorical question, styled after the OP's question in an attempt
to make an ironic point.
Most of the switch over happened the other way : most C++
compilers will compile C but no vice versa.

Nope. C++ compilers compile C++, and it's trivial to come up with a program
that is legal C but not legal C++. Offer such a program to a C++ compiler
and it is *obliged* to diagnose the program as incorrect.
It is rare for someone to move back to C from C++ IMO.

And yet I managed it. I moved from C to C++, and then moved right back again
after a few months, because I found C++ just too blechy for words. (I
accept that this was before the 1998 standardisation. Things have no doubt
improved now.)
 
S

Spiros Bousbouras

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++?

I know C and I don't know 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?

You seem to think that the natural way to go after C
is C++. I have no reason to think so. I'm learning Common
Lisp and when I'm proficient with it I'll "switch over" to it.
After that and a couple more versions of Lisp my next stop
will be Forth unless some new very exciting language gets
invented in the meantime. I doubt that I'll ever have the time
to learn C++.
 
S

Spiros Bousbouras

Richard said:
Prefer C to a chain saw? What a ridiculous analogy. You cant program
a computer in a fairly low level,optimised, compiled manner with a
chainsaw.

I think it's an apt analogy. The opening poster did
not explain why he thinks that many people prefer
C to C++. I'm guessing that J.J. Farrell guessed that the
OP thinks so because many people use C and do not use
C++. So J.J. was making the point that use A and not use
B does not imply prefer A over B. The chainsaw analogy
illustrates that point just fine.
Huh? Most of the switch over happened the other way : most C++
compilers will compile C but no vice versa. It is rare for someone to
move back to C from C++ IMO.

Perhaps you're right but the point is that the opening poster
asked a loaded question. The way he phrased it sounded
like he thinks that switching from C to C++ is some kind
of default and people need a reason not to follow that
default. By reversing the question J.J. exhibited why the
original question was loaded.
Are you trolling? Damn. You are. You must be.

I'm pretty sure he isn't.
 
J

J. J. Farrell

Richard said:
Prefer C to a chain saw? What a ridiculous analogy.

On the contrary, it's a good analogy. C, C++, and chain saws are all
tools, differently suited to different jobs. I use whichever tool is
most appropriate to the job in hand. I don't "prefer" one tool over the
others. I use a hammer for some jobs and a screwdriver for others, but
I don't prefer one over the other. I use one in preference to the other
for each individual job because of its better suitability to that job,
but the preference changes depending on the job.
You cant program
a computer in a fairly low level,optimised, compiled manner with a
chainsaw.

Obviously not, what a silly idea.
To the op : which every way you want to cut it, C is easier than C++ in
that its generally far simpler to understand. With C++ you can end up
with incredibly complex code with operators overloaded, generic
packages, obscure object library incantations, multiple inheritance etc etc


Huh? Most of the switch over happened the other way :

What "switch over"? You write as if there's some exclusive permanent
choice between C and C++.
most C++ compilers will compile C but no vice versa.

Not true; all C and C++ compilers will compile code written in the
common subset of C and C++.
It is rare for someone to move back to C from C++ IMO.

Again, what's this about "moving back"? Why would anyone "move" between
the two?
Are you trolling? Damn. You are. You must be.

Nope, just puzzled by questions which seems to be based on strange but
unstated assumptions, or to which the answer seems blatantly obvious. I
did wonder if I was being trolled. To me, the most obvious benefit of
learning a language comes when you need to use it. I can't imagine how,
but the OP seemed to have missed that.

The OP's not alone. I once heard a conversation along the lines of
"What's the point of learning French?"
"I think it will be helpful when I visit France"'
"Oh, I hadn't thought of that".
 
A

Ancient_Hacker

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?

Let's say you want to get across town.

Your choices are:

(1) A VW Bug-- 4 cylinders, turn the key, and you're off.

(2) A MIG-25. Say three years of flight training, two hours of
pre-flight planning, paperwork, and inspections.

Now the MIG-25 is a whole lot cooler. Which one do you choose?
 
R

Richard Heathfield

Ancient_Hacker said:

Let's say you want to get across town.

Your choices are:

(1) A VW Bug-- 4 cylinders, turn the key, and you're off.

(2) A MIG-25. Say three years of flight training, two hours of
pre-flight planning, paperwork, and inspections.

Now the MIG-25 is a whole lot cooler. Which one do you choose?

It's got to be the MIG. My business across town isn't all that urgent, and
turning up in a MIG will definitely give me some street cr^W^Wair miles.
 
K

Keith Thompson

Richard Heathfield said:
Ancient_Hacker said:


It's got to be the MIG. My business across town isn't all that urgent, and
turning up in a MIG will definitely give me some street cr^W^Wair miles.

I was thinking I'd take the MiG, sell it, use some of the money to buy
a VW Bug, and drive to the bank with a trunk full of cash.
 
J

Joe Wright

Keith said:
I was thinking I'd take the MiG, sell it, use some of the money to buy
a VW Bug, and drive to the bank with a trunk full of cash.
Dummy, the trunk of the VW has an engine in it. There is not nearly
enough room under the hood to hold that much cash.

Take the MiG, sell it on eBay, money to PayPal, take a cab across town.
 
I

Ian Collins

Richard said:
To the op : which every way you want to cut it, C is easier than C++ in
that its generally far simpler to understand. With C++ you can end up
with incredibly complex code with operators overloaded, generic
packages, obscure object library incantations, multiple inheritance etc etc
Or you can end up with very clear, easy to read code. The choice is yours!
Huh? Most of the switch over happened the other way : most C++
compilers will compile C but no vice versa. It is rare for someone to
move back to C from C++ IMO.
I prefer to oscillate, it keeps me on my toes.
 
J

Jordan Abel

2006-10-26 said:
Richard said:

Nope. C++ compilers compile C++, and it's trivial to come up with
a program that is legal C but not legal C++. Offer such a program to
a C++ compiler and it is *obliged* to diagnose the program as
incorrect.

Perhaps it would have been better to say "many C++ compilers are also
the same program as a C compiler". And I believe C++ does specify binary
compatibility with C via 'extern "C"', which might tend to ease
migration.
 
L

Lowell Gilbert

Ian Collins said:
Or you can end up with very clear, easy to read code. The choice is yours!
I prefer to oscillate, it keeps me on my toes.

Not claws?
Oh, wait, that would be an ocelot.
 
C

Charlton Wilbur

CBFalconer said:
One aspect is that C does not hide much in abstractions, as does
C++. Thus programs written in C give you a much better idea of
what is really going on in the machinery. Of course assembly will
do that even better, but is not portable. Without that fundamental
knowledge you cannot have any idea if you are consuming excess
resources, either hardware or time.

This is also beneficial in that you can build very efficient
abstractions yourself as an exercise, and then look at how other
languages do it. You know what you're hiding because you wrote it.

This is how I learned object-orientation: I started out in C, with
abstract data types, typedef struct foo_struct { ... } foo, foo
*alloc_foo(), void destroy_foo(), etc., and *then* progressed to
languages with explicit support for all those nice OO features.

Now my languages of choice are Perl and Objective-C, but I write a lot
of C when I want things to be portable -- you can embed C in Perl, or
link it with Objective-C or C++....

Charlton
 
A

arnuld

Ian said:
Or you can end up with very clear, easy to read code. The choice is yours!

you are right, i am using them both from last 4 months (in procedural
style only, without creating any classes). C++ programmes are much
shorter & easy to maintain. OTOH, C++ sometimes confuses you very much
whereas C is very simple to learn. i wanted to learn C++ but i had to
learn C for that as there is no book in my country that teaches C++
independently, every book takes route through C & hence today i quit
C++ & dwell into C.

depends on "what people think when they are faced with a problem?".

what problem you are trying to solve? mine was "A JOB in India" i.e.
why C++ but "books" posed the new problem & also i lack on real-life
coding experience, i only know what are variables & fucntions & some
Common Lisp. hence 3 problems at hand, will solve them through C.

what *exactly* the problem you are trying to solve?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top