Live data from Hacker News

Who Says C is Simple? (2010)

eecs.berkeley.edu

51–59 of 59 posts

Re: Who Says C is Simple? (2010)

#51

All of the examples here are really horrible code. This is the second article in a few days on Hacker News to list out a few examples of how hard C is. And for little reason; there's absolutely no value in being able to write something like: return ({goto L; 0;}) && ({L: 5;}); It probably has a bug, will be hard to debug, and isn't more performant than writing it in a clearer way. And unfortunately, while the example…

> This points to a need for a new language that avoids these issues. I think Rust is the answer, but I would like to see more languages try to fill that gap--competition is healthy. Programs written in C and C++ may have issues because the languages assume the programmer knows what they are doing. This assumption leads to some great solutions to hard problems because the programmer is essentially free to do what they…

> Programs written in C and C++ may have issues because the languages assume the programmer knows what they are doing. This assumption leads to some great solutions to hard problems because the programmer is essentially free to do what they want.

There’s an assumption here that it would be impossible to design a language which would make these solutions available without being as error prone. Existing languages may be less capable than C, but that’s only because equally capable languages with less risk haven’t been created (Rust may be a solution, I'm not sure yet).

What exactly do you think can’t be done in a language that is less error-prone?

> We do not need new languages. What we need is programmers who won't abuse the languages we already have.

You’re part of the problem. It takes incredible hubris to say something like this, to think that it’s even possible for a human to do this.

Every nontrivial networking program written in C has security holes caused by memory management issues. If you’re going to claim that these errors are caused by bad programmers, then every C programmer is a bad programmer, because every C programmer has written bugs like this. If you’re claiming that bugs caused by C’s error-prone semantics are programmers abusing the language, then using C is equivalent to abusing C. The very best programmers writing C write bugs in C that they wouldn’t write in a language like Rust.

A system which depends on humans being perfect is bound to fail. There’s simply no way you can reasonably debate this fact.

Every other engineering field has redundancy, multiple layers of error checking that catch errors.

Until you see this as a problem then you’re a danger to any mission-critical product you work on. Not understanding that using C is a risk displays a shocking level of naiveté for a professional in this field. I’m not saying C is never a good choice. I write a lot of C myself, but I do so with the awareness that my code is not being checked adequately and that I have to take extreme measures to ensure that my code is well-validated.

Re: Who Says C is Simple? (2010)

#52
post #48

Earlier quoted context omitted.

> And, you do realize that one of the simplest languages for compiler writers, lisp, doesn't have to move heaven/earth to make that calculation work out how you want it. I've written a C compiler and am currently writing a Lisp compiler, and I'm not sure where you get the idea that Lisp is a simple language for compiler writers. Lisp's simple representation belies a very complicated runtime, to the point that the maj…

This seems to get back to the other debate that crops up with "simplest." Just because I posit that it is one of the simplest languages, does not mean I imply it is by definition simple.

I'm pretty comfortable with asserting that there's no reasonable definition of "simple" which would make a mature Lisp compiler simpler than a mature C compiler.

Re: Who Says C is Simple? (2010)

#53
post #48

Earlier quoted context omitted.

This seems to get back to the other debate that crops up with "simplest." Just because I posit that it is one of the simplest languages, does not mean I imply it is by definition simple.

I'm pretty comfortable with asserting that there's no reasonable definition of "simple" which would make a mature Lisp compiler simpler than a mature C compiler.

Fair, though I am focusing on the less mature situations. Specifically, a naive lisp evaluator is much easier than a C compiler.

Are there any mature compilers, for any language, that would qualify as simple?

Re: Who Says C is Simple? (2010)

#54
post #43

Earlier quoted context omitted.

> Last but not least, C had not yet taken the world by storm, and a lot of those developers and companies had never even heard of C, and the ones that had heard of it were pretty dubious, more often than not. Specially since some of us were exposed to languages (Modula-2, Turbo Pascal) that were more feature rich than C while allowing similar performance levels on the same systems.

Certainly, although of course it depends on which range of years we're talking about, and which platforms we're talking about; you're talking about later years than PDP 11 C and more capable platforms than the "NES" mentioned above. Prior to Turbo Pascal there was UCSD Pascal, which was extremely popular but not high performance. But the whole idea that any high level language could be even close to competitive with…

> But the whole idea that any high level language could be even close to competitive with assembly was a very radical idea considered laughable by the mainstream, for many years, which I think is the underlying idea here.

From the papers I used to dig during my degree, I would assume Algol derivatives were already quite competitive, given that quite a few OS were implemented in them.

> I wasn't a Turbo Pascal user, but wasn't it, too, tied to the one platform?

Yes, to the PC. I eventually moved into C++ as time came to move along to more portable languages, as C was too primitive for my taste and I had just got hold of Turbo C++.

> Wirth's languages after Pascal, I dunno; everyone heard of them but they were never that widely adopted. I guess I'm unclear on why.

I was lucky to discover Oberon, and to use the Native PC version.

It opened my eyes that is it possible to have workstation OS done in GC enabled systems programming languages.

It also made me research Modula-3, Component Pascal, Oberon-2 and Active Oberon.

Coming back to the original point, back when coding for home computers, if performance was an issue, Assembly was the only option (Z80, 68000, x86).

For me, C was something I would see mentioned in some computer magazines about those new expensive UNIX workstations.

Re: Who Says C is Simple? (2010)

#55
post #53

Earlier quoted context omitted.

I'm pretty comfortable with asserting that there's no reasonable definition of "simple" which would make a mature Lisp compiler simpler than a mature C compiler.

Fair, though I am focusing on the less mature situations. Specifically, a naive lisp evaluator is much easier than a C compiler. Are there any mature compilers, for any language, that would qualify as simple?

> Specifically, a naive lisp evaluator is much easier than a C compiler.

That's true, but a naive Lisp evaluator is a) not a compiler, and b) not correct. A naive implementation of Lisp leaks memory very rapidly, and obvious memory management schemes fail. Garbage collection was invented for Lisp to deal with these problems, and even assuming an immature implementation, GC isn't trivial. The simplest implementation of mark-and-sweep garbage collection requires a lot of discipline to make sure that objects are correctly allocated so that in-scope objects are kept live and out-of-scope objects are discoverable as dead. Even if you're writing your own allocator for C, that allocator is pretty trivial in comparison.

Re: Who Says C is Simple? (2010)

#56
post #43

Earlier quoted context omitted.

> Last but not least, C had not yet taken the world by storm, and a lot of those developers and companies had never even heard of C, and the ones that had heard of it were pretty dubious, more often than not. Specially since some of us were exposed to languages (Modula-2, Turbo Pascal) that were more feature rich than C while allowing similar performance levels on the same systems.

Certainly, although of course it depends on which range of years we're talking about, and which platforms we're talking about; you're talking about later years than PDP 11 C and more capable platforms than the "NES" mentioned above. Prior to Turbo Pascal there was UCSD Pascal, which was extremely popular but not high performance. But the whole idea that any high level language could be even close to competitive with…

> Another language worth mentioning is Bliss

I work with a former member of the DEC compiler team who brings up BLISS from time to time. One feature he liked was the control over register assignment, making it easy to keep frequently used variables in registers across function calls.

I'd be curious to know whether BLISS lives on at VMS Software, Inc. as they port to AMD64.

Re: Who Says C is Simple? (2010)

#57
post #38

I've been looking for this for months, I wanted to link this to my friend who said he prefers C to Java for his CS classes.

Come on, almost any language I can think of is a better fit for CS classes than Java.

But get this, he said Java was HARD. Compared to C?

Re: Who Says C is Simple? (2010)

#58
post #47

Earlier quoted context omitted.

An uninitialized variable is UB, not implementation-defined. Thus, the compiler is free to treat the variable as though it doesn't have a value at all, or change it's value at will. It's not uncommon for the value of an uninitalized variable to change at strange places in the code that you wouldn't expect, because the compiler initially said "Variable x will be kept in register %eax", but then without a value to init…

What evidence do you have that it's an uninitialized variable? It's a code fragment; it's not in a function body. The way I read it, it was simply to document the type of x. 'x' could be a global for all we know.

My evidence is that the entire page is basically just to shows CIL's output on various pieces of code, and CIL's output is linked on the page and looks like this:

    /* Generated by CIL v. 1.3.7 */
    /* print_CIL_Input is true */

    #line 1 "cilcode.tmp/ex30.c"
    int main(void) 
    { int x ;

      {
    #line 2
      return (x == (x != 0));
    }
    }
From that I think it's safe to say that it's talking about 'x' being an uninitialized variable in a function (Because that's what they put into CIL). This code definitely has the issue from UB that I described above.

Re: Who Says C is Simple? (2010)

#59
post #54

Earlier quoted context omitted.

Certainly, although of course it depends on which range of years we're talking about, and which platforms we're talking about; you're talking about later years than PDP 11 C and more capable platforms than the "NES" mentioned above. Prior to Turbo Pascal there was UCSD Pascal, which was extremely popular but not high performance. But the whole idea that any high level language could be even close to competitive with…

> But the whole idea that any high level language could be even close to competitive with assembly was a very radical idea considered laughable by the mainstream, for many years, which I think is the underlying idea here. From the papers I used to dig during my degree, I would assume Algol derivatives were already quite competitive, given that quite a few OS were implemented in them. > I wasn't a Turbo Pascal user, b…

> I would assume Algol derivatives were already quite competitive, given that quite a few OS were implemented in them.

Yes, and PL/1 for systems programming in Multics and IBM systems, etc. (We won't count Burroughs since they literally designed the hardware to be programmed in Algol.)

That shows my comment was far too imprecise; it must have to do with different segments of the industry or something.

> back when coding for home computers, if performance was an issue, Assembly was the only option (Z80, 68000, x86).

Indeed.

Post reply on HN