Guest User

history of C and why it's garbage

a guest
Oct 12th, 2015
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. On history and justification of C programming language: Best System Language Ever or Bad by Design?
  2. (numbered summary version)
  4. There's a recurring theme where people think the C language's design is good for systems programming, even today. These people think that someone sat down, thought of every tradeoff, and made the best ones for system programming. They assume it couldn't have been better because any modification would hurt its goals of performance or portability. This isn't true in the slightest and totally contradicts real reasons why C is designed the way it is. Even back then, there were better languages/OS's [1] that cheap hardware just hadn't caught up to. That cheap hardware's limitations, and them alone, drove the design decisions of BCPL, B, and then C.
  6. You wouldn't want my opinion, though: let's look a historical records and papers on the development of these. Hacker New's commenter pjmlp sent me a great video [2] detailing the history of C and C++ languages w/ pics and paper excerpts. The author takes it step-by-step showing what the goals were, what they were using, the problems they encountered, and what changes they made. Thompson and Ritchie actually had little to do with most of C's key decisions and philosophy: borrowed or stolen from BCPL at Cambridge with little to no credit early on. They kind of went with it from there.
  8. Numbered List of Key Points in C's History
  10. 1. Starts with assembler code on EDSAC [3], the Most Godawful Computer on Earth (TM).
  12. 2. University orders a watered-down Atlas called Titan/Atlas2. Must wait years to get it and still another year to make it run.
  14. 3. Need new language for it plus it was trendy to make new languages for new computers.
  16. 4. ALGOL60 [4] had many nice features of languages today but was too theoretical: only existed on paper.
  18. 5. Fortran was locked into IBM mainframes and mapped 1-to-1 to their hardware, not Atlas or Titan.
  20. 6. Designed CPL language as a real-world version of ALGOL *before* their Titan shipped. CPL had all kinds of features supporting many types of applications, even lambda calculus!
  22. 7. Had to use Most Godawful Computer on Earth (EDSAC) to build the CPL compiler.
  24. 8. Queued up behind others with snippets of EDSAC machine code testing pieces of it. Predictably, this didn't scale to CPL's size and complexity. Abandoned CPL compiler.
  26. 9. New design goal: trim out anything hard to compile from CPL. Naturally eliminates most features for robust and maintainable programming.
  28. 10. New design goal: give programmer total control to the point that he or she can do arbitrary stuff in memory. Maps better to Most Godawful Computer on Earth's style of execution and constraints.
  30. 11. The result of these was BCPL [5]: a typeless, word-oriented language with few keywords and unrestricted use of memory. Created philosophy of "the programmer is in charge and gets no help." Compiler was easy to write on Most Godawful Computer on Earth. Ran fast on it, too.
  32. 12. BCPL author took it with him to MULTICS project [6], where Ken Thompson and Dennis Ritchie were working. Got used on some portions of it. Thompson apparently liked it.
  34. 13. MULTICS was built but failed in market because of delays, scope, and cost ($7+ mil per unit).
  36. 14. Thompson was limited to a PDP-7 [7] in next job. It couldn't run MULTICS or advanced languages on it. Plus, PDP-7's OS and tools sucked. He and Ritchie decided to build a bare-bones version of MULTICS, called UNICS, in assembly focusing on simplicity and performance above everything. Stripped out or changed most features benefiting safety/security, maintenance, and consistency.
  38. 15. Around same time, Thompson was trying to get BCPL to work on his similarly-awful PDP-7. Had to trim it further to make it fit. Changed syntax for personal style. That included long-time headaches like going from ALGOL := assignment and = equality to = assignment and == equality. Resulted in B language.
  40. 16. The PDP-11 [8] was byte/character-oriented instead of word-oriented. B didn't work well. Ritchie added limited typing to it to support these plus a few other changes. Result was the C language.
  42. 17. Rewrote parts of UNIX in C. Others were too hard.
  44. 18. Those difficulties led to adding struct's which allowed rest to be re-written in C. Neither C nor UNIX were meant to be portable despite some people's claim it was a "cross-platform assembler."
  46. 18. Simplicity of C and UNIX allowed easy porting anyway which started from a year later onward by other people.
  48. 19. K&R adds some types and standard I/O. Remained for years the baseline for portable C.
  50. 20. Bjourne loves programming in Simula [9]: an ALGOL60 superset with classes and concurrency. Creates C with Classes to bring it closer to Simula.
  52. 21. Bjourn adds features from ALGOL68, Ada, CLU, and ML to C w/ Classes to produce C++: a C extension that reduces freedom where sensible but mostly adds features for productive or maintainable programming.
  54. 22. ANSI C standard created a superset of C features, including some from C++. Becomes standard style for C programming. Tons more code written this way.
  56. Conclusion(s)
  58. So, there you have it. They started with a great language (ALGOL60) that inspired Go, etc. Needed something ground in reality, leading to similarly great CPL. Hardware and software were so hard to use they stripped it to bare minimum (BCPL). Thompson stripped that to B because his PDP-7 was too limited and added syntax problems purely due to preference. Ritchie added a little to that to get the PDP-11 to work, resulting in C. Added struct's to for more complex data structures. Writing the simple, UNIX in C language caused C to flourish as it did due to social and economic reasons [10]. Eventual standard borrowed a bit from C++. All the C code out there resulted.
  60. Hardware eventually got better than EDSAC, PDP-7, or PDP-11. Language and OS decisions created due to its limitations aren't removed. All of that is extended or worked around instead. UNIX and later C applications have those issues as a result. Result is a mess so huge [11] that it might be impossible to fix.
  62. Conclusion: the worst aspects of UNIX and C were intention design decisions that had nothing to do with what a good, systems language should look like and everything to do with limitations of an EDSAC, PDP-7, & PDP-11.
  64. Conclusion 2: we should've ditched or modified C to look more like ALGOL68 a long time ago. Like Bjourne and Wirth were doing.
  66. Conclusion 3: C and UNIX should be avoided where possible because they're Bad by Design for reasons that stopped applying sometime in the 80's or early 90's.
  68. However, if you're device's hardware is PDP-11 equivalent, then there is a language and OS that are stripped enough to run on it. Might want to consider C and UNIX 1.0 then. ;)
  70. [1]
  72. [2]
  74. [3]
  76. [4]
  78. [5]
  80. [6]
  82. [7]
  84. [8]
  86. [9]
  88. [10]
  90. [11]
Add Comment
Please, Sign In to add comment