7 ms·
I have to say, the way indentation and brackets were done here looks like it's just inviting subtle bugs. Take this for example: if (peekc) { c = pee
by amyjess 6y ago
I have to say, the way indentation and brackets were done here looks like it's just inviting subtle bugs. Take this for example:
if (peekc) {
c = peekc;
peekc = 0;
} else
if (eof)
return(0); else
c = getchar();
- bawolff 6y agoI dont think it would look that out of place if he was using the ternary operator which is the same thing after all. E.g.: if (peekc) { c = peekc; peekc = 0; } else eof ? return(0) : c = getchar(); The first else clause sill looks weird, but the final part isn't nearly as out of place (well i guess assigning in a ternary would be weird, but in terms of indentation) and its not like we actually changed anything.
- andreareina 6y agoCan't return in a ternary.
- amelius 6y agoCorrect, return is not an expression. But then again, he could if he wanted to, as the language designer ;)
- Maken 6y agoMaybe it was not worth the extra work.
- Koshkin 6y agoWouldn't it be wonderful if we could write a = return b;
- colejohnson66 6y agoWhat would that even do? Return b, but then set b to a right before “deleting” a? That would serve no purpose.
- yitchelle 6y agoIt would have made code review a nightmarish activity for the team.
- wruza 6y agoWhy nightmarish? A reviewer may explain that it is prone for other human to overlook the end of conditional and go sleep as usual. I never understood the emotional component of blaming someone’s personal code styles, as if it were a religion with sacrifices and blasphemy instead of just a practical way of coding in a heterogeneous team. This triggers me because many people jump on “bad c0de” in the forums, but then you read some practical code on github, and it is (a) not as perfectly beautiful as they imagine at all and (b) is still readable without nightmares they promised and (c) the algorithms and structure itself requires programmer’s perception and understanding levels far beyond the “it’s monday morning so i feel like missing an end of statement in a hand-written scanner” anyway.
- sriram_malhar 6y agoThat team had Bell Labs researchers, Ken Thompson and Doug McIlroy being among them. Their brains could handle much harder things!
- code_sloth 6y agoIf you judge the coding style of the early 1970s with modern standards, it isn't going to look great. 50 years is a loooong time. dmr was one of, if not the first C programmer(s).
- kiwidrew 6y agoAnd he was almost certainly using ed(1) as his editor and a mechanical teletype at 7.5 or 10.0 characters per second as his terminal... The C language (and all of Unix) was designed to be very terse as a consequence.
- tralarpa 6y agoWas it different for the designers of ALGOL/SIMULA/Pascal?
- kiwidrew 6y agoYeah, those languages were IIRC designed to be edited offline (as a deck of punch cards) and submitted to a mainframe via high-speed card reader as a batch job.
- tralarpa 6y agoVery interesting when you think about it. A language created in 2009 (Go) owes its syntax to a language from 1969 (B), and the latter looks like it does because it was designed during a short transition period between offline editing (1960s) and electronic terminals (1970s). And there are people claiming that computer scientists are not conservative :) To what extend this explanation is correct is another question... The article by Denis Richie says "Other fiddles in the transition from BCPL to B were introduced as a matter of taste, and some remain controversial, for example the decision to use the single character = for assignment instead of :=". It's a kind of butterfly effect :) Mr. Richie prefered "=" over ":=" and fifty years later a server crashes somewhere because somebody wrote a=b=c instead of a=b==c.
- rightbyte 6y agoIf you can only read it line by line: return(0); else makes a bit of sense.
- amw-zero 6y agoThe difference between Dennis Ritchie and the average programmer of today is, Dennis Ritchie did not write bugs in the first place.
- Koshkin 6y agoWell, some say (I disagree) that C is a bug.