C as first language?

Discussion in 'C Programming' started by toxemicsquire4@gmail.com, May 21, 2014.

  1. Malcolm has made the preposterous claim that "if you're thinking of an
    algorithm you'll think of it in C terms".

    The question of whether some "language" is needed (however abstract and
    ill-specified) simply to *think* about algorithms, is one I am not
    remotely qualified address. I could report what I feel is happening in
    my head when I do such a thing, but will that help to arrive at a true
    picture of the phenomenon? I doubt it.

    Expressing an algorithm needs a notation, but that's as far as I'd be
    prepared to go.
     
    Ben Bacarisse, May 22, 2014
    #41
    1. Advertisements

  2. Stefan Ram Guest

    It depends on the definitions used. ISO/IEC 2382-1:1993
    »Information technology -- Vocabulary -- Part 1: Fundamental
    terms«, which is a normative reference of n1570, says:

    »01.05.05
    algorithm
    A finite ordered set of well-defined
    rules for the solution of a problem.«

    If this is a /set/, then by the mathematical definition of
    »set«, all its elements must be clearly specified. Without
    any language, it should be difficult to specify rules.
     
    Stefan Ram, May 22, 2014
    #42
    1. Advertisements

  3. G G Guest

    learn assembler first. ;-)
    after that, C will be the greatest lang. you will come to know.

    just kidding about assembler first.
    C is ok for a first lang. Pascal would be better. i don't think Pascal has a lot of followers these days.

    but, pascal was cool. loved that lang. the elders remember it, but they may have real problems with it. but, i loved it. ada is similar but it's too, something... didn't like it at all.
     
    G G, May 22, 2014
    #43
  4. James Harris Guest

    I have to say that I think that it is a terrible idea for a beginner to
    learn C++ first. (Sorry!) C++ has its good points but, like many languages
    which start off well, has become too large and cumbersome. It is mentally
    manageable if a programmer sticks to a subset of C++ - and I presume that's
    what you had in mind - but the trouble is that one has to interact with the
    ninjas who want to use the more esoteric features. C++ was already bulky in
    its early days, compared to C. It has since become worse. Thus there is a
    lot of it to learn if one wants to work with others.

    Programming language designers, ISTM, get hooked on adding features. Perhaps
    because they are so familiar with their own languages they see them as
    easily understandable. So enhancements don't seem to add much complexity.
    And there is always the temptation to add a useful new feature - like being
    on a diet but gazing at tempting items of food! So the language gets bigger
    and increases the knowledge a programmer needs not for his own code but in
    order to interact with other programmers who might use those features.

    By contrast, C has been kept admirably small even after decades. That is
    remarkable in itself but it also, IMO, makes C a better language for a new
    programmer to learn properly.

    James
     
    James Harris, May 22, 2014
    #44
  5. Ian Collins Guest

    The more complexity that goes into the language (and its library), the
    less ends up in user code! C++ resource management is a classic example.
    The C++ committee listens to the user community and adds features that
    users want and in many case have been using through libraries such as
    boost. Now if C only had a sandpit like boost to develop new ideas...
    Maybe, there's certainly less to learn, but is there less to learn
    before a newcomer can produce robust code? A good example is the input
    thread that's been running and running. It simply wouldn't happen on a
    C++ list because the language has the necessary support for arbitrarily
    long lines.
     
    Ian Collins, May 22, 2014
    #45
  6. BartC Guest

    (I agree. Probably not as a second or third language either, only if it's
    unavoidable.)
    You're talking about C++ pretending it is a higher level language than C.

    Certainly it can do many things which are already built-in, but the
    cumbersome mechanics of how they are implemented aren't very well hidden and
    the resulting code tends to be ugly (enough to put people off).

    If a beginner wants a higher level language to experiment with, then there
    are easier ones: Python has been mentioned to complement C. For example,
    someone mentioned a GCD algorithm, here is a version in Python:

    def gcd(a,b):
    while b!=0:
    t=b
    b=a % b
    a=t
    return a

    print (gcd(31415926534676736647,438478473847834834784748))

    It just works.

    But also, with a language like C++ with so many things built-in, there is
    less opportunity to learn how to implement them, because they're already
    there! (And with over-the-top implementations too.)

    (The language is also extremely complex; most people seem to agree about
    that. I've been programming for decades, and I could never get my head
    around it. It's not enough to say you only need to use a subset; you're
    always aware of the complexity behind the scenes. It's not a beginner's
    language.)
     
    BartC, May 22, 2014
    #46
  7. Borax Man Guest

    I learned assembler first, and C made a LOT more sense because of it.
    Pointers and pointer arithmetic, referencing and dereferencing instantly
    made sense. Many other aspects of C were "familiar".
     
    Borax Man, May 22, 2014
    #47
  8. (snip)
    Well, there is what Brooks, in "Mythical Man Month" calls "The Second
    System Effect". That was intended to apply to OS designers, but
    could also apply in this case.
    -- glen
     
    glen herrmannsfeldt, May 22, 2014
    #48
  9. Ian Collins Guest

    I think you just proved my point that the more complexity that goes into
    the language (and its library), the less ends up in user code!
     
    Ian Collins, May 22, 2014
    #49
  10. Jorgen Grahn Guest

    Same experience here. Python is by far the most common tool for such
    things. Free, flexible and perceived as newbie-friendly.
    IME it's uncommon to find a Linux system where Python isn't installed.
    Many (all?) distributions use it for infrastructure things, when shell
    scripts aren't enough.

    ....
    I planned to skunk that in, but sadly missed my window of opportunity.

    /Jorgen
     
    Jorgen Grahn, May 22, 2014
    #50
  11. Jorgen Grahn Guest

    Ok, but please note that that was not what I suggested!

    /Jorgen
     
    Jorgen Grahn, May 22, 2014
    #51
  12. jacob navia Guest

    Le 21/05/2014 23:07, Jorgen Grahn a écrit :
    I would say that this is not a coincidence.

    C is much more popular than C++
     
    jacob navia, May 22, 2014
    #52
  13. Jorgen Grahn Guest

    .
    I won't do C++ advocacy here, except I'll note that I don't find it
    particularly complex (and I'm not particularly smart). Working with
    it is like working in C, except you don't have to invent linked lists
    over and over again.
    To me that translates to one of:
    - I never seriously tried.
    - I got burned in the OOP craze in the early 1990s, when it
    was more important that your code could be reused in the
    Space Shuttle than that it solved your immediate problem.

    I can emphatize with the latter ... one drawback that C++ has and C
    hasn't is that it -- sometimes -- attracts people who aren't
    interested into Getting Things Done.

    /Jorgen
     
    Jorgen Grahn, May 22, 2014
    #53
  14. BartC Guest

    So why hasn't C disappeared then, as everyone rushes to use C++ which is so
    much better?

    (BTW you only have to invent linked lists once. You might have to implement
    them more than once, but since my data structures were linked to each other
    in up to seven different ways, a simple generic off-the-shelf linked-list
    type in a library wouldn't have worked.)
    I've tried to get into it every so often, to discover the mysteries of OOP
    and templates and generics and polymorphism and so on. But when I looked at
    examples, it was stuff I'd already been doing for years anyway in some
    dynamic language or other, without even knowing I was doing it! And with a
    lot less effort. C++ might just do some things a bit faster.

    (In my case I use two levels of language: a higher level (than C++) dynamic
    language to do most of my work, and a lower-level one (C or like C) to
    implement the other; this one doesn't need to be fancy. I don't need a
    generic, flex array type, because that's in the other language.)
     
    BartC, May 22, 2014
    #54
  15. James Harris Guest

    I suppose it wasn't! The OP who asked for suggestions did say he was a
    beginner. I assumed you were answering in that context but I see that could
    have been an incorrect assumption.

    James
     
    James Harris, May 23, 2014
    #55
  16. I'd been programming on and off for about ten years when I got my first C
    compiler. So for me "that funny asterisk isn't a unary multiply, it's the
    indirection operator" more or less sorted pointers. To someone who is new
    to programming, however, they are often highly confusing.
     
    Malcolm McLean, May 23, 2014
    #56
  17. Jorgen Grahn Guest

    Sorry, that's probably also a misreading. The advice I was playing
    with was "learn and use C++ and skip C" rather than "learn C++ with
    the final goal to learn and use C".

    I don't believe in making detours via another language -- except very
    brief ones which can show you what's unique to/missing from the
    language you're learning. People seem to find it hard to separate at
    least the statically typed languages, and you see them write C++ as if
    it was Java, C++ as if it was C and C as if it was C++.

    /Jorgen
     
    Jorgen Grahn, May 24, 2014
    #57
  18. Jorgen Grahn Guest

    A good question, and I often ask myself that.

    C works, that's one reason. It's known not to be a toy language!

    Another may be a certain conservatism in the ecosystem where C is
    strong (Unix, embedded -- the areas where I myself work). In the
    Microsoft or Java worlds people seem prepared to switch everything and
    relearn once a year. I think it takes years to be optimally
    productive in a programming environment, so I assume those people are
    always working /below/ their optimal level.

    A third is I think organizations got burned in the 1990s when they
    tried to switch from C to a not fully mature C++, and at the same time
    focus heavily on OOA/OOD/OOP and navel-gazing in general. I know
    examples of companies which had disaster projects back then, and then
    blamed and more or less banned C++ until now.

    Fourth: there are many more ways to do things in C++, and it's hard to
    get people to agree on one. I sometimes think this is the best
    argument for C -- although there are surprisingly many incompatible
    ways to treat C too!
    I never could get my head around OOP and polymorphism either -- write
    your code as a deep class hierarchy and I'm immediately lost. I
    suspect it's a personality thing, because experienced programmers tell
    me it's the way to go, at least for some kinds of problems.

    Fortunately you don't have to do it: you can design all your classes
    without any inheritance. The C++ standard library itself rarly uses it.

    The big benefits of C++ lie elsewhere, and would IMO feel more natural
    to someone coming from C.
    In recent years I've begun to rewrite much of my Python code into C++.
    Not because of speed usually -- I noticed the lack of static type
    checking made my code hard to maintain ... I like Python, but the
    "rigidness" of C and C++ suits me better in the long run.
    That's not the scenario I was thinking of ... True, if you're program
    is e.g. Python with some "leaf" parts in C, you have little use for C++.

    /Jorgen
     
    Jorgen Grahn, May 24, 2014
    #58
  19. J. Clarke Guest

    There's an old saying, "You can write FORTRAN in any language". If your
    goal is to learn X then learn X, not Y that is somewhat similar to X.
    If your goal is to learn to program and not to learn a specific
    language, then your options are broader.
     
    J. Clarke, May 24, 2014
    #59
  20. (snip)
    And my Java code probably looks more like C than most Java
    programmers would expect. For one, I now use

    System.out.format()

    for most of my output. A relatively new addition to Java
    that works much like C's printf. One difference, though, is
    that you use %n instead of \n to generate a newline.
    I believe it generates \r\n on Windows machines.
    -- glen
     
    glen herrmannsfeldt, May 24, 2014
    #60
    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.