Shop OBEX P1 Docs P2 Docs Learn Events
C is quirky, flawed, and a huge success — Parallax Forums

C is quirky, flawed, and a huge success

LoopyBytelooseLoopyByteloose Posts: 12,537
edited 2014-06-22 06:31 in General Discussion
Dennis Richie said that, not me.

These days I am enjoying reading, Expert C Programming.

Free PDF link removed as it appears to be a copyright violation.
Buy the book or ebook
http://www.amazon.com/Expert-Programming-Peter-van-Linden/dp/0131774298

And sadly, it seems the same issue applies for Kernighan and Richie's The C Progamming Language:2ed which I have previously provided links to.

If you choose to seek out and download PDF versions, do so at your own risk.


======================

Expert C Programming seems to soothe some of the frustration I have had with learning C late in life. It may help younger programmers that were not aware of the history of C, or why Dennis Richie might say such a thing.

http://en.wikiquote.org/wiki/Dennis_Ritchie

BTW, there was a time when programmers were a fun-loving irrevernt lot. Read the book to find out more about that side of the whoe industry.
«13456

Comments

  • EntomyEntomy Posts: 8
    edited 2014-06-08 09:29
    I think calling C an abstract assembler is rather fitting. A lot of the quirks about C disappear when I think of it that way, as apposed to a higher level language like Ada (I work with machine automation, which Ada happens to be really good for; people tend to judge it like a desktop programming language).

    That looks like a good read so far. I thank you for sharing that.
  • bill190bill190 Posts: 769
    edited 2014-06-08 09:39
    For fun, there is the "Obfuscated C Code Contest"...
    http://www.ioccc.org/

    For example, the following is an entire C program...

    main(a,b)char**b;{int c=1,d=c,e=a-d;for(;e;e--)_(e)<_(c)?c=e:_(e)>_(d)?d=e:7;
    while(++e<a)printf("\xe2\x96%c",129+(**b=8*(_(e)-_(c))/(_(d)-_(c))));}
  • David BetzDavid Betz Posts: 14,516
    edited 2014-06-08 12:21
    Dennis Richie said that, not me.
    DId he say what he thought the quirks were in C? I suspect they aren't what people here complain about like the use of braces to delimit blocks.
  • 4x5n4x5n Posts: 745
    edited 2014-06-08 15:03
    David Betz wrote: »
    DId he say what he thought the quirks were in C? I suspect they aren't what people here complain about like the use of braces to delimit blocks.

    I don't know if he included the flaws in C when he made that statement but I do know that he thought that in at least a few cases the precedence of various operators were "wrong". I snuck into a lecture he gave while I was at Lucent 1999-2000 and he talked about some other design flaws in the language but I have no memory of what they were.
  • 4x5n4x5n Posts: 745
    edited 2014-06-08 15:06
    Entomy wrote: »
    I think calling C an abstract assembler is rather fitting. A lot of the quirks about C disappear when I think of it that way, as apposed to a higher level language like Ada (I work with machine automation, which Ada happens to be really good for; people tend to judge it like a desktop programming language).

    That looks like a good read so far. I thank you for sharing that.

    The instructor I had for my first C programming class had at one point worked at Bell Labs as a software developer. She made a habit of reminding us that C wasn't a high level language but rather that it was a high level assembler!
  • David BetzDavid Betz Posts: 14,516
    edited 2014-06-08 19:47
    4x5n wrote: »
    I don't know if he included the flaws in C when he made that statement but I do know that he thought that in at least a few cases the precedence of various operators were "wrong". I snuck into a lecture he gave while I was at Lucent 1999-2000 and he talked about some other design flaws in the language but I have no memory of what they were.
    Yes, I agree about operator precedence. I tend to add parens when I'm not sure. I think the problems mostly have to do with the bitwise boolean operators.
  • rod1963rod1963 Posts: 752
    edited 2014-06-08 21:04
    Never cared for it, since a lot coders went out of their way to write cryptic code that made assembler look good. But if coders try to keep the code readable it's not half bad.

    But it doesn't mean you can't extend it so to speak like the way Banzai and the Arduino folks did and make it useful for hobbyists and artists to use all sorts of different microcontrollers all over the world, which is very cool.

    I also like C#, nice language.
  • msrobotsmsrobots Posts: 3,709
    edited 2014-06-08 21:49
    David Betz wrote: »
    Yes, I agree about operator precedence. I tend to add parens when I'm not sure. I think the problems mostly have to do with the bitwise boolean operators.

    Exactly!

    C or not, adding parens makes things clear. And a compiler/optimizer will hopefully throw out unneeded ones anyways, so the resulting code may be the same. Just the code is more defined.

    Basically a binary AND is a * and a binary OR is a +. Over all the languages I used I never found the RIGHT answer of how the precedence is supposed to be. MOST of it is clear. But I tend to put parens around everything I am unsure, like David does. Actually it does not really hurt. Some keystrokes more. And all is clear for the compiler and any human reader of the code..

    C quirky and flawed?

    Every language I programmed in my live was somehow quirky and flawed. Even COBOL, my favorite.

    Up to now there is no perfect language. All of them are domain specific. And they should. It is good.

    Enjoy!

    Mike
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-06-08 22:35
    msrobots wrote:
    Over all the languages I used I never found the RIGHT answer of how the precedence is supposed to be.
    The right answer is not hard to discern. Just take thousands of programs, and parse their expressions according to the precedence rules in effect. Then reformulate them against other candidate precedence rules. The candidate that results in the least number of required parentheses for the same semantics wins. Simple.

    -Phil
  • jazzedjazzed Posts: 11,803
    edited 2014-06-08 22:49
    The right answer is not hard to discern. Just take thousands of programs, and parse their expressions according to the precedence rules in effect. Then reformulate them against other candidate precedence rules. The candidate that results in the least number of required parentheses for the same semantics wins. Simple.

    -Phil


    Line by line clarity and maintainability wins unless some obscure optimization is required for performance.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-06-08 23:22
    jazzed wrote:
    Line by line clarity and maintainability wins unless some obscure optimization is required for performance.
    True, but I suspect that your metric and mine will produce almost exactly the same precedence rules. (Mine is easier to quantify, though. :) )

    -Phil
  • jazzedjazzed Posts: 11,803
    edited 2014-06-08 23:48
    Could be Phil.

    I generally keep obscure little operators out of my dictionary though ;-)
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-09 03:16
    Programmers and cats, neither takes very well to hearding.

    Right now I am working up a comparision of the Serial and Stream libraries between ANSI C, Arduinio what's it, and Propeller GCC. (... and maybe, Catalina C too.)

    Why?
    Well Propeller GCC claims to conform to ANSI C.
    And the Propelleruino library is suppose to bridge the gap between whatever the Arduino does to serial i/o and Propeller GCC.

    I won't make any judgements here other that to say there seems to be some divergence. If is frustrating when pundits simply say all the answers are in Learn or any old C tutorial will get you started with the Propeller.

    Of course, Kernighan and Richie just side-stepped the issue by mentioning that all the i/o is in the libraries which are not actually part of ANSI C.
  • ksltdksltd Posts: 163
    edited 2014-06-09 10:43
    Success is not measured by popularity. They are different. By any measure, C is quirky, flawed and a huge failure.

    I do not believe there's much controversy in evaluating language design. The goal of an abstract computer language is to capture the semantics of operation in a concise, precise and maintainable fashion. It is the role of development tools to translate abstract programming source into suitable distributable, maintainable executable form and to support debugging of those executables.

    C accomplishes none of those goals. It is not a concise source code representation. Its semantics are imprecise and simplistic, although I'd suggest they are really somewhere between crude and vulgar. The entire motivation behind C syntax and semantics would appear to be the reduction of the number of characters in the source file (at the great expense of maintainability and precision) and the simplification of creating a compiler. In short, C is a compiler writer's dream and a software engineer's nightmare. The sad state of the software industry is a testament to that.

    That anyone would claim it were a success is beyond me. Shame on Richie and Kernighan and Bell Labs for the travesty that is their legacy.

    What's most disparaging is that the science of programming was already well advanced by 1978 when their publication hit the streets as made evident by Aho's Compilers: Principles, Techniques and Tools - affectionately referred to as The Dragon Book - in 1977.
  • jazzedjazzed Posts: 11,803
    edited 2014-06-09 11:01
    Javascript is a huge success ;-)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-06-09 11:03
    ksltd,

    Wow. Not even I would go that far, nor am I capable of such biting eloquence, but it doesn't mean that I disagree. It used to be that Fortran was known as the "language of the streets." But, from your comments, it appears that vulgarity has found a new home. :) (Are you a book or movie reviewer by trade?)

    -Phil
  • jazzedjazzed Posts: 11,803
    edited 2014-06-09 11:31
    "And now for something completely different ...." but on topic LOL.
    BRIDGEKEEPER: 
    Stop! 
    Who would cross the Bridge of Death must answer me these questions three, ere the other side he see. 
    LAUNCELOT: 
    Ask me the questions, bridgekeeper. I am not afraid. 
    BRIDGEKEEPER: 
    What... is your name? 
    LAUNCELOT: 
    My name is 'Sir Launcelot of Camelot'. 
    BRIDGEKEEPER: 
    What... is your quest? 
    LAUNCELOT: 
    To seek the Holy Grail. 
    BRIDGEKEEPER: 
    What... is your favourite colour? 
    LAUNCELOT: 
    Blue. 
    BRIDGEKEEPER: 
    Right. Off you go. 
    LAUNCELOT: 
    Oh, thank you. Thank you very much. 
    ROBIN: 
    That's easy! 
    BRIDGEKEEPER: 
    Stop! Who approacheth the Bridge of Death must answer me these questions three, ere the other side he see. 
    ROBIN: 
    Ask me the questions, bridgekeeper. I'm not afraid. 
    BRIDGEKEEPER: 
    What... is your name? 
    ROBIN: 
    'Sir Robin of Camelot'. 
    BRIDGEKEEPER: 
    What... is your quest? 
    ROBIN: 
    To seek the Holy Grail. 
    BRIDGEKEEPER: 
    What... is the capital of Assyria? 
    [pause] 
    ROBIN: 
    I don't know that! Auuuuuuuugh! 
    BRIDGEKEEPER: 
    Stop! What... is your name? 
    GALAHAD: 
    'Sir Galahad of Camelot'. 
    BRIDGEKEEPER: 
    What... is your quest? 
    GALAHAD: 
    I seek the Grail. 
    BRIDGEKEEPER: 
    What... is your favourite colour? 
    GALAHAD: 
    Blue. No, yel-- auuuuuuuugh! 
    BRIDGEKEEPER: 
    Hee hee heh. Stop! What... is your name? 
    ARTHUR: 
    It is 'Arthur', King of the Britons. 
    BRIDGEKEEPER: 
    What... is your quest? 
    ARTHUR: 
    To seek the Holy Grail. 
    ***BRIDGEKEEPER: 
    What... is the air-speed velocity of an unladen swallow? 
    ***ARTHUR: 
    What do you mean? An African or European swallow? 
    BRIDGEKEEPER: 
    Huh? I-- I don't know that. Auuuuuuuugh!
    
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-09 12:26
    Americans tend to measure success by popularity... we even have Facebook (and popularly elected leaders).

    Frankly, many many years ago I wanted the BasicStamps to have C and couldn't see why they couldn't or wouldn't provide it.. I have learned a lot since then. And now I feel a bit embarrassed. The more I learn about GCC, C, and C++; the more I desire to return to Spin, PASM, and Forth on the Propeller.

    Catalina C seems to be better documented for the Propeller at this point in time than GCC. But that doesn't make C on the Propeller any better than C on anything else. It is the Propeller that is superior.
  • tomcrawfordtomcrawford Posts: 1,129
    edited 2014-06-09 12:28
    "C Sucks". Gene Gonzales
  • GadgetmanGadgetman Posts: 2,436
    edited 2014-06-09 13:15
    Just one note...

    Please note that the legality of downloading books from that site is pretty dubious.
    This book is still under copyright, and is actually still for sale.
    (Kindle edition i $24 )
  • User NameUser Name Posts: 1,451
    edited 2014-06-09 14:14
    ksltd wrote: »
    By any measure, C is quirky, flawed and a huge failure.

    Wow!

    If I were the technical consultant for some hypothetical dictator, and said dictator decided that henceforth his country would have but one programming language, and he assigned me to pick it, I'd pick C in a heartbeat. Hands down. Nothing even comes close to being a universal language, imho. I base this on execution speed, versatility, and flexibility if nothing else.
  • 4x5n4x5n Posts: 745
    edited 2014-06-09 15:09
    User Name wrote: »
    Wow!

    If I were the technical consultant for some hypothetical dictator, and said dictator decided that henceforth his country would have but one programming language, and he assigned me to pick it, I'd pick C in a heartbeat. Hands down. Nothing even comes close to being a universal language, imho. I base this on execution speed, versatility, and flexibility if nothing else.

    I personally would pick assembly as the one programming language allowed. Oh that's right C is a high level assembly. :cool: Truthfully though there is a time and place for high level languages like perl and (even though I don't use it) python ( never got past the blocking by indentation thing).

    Personally though while knowing C/C++/Java is assumed for software developers looking for a job and if you're looking for a job developing software for embedded control knowing assembly is a must. While spin is nice for what it is and does don't expect to get many software development jobs knowing only spin and pasm!
  • $WMc%$WMc% Posts: 1,884
    edited 2014-06-09 18:57
    Seems like Complier/Interpreter quality and Program coding quality are getting mixed up here.
    '
    "Basic","C-C+-C+++", "Python","Perl", "Java" And "what ever else" all compile or interpret to some form of ASM.
    '
    Some are way better than others. This has nothing to do with the Programing lingo.
    '
    I have noticed that C and Java coder's like to type more the Basic coders.
  • jazzedjazzed Posts: 11,803
    edited 2014-06-09 19:59
    $WMc% wrote: »
    I have noticed that C and Java coder's like to type more the Basic coders.


    By Jove, I think you've got it!
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-09 21:57
    Gadgetman wrote: »
    Just one note...

    Please note that the legality of downloading books from that site is pretty dubious.
    This book is still under copyright, and is actually still for sale.
    (Kindle edition i $24 )

    Opps. Living in Taiwan seems to allow me to find free PDF versions of texts that shouldn't have such repositories. Should I remove the link to protect Parallax, et al?
  • RossHRossH Posts: 5,505
    edited 2014-06-09 22:35
    Of course, Kernighan and Richie just side-stepped the issue by mentioning that all the i/o is in the libraries which are not actually part of ANSI C.

    You are talking about "K&R" C.

    "ANSI" C does include the libraries - e.g. see http://www.csse.uwa.edu.au/programming/ansic-library.html

    Ross.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-06-10 02:12
    I am just curious, since "K&R C" was developed to create operating systems, according to K&R, does anybody know of a functional OS that was created, using "K&R C"? And another thought, how well would "K&R C" work on the Propeller? I guess without the libraries you would just have to re use a whole bunch of functions, manually.

    Ray
  • RossHRossH Posts: 5,505
    edited 2014-06-10 02:22
    Rsadeika wrote: »
    I am just curious, since "K&R C" was developed to create operating systems, according to K&R, does anybody know of a functional OS that was created, using "K&R C"?

    Unix.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-06-10 02:45
    Yes, the ANSI C Standard does include libraries.

    But the way that Kernighan and Richie state it, i/o are not part of the C language and that is why they are in the libraries. I suppose this results in another debate about what is and isn't the C language.

    I just uploaded the V0.98 of the SimpleText libary for GCC and the documentation is a huge improvement over what I had that came with my installation of SimpleIDE. This is the library that uses the serial interface and is of key importantance. Nonetheless, there is the Parllax SimpleText way, the ANSI C Standard I/O way, and the Arduino C++ way that uses classes of Serial and Stream.

    For a language that is supposed to sustain portablity, Parallax has pretty much ignored the concepts of STDIN, STDOUT, and STDERR and replaced the three with the Debug/Terminal port. And other serial ports are designated as a Device.

    ++++++++++++
    So the assertion that i/o is not part of the C language seems to agree with the fact that asynchonous serial is done a bit differently wherever I look.

    Catalina C on the Propeller also has its own vision of compliance of i/o with C portablity. In big programs with few serial ports, the variations may not be a huge issue. Not sure what to say about standard i/o when the Propeller provides keyboard and monitor services that should default to STDIN and STDOUT, with maybe STDERR.

    Why am I looking at all this? Well, I thought that it would be easy to port C or C++ code to the Propeller GCC. I am not so sure that I was realistic. It may be quite easy for seasoned programmers and I am just struggling as the documentation for GCC is still in a late Beta condition.

    Conclusions --
    GCC seems to be getting much closer to be ready for public use.
    Though I dislike working without complete documentation and with Beta versions of software; the ability to do so are part of mature programming skills.
    If one is waiting for the dust to settle, they are still programming with training wheels.
    ANSI standards are helpful, but never quite fit the real work of producing useful software. Committees that have to vote to accept this or that will never quite keep up with real creativity.

    I guess I just have to accept that I need to learn C++ and how it uses Object Oriented Programing design, though I was hoping to just learn C.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-06-10 02:48
    According to some article that I read that was cited here in this thread, UNIX came before C. I always thought that it was UNIX, but since that is not the case, that is why I posed my question. Now that I think about it, maybe "K&R C" should be used with the Propeller, since it is for educational purpose; maybe somebody can come up with an elegant OS for the Propeller while they were at it.

    Ray
Sign In or Register to comment.