New to Programming

Discussion in 'C Programming' started by SG, Oct 26, 2006.

  1. SG

    SG Guest

    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,

    SG, Oct 26, 2006
    1. Advertisements

  2. 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."
    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 Hutchings, Oct 26, 2006
    1. Advertisements

  3. 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?
    It will likely help you get jobs which require you to know C, for
    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).
    J. J. Farrell, Oct 26, 2006
  4. SG said:
    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.

    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.
    Richard Heathfield, Oct 26, 2006
  5. SG

    Richard Guest

    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

    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 : most C++
    compilers will compile C but no vice versa. It is rare for someone to
    move back to C from C++ IMO.
    Are you trolling? Damn. You are. You must be.
    Richard, Oct 26, 2006
  6. 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.
    Hallvard B Furuseth, Oct 26, 2006
  7. SG

    CBFalconer Guest

    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.
    CBFalconer, Oct 26, 2006
  8. Richard said:
    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.
    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.
    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.)
    Richard Heathfield, Oct 26, 2006
  9. I know C and I don't know C++.
    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++.
    Spiros Bousbouras, Oct 26, 2006
  10. 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.
    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.
    I'm pretty sure he isn't.
    Spiros Bousbouras, Oct 26, 2006
  11. 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.
    Obviously not, what a silly idea.
    What "switch over"? You write as if there's some exclusive permanent
    choice between C and C++.
    Not true; all C and C++ compilers will compile code written in the
    common subset of C and C++.
    Again, what's this about "moving back"? Why would anyone "move" between
    the two?
    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".
    J. J. Farrell, Oct 26, 2006
  12. 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?
    Ancient_Hacker, Oct 26, 2006
  13. 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.
    Richard Heathfield, Oct 26, 2006
  14. 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.
    Keith Thompson, Oct 27, 2006
  15. SG

    Joe Wright Guest

    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.
    Joe Wright, Oct 27, 2006
  16. SG

    Ian Collins Guest

    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.
    Ian Collins, Oct 27, 2006
  17. SG

    Jordan Abel Guest

    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
    Jordan Abel, Oct 27, 2006
  18. Not claws?
    Oh, wait, that would be an ocelot.
    Lowell Gilbert, Oct 27, 2006
  19. 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 Wilbur, Oct 28, 2006
  20. SG

    arnuld Guest

    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?
    arnuld, Oct 28, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.