Slashdot Mirror


What's To Love About C?

First time accepted submitter edA-qa writes "Antiquated, clunky, and unsafe. Though beloved to some, C is a language that many choose to hate. The mass opinion is indeed so negative it's hard to believe that anybody would program anything in C. Yet they do. In fact a lot of things, even new things, are programmed in C. The standard was recently updated and the tools continue to evolve. While many are quick to dismiss the language it is in no danger of disappearing."

27 of 793 comments (clear)

  1. Re:because by Anonymous Coward · · Score: 5, Insightful

    Using a string literal as not const is very bad form.

  2. One good reason... by Anonymous Coward · · Score: 5, Insightful

    It's not the bloated obscenity that is C++.

    1. Re:One good reason... by AuMatar · · Score: 5, Interesting

      I like C++, but I can think of a few. Lets ignore for the moment things like macros that are outdated in C++ and kept for C compatibility. We can easily get rid of:

      *Value templates.
      *Diamond inheritance (just make it illegal)
      *The entire algorithms part of the STL. Nobody uses it and it makes for unreadable code (keep the container classes, of course)
      *Kill either structs or classes. We don 't need both, with one being syntactic sugar to change the default visibility on the other
      *The iostream libraries. I don't think I've ever seen code that didn't say fuck that and just use C style stdio. They're clunky.

      That's off the top of my head, without going into things we could do better. And I like C++, it's my preferred language. The real argument here is even though C++ is bloated, it's far from the worst that way. Perl takes that crown, with it's 500 special variables. And the people who complain about C++'s bloat generally like Python or Ruby, which are both just as bloated as C++, without the bonus of it's simplicity.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    2. Re:One good reason... by bluefoxlucid · · Score: 5, Interesting

      Compare C++ to Objective-C. You might dislike the syntax of Objective-C some, but it has clear advantages:

      • It is a strict superset of C: C compiles as Objective-C (C++ doesn't, since structs have a different syntax, among other things)
      • More importantly, it is runtime-resolved. That means you can expand Objective-C classes without breaking the ABI; in C++ you can't add members to classes, at all. Class members can be in different libraries, and in different header files (a "private" member is one not exposed in the API, but you COULD access it directly by defining it or including the header for it).
      • The mangling in C++ is a serious pain and makes loading C++ libraries and programs retardedly slow.
      • Swizzling (you can replace members of classes at runtime--not just inherit, but actually overload class members) makes the language quite a bit more flexible.
      • Operator overloading and templates are an abomination, and don't exist in Objective-C.

      We can all supply better languages for a purpose; Objective-C and C++ have the same purpose (an object oriented general purpose native compiled mid-level programming language), and so this comparison is relevant. Comparing to Java or Python or C#.NET would be irrelevant.

      A loose argument can be made that Objective-C is better because of its much better polymorphism features--the main point of an object oriented language. Objective-C does indeed supply much more flexible, more useful polymorphism; C++ class inheritance is pretty rigid because of its rigid ABI. Objective-C's run time resolution enables this, and I would admit that run time resolution of class objects is a bit slower ... if it wasn't optimized by cache (i.e. resolve the first time on demand and build the PLT) AND if C++ class member mangling didn't make actually building the PLT at load time so god damn slow. Two points to Objective-C.

      Objective-C doesn't have operator overloading. Operator overloading is often claimed as a negative feature because it makes code hard to read. The effective argument AGAINST operator overloading is is that everyone is used to the 'cout >>' and 'cin

      The biggest argument for operator overloading is really that nobody uses it, so we're all familiar with the corner case syntax in the standard library. Think about that: the biggest argument for it is that it never gets used.

      Also, Objective C has reference counting with cycle detectors and all. Garbage collection is a limited feature (you can create garbage collected objects intentionally).

      It's actually relatively easy to argue that C++ is an abomination. It's not unexpected either: it's an old language, and an OOP shim hacked on top of a well-designed mid-level language. That C is so well designed is surprising; but then it is the legacy of assembly, PASCAL, FORTRAN, and BASIC. COBAL is circa 1959, BASIC circa 1964, C circa 1972, C++ circa 1984. C++ had only Smalltalk to learn from, really, and was trying to be C with Classes.

    3. Re:One good reason... by AuMatar · · Score: 5, Insightful

      Value templates- yes, templating on the value, rather than the type. It's an extremely niche use case that causes difficult to read code and provides little in the way of benefits. I doubt even 5% of the user base knows it exists. Kill it.

      Diamond inheritance- it isn't used much, but when it is it's a problem. Because you don't know when the common base class will be initialized, or which constructor will be called by what values. Make it illegal to solve those problems (or add it to the specification)

      STL algorithms- sorry, totally disagree. The entire thing is a horrible hack based on using constructors to make quasi-first order functions. They were never meant to work like that. At best it's confusing, at worst it's unreadable and hard to debug. I bounce any code review I see using them. Worse, it encourages people to make more code like that, which tends to be done worse and be even more unreadable and frequently just wrong (generic programming has a lot of gotchas). I'd rather see the whole thing killed.

      Structs vs class- it is pretty harmless, but we're talking bloat. It's bloat. There's no reason to have both. I wouldn't say this is something that has to be fixed, but it's silly to have the two of them.

      Yup, I stand by my original opinion- all of these could be cut with no real loss to the language. Then again, if I were writing my own language I'd take C, add constructors, destructors, and C++ style syntax for member functions, add container classes, and call it perfect.

      --
      I still have more fans than freaks. WTF is wrong with you people?
  3. Maybe because it compiles down to the metal... by skids · · Score: 5, Insightful

    ...and not some VM? Most of the popular languages these days are all dynamic. And they are very convenient and nice. But if you actually want to know what the machine is actually doing, and want to have a say in such things, C is the way to go.

    I mean, unless you want to, you know, use pascal or fortran or something.

  4. Good habits by Bucky24 · · Score: 5, Insightful

    Personally the thing I like most about C is that it's not "safe". It doesn't take care of a lot of memory management for you and you can easily eat up all the memory or introduce a buffer overload vulnerability if you're not paying attention. It forces programmers to actually look at what they're doing and consider what it will do in the long run, and causes good coding habits to form. I think the majority of people who dismiss C as "too hard" are coming from Java programming. C gives you a lot of power, but, as the well-cliched saying goes, "with great power comes great responsibility".

    --
    All the world's a CPU, and all the men and women merely AI agents
    1. Re:Good habits by localman57 · · Score: 5, Informative

      Exactly. My company does a lot of different things from embedded systems to web interfaces, and, generally speaking, the C guys write better Java code than the Java guys write C code.

    2. Re:Good habits by jmsp · · Score: 5, Insightful

      > It forces programmers to actually look at what they're doing

      OMG! There. That's where all the hate comes from.

      --
      (Programming in C since 1984)

    3. Re:Good habits by ShanghaiBill · · Score: 5, Insightful

      the C guys write better Java code than the Java guys write C code.

      My experience is that the C guys (and gals) often write better Java than the Java guys write Java.
      Programmers who have never written in C (and/or assembly) often have a poor understanding of how computer actually work.

  5. Control by Dan+East · · Score: 5, Insightful

    C offers control. If you can't handle having that much control (over memory, how the CPU acts on that memory, etc) then your software will have many problems and you will hate C.

    --
    Better known as 318230.
    1. Re:Control by jythie · · Score: 5, Insightful

      Not just control, but predictability. C does exactly what you tell it to do and you can see what it is doing more easily then other languages. You can tell C++ to do 'X', but it might slip in a 'Y' and 'Z' without telling you.

  6. The portable assembler by heson · · Score: 5, Insightful

    Close to the metal but still not specific to any machine if you do not need to. Easy to understand exactly what machinecode the compiler will produce.

  7. Sesame Street already covered this by Zephyn · · Score: 5, Funny

    It's for cookie.

    That's good enough for me.

  8. Shorthand for Assembler by codefool · · Score: 5, Interesting

    The power of C is - and always has been - that it is a shorthand for assembly. It compiles very small and runs very fast, making it ideal for embedded systems.

    --
    "Stop whining!" - Arnold, as Mr. Kimble
  9. Think of it as standardized assembly programming by localman57 · · Score: 5, Insightful

    C is going to stay around for a long time in embedded systems. In this environment many microcontrollers still have 4k or less of RAM, and cost less than a postage stamp. In these systems there is virtually no abstraction. You write directly to hardware registers, and typically don't use any dynamically allocated memory. You use C because, assuming you understand the instruciton set, you can pretty much predict what assembly instructions it's going to generate and create very efficient code, without the hassle of writing assembly. Aditionally, your code is portable for unit testing or, to a lesser degree, other microcontrollers. This allows you to write a program that will run in 3.2 k of ram, rather than 4k, which allows a manufacturer to save 4 cents on the microcontroller they pick. This saves you $40,000 when you're making a million of something.

  10. Simple. by Short+Circuit · · Score: 5, Insightful

    Tons of people love to have something to hate. It might be because they don't like something about it...but I think it's mostly because people like to set up communities held together by rhetoric against a tool or technology perceived and portrayed as an enemy.

    "C++ sucks. We are at war with C++. We have always been at war with C++.[1]"

    Swap out "C++" for whatever language you like.

    Certainly there are going to be cases and scenarios where C is preferable over C++, where C++ is preferable over C, or where Brainfuck is preferable over either. Use the right tool for the right job,[2] and the right tool is whichever allows you to most effectively achieve your goals.

    [1] Or, at least since its inception. Or since [insert arbitrary date here].[3]
    [2] For whoever asks "what's the right job for Brainfuck?" ... just wait. Someone will eventually come along and get modded +2 Funny when they reply to you.
    [3] I see what you'll do there, Mr. Connor.

  11. Re:because by localman57 · · Score: 5, Informative

    No, he's right. On systems where your constants exist in a different medium than your variables (such as microcontrollers where variables are in RAM but constants are in flash), declaring a string as const or not const can have a big impact on what resources you eat up. Typcially, there's often a #pragma or non-standard keyword such as ROM that goes along with this.

  12. Re:Useless submission. by Anonymous Coward · · Score: 5, Insightful

    If you're not a developer then you don't care about the nuances of C.

    Of course. Curiosity is a bad thing. You should stick to what you already know, and never try to expand your knowledge beyond your field.

  13. Negative opinions, says who? by fahrbot-bot · · Score: 5, Insightful

    Though beloved to some, C is a language that many choose to hate. The mass opinion is indeed so negative it's hard to believe that anybody would program anything in C.

    The masses to which you refer are idiots. C is great. It lets you do what you want, how you want. True, you're afforded enough programming rope to easily hang yourself, but you learn not to, and while most things can be more easily done in higher languages (you'll have to pry Perl from my dead, cold hands), many things can only be done in languages like C or its derivatives. C is one of those languages that separates the adults from the kids, so put on your big-boy pants, stop whinging about it and step up.

    --
    It must have been something you assimilated. . . .
  14. right tool for the job by bcrowell · · Score: 5, Insightful

    The mass opinion is indeed so negative it's hard to believe that anybody would program anything in C.

    Huh? What mass opinion? Where's the evidence for this?

    Pick the right tool for the job. C is the right tool for some jobs, specifically jobs like writing drivers or operating systems.

    Historically, C won by having an innovative syntax for pointers, which a lot of people liked, and it also won by being a small language that was easy to implement. Because it was small and easy to implement, it ended up being widely available. Ca. 1980, the joke was that C was like masturbation: it might not be what you really want, but it's always available. A lot of people in 2012 may not realize that in the era when C was winning popularity, people didn't usually have access to free compilers, and for many types of hardware (e.g., 8-bit desktops like the TRS-80), there simply weren't any good development tools. Another big win for C was that because it was so widely available, it became easy to find programmers who could code in it; it fed on its own success in a positive feedback loop. This is why languages like java had C-like syntax -- they wanted to ride the coattails of C.

    IMO the biggest problems have been when people started to use C for tasks for which it wasn't the right tool. It started creeping up into higher-level applications, where it wasn't really appropriate. This became particularly problematic with the rise of the internet. Networks used to be small and run by people with whom you had personal contact, so nobody really cared about the kind of buffer-overflow vulnerabilities that C is prone to. The attitude was that if you gave a program crazy input that caused it to crash, well, what was the big deal? You crashed the program, and you were only hurting yourself.

  15. Fortran is better. by Salis · · Score: 5, Funny

    Go ahead. Argue. I dare you.

    v same sig since 2002. v

    --
    Favorite /. tagline: "On the eighth day, God created FORTRAN." And it was good.
  16. Re:news for n00bs by Vlad_the_Inhaler · · Score: 5, Funny

    Move along, nothing left to C

    --
    Mielipiteet omiani - Opinions personal, facts suspect.
  17. Litmus test. by HornWumpus · · Score: 5, Insightful

    If you can't code in C you can't code.

    That said, unless you are doing low level/embedded work if you can't find a better tool for the job, you also can't code.

    C should be _every_ programmers second language at the latest.

    The other thing to love about C? Pointers! Pointers to pointers! etc. Coding without pointers might be safe, so is fapping.

    --
    John McAfee 'It was like that time I hired that Bangkok prostitute; to do my taxes, while I fucked my accountant'
  18. Re:because - by Mike+Buddha · · Score: 5, Funny

    And the funny thing is that most people who write const char* foo really want char const * const foo. You don't want either the pointer or the data pointed at to change. However, almost nobody knows that, so even those who do just use the weaker const char* so people understand the code.

    Hmm. I wonder why there's so much animosity towards C? It's a mystery.

    --
    by Mike Buddha -- Someday the mountain might get him, but the law never will.
  19. Re:because - by TwineLogic · · Score: 5, Insightful

    Oh, no, it's not a mystery. The animosity comes from ignorance and lack of ability. Many newer programmers have never programmed in assembly language or C, and would not be able to build a computer out of logic chips. This same demographic has learned Java and believes that Hashmap is a magic O(1) thing you can just smear onto any algorithm. C was initially popular among people who were, in fact, able to build computers out of 7400-series logic, or even transistors, if need be. In other words, the animosity comes from those who aren't qualified to judge.

  20. Re:Useless submission. by jd · · Score: 5, Funny

    Curiosity is real. Unless declared integer.

    --
    It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)