11 ms·
The cost of forsaking C
- deleted 9y ago[deleted]
- brudgers 9y agoC is so unfashionable that the authors have neglected to update it in light of 30 years of progress in software engineering. Words escape me.
- bitwize 9y agoHe means the authors have failed to update the book, The C Programming Language, not C itself.
- phkahler 9y agoI would say the authors have failed to ruin a classic by trying to update it. It's short, concise, readable, and useful as a reference. Not sure why anyone would want to mess with it. It was still a fun quip about the age of the language.
- epistasis 9y agoIn an age when I expect and experience 0.0.X versions of very popular and important Python packages to have major API-breaking changes, it's extremely relevant to point out how a 30-year old, un-updated, book can be useful.
- berbec 9y agoNot just useful, but impressively currently useful. Picking up K&R with little previous experience, and you can make a program that does something in hours, on a current machine. It's dense, but well-written and easy to pick up.
- tomsmeding 9y agoOut-of-context quote. (Even if the original is slightly strangely written.) The "update it" refers to the book The C Programming Language, not to the C language itself; C itself has seen an update as recently as 2011.
- Avshalom 9y agoIt's not out of context at all. It's bizarre to assume that every book ever written about a subject will be updated constantly by it's (currently septagenarian) authors in perpetuity and/or that a failure to update it is an indication of the culture in general and not the authors having literally anything else to do. It's not like books on C stopped being written by 1990.
- saagarjha 9y agoYes, but The C Programming Language is almost always recommended as the book to read.
- smitherfield 9y agoStill an odd statement, since one of the authors is deceased.
- brudgers 9y agoIt's fractal.
- deleted 9y ago[deleted]
- eptcyka 9y agoI fail to see how an understanding of C would make one better at understanding userspace process scheduling or text editors.
- tomsmeding 9y agoEven if it doesn't, there are plenty things it does make one better at understanding, like the subjects mentioned in the article.
- asimpletune 9y agoYou take for granted how almost all popular programming languages have inherited the execution model of C.
- vvanders 9y agoMay I kindly lay out VSCode and Atom as a counter to your second example? Knowing your allocations and performance at a low level can influence usage of a high level language and have a huge impact.
- UncleEntity 9y ago> I fail to see how an understanding of C would make one better at understanding userspace process scheduling or text editors. Can't even count how many times I've read the sources of some program to figure out what some random button does (or is supposed to do) -- back when I messed around with blender I used the code more often than the wiki to figure things out and found tons of bugs that way.
- sreque 9y agoKnowing C has made me a better and much more versatile programmer than I would be without it. For instance, a while back I had to diagnose a JVM core dumping sporadically, and I was able to use my knowledge of C to try to recover valid return addresses from a corrupted stack, figure out there was a signal handler block on the stack, then further unwind from there to find out the whole story of what likely caused the crash. Knowing C also helps me write more performant code. Fast Java code ends up looking like C code written in Java. For instance, netty 4 implemented their own custom memory allocator to avoid heap pressure. Cassandra also has their own manual memory pools to try to improve performance, and VoltDB ended up implementing much of their database in C++. I've been able to speed up significant chunks of Java code by putting my "C" hat on. I would recommend every college student learn C, and learn it from the perspective of an "abstract machine" language, how your C code will interact with the OS and underlying hardware, and what assembly a compiler may generate. I would consider learning C for pedagogical purposes to be much more important than C++.
- tomsmeding 9y ago> I would recommend every college student learn C, and learn it from the perspective of an "abstract machine" language, how your C code will interact with the OS and underlying hardware, and what assembly a compiler may generate. Do note that these are two very different things. The C abstract machine as defined by the standard is sometimes so different from the actual machines you're going to run your code on, that you get these fine undefined behaviour things that everybody's on about. Please learn both, indeed, and stress the differences; then highlight the advantages of C. C is a dangerous, but powerful tool, and the necessity of warning students about things should not inhibit learning C.
- fao_ 9y ago> C is a dangerous, but powerful tool, and the necessity of warning students about things should not inhibit learning C. C is sharp, yes. It's also a universal interface. Almost every language has bindings for C, and C has bindings for almost everything.
- asimpletune 9y agoI know these guys and they provide legit college-level CS education. If any of you live in the bay and have an education stipend at work, or just want to level up, then I highly recommend.
- inetknght 9y ago> The most recent edition of the canonical C text (the excitingly named The C Programming Language) was published in 1988 So... C99 and C11 aren't things?
- tomsmeding 9y agoThat sentence refers to the book, The C Programming Language. I admit the sentence is strangely worded.
- deleted 9y ago[deleted]
- loeg 9y agoYeah. The sentence is misleading, if not mistaken.
- robotresearcher 9y agoThat was a misquote. The sentence is: 'The most recent edition of the canonical C text (the excitingly named The C Programming Language) was published in 1988; C is so unfashionable that the authors have neglected to update it in light of 30 years of progress in software engineering.' Of course you can't see that 'it' refers to the book when you quote it with half the sentence missing.
- loeg 9y agoI read and understood the context. My claim is that calling K&R, last updated in 1988, "the canonical C text" is misleading, if not mistaken. Canonical C has moved on from K&R in the form of the C99 and C11 standards.
- lsaferite 9y agoPerhaps you are parsing "the canonical C text" differently? I read it as "the canonical 'C text'" and it sounds like perhaps you are reading it as "the 'canonical C' text"
- loeg 9y agoBy all means teach and use C (I do!), but please teach students to refer to C11 or C99, not C89.
- waynecochran 9y agoYes. At least C99. Also, the blog throws in "and C++" in parentheses. C++ is another beast altogether -- it diverged from C a long time ago -- read Scott Meyer's "Effective Modern C++" if you think C and C++ bear any resemblance.
- ChrisSD 9y agoIf you want to "think like a computer" then learn assembly, not C. I'm not joking. In my experience young devs using C get very confused about wtf pointers are really about and what's the deal with the heap, stack, etc. Whereas they understand the concepts better in assembly despite the verbosity. I'm not arguing for a deep understanding of assembly but if the goal is to "think like a computer" than at least a basic understanding is incredibly helpful. Or at least less confusing than C.
- notacoward 9y ago> if the goal is to "think like a computer" If the only goal. The OP listed four.
- gerred 9y agoHe stopped reading after one for the sake of sweet karma.
- Avshalom 9y agoI'll give shit about #1 when someone invents a time machine and prevents Java from existing. #2 is a great reason to learn Latin but the "influence of C" is identical to the influence of Fortran or Pascal or Algol and of equivalent magnitude to (what evolved into) Common Lisp or Scheme. And #4 is true eventually but it only matters when the software is broken.
- notacoward 9y agoWell, that's a better answer than I was responding to. I think I disagree a bit on your response to #2, though. Sure, other languages have also contributed mightily to the design of later languages. Some of them might have contributed more than C. OTOH, they haven't contributed nearly as much to the design of libraries and runtimes that are also important for a working engineer to understand. Programs written in any language are loaded into memory in a manner designed to accommodate C. The primary interface between userspace code written in any language and the kernel is via direct syscalls or libc, which were likewise designed with C's needs in mind. When those APIs do change, it's the C definitions that change and other languages are left on their own to parse the new definitions. So it's true that other languages have been just as influential from a computer scientist's perspective, but from a working engineer's perspective no other language comes close.
- rossdavidh 9y agoI think learning C is a fine thing to do, when the alternative is to learn nothing at all, as knowing C is a quite useful skill. However, a more substantive question should be, "should you learn C next, or R?" or "should you learn C next, or neural networks"? or "should you learn C next, or Bayesian statistics"? It may be that C is more urgent and important to learn than any of those, but if you find that people are not, it is not necessarily the case that they don't see the usefulness of it. They may just have a finite amount of time, and learning Mandarin Chinese ranks higher for them, not least so they can better understand how natural language processing would work if you're involved with non-European languages.
- Avshalom 9y agoC does not help you think like a computer. It has no language level support for memory hierarchies or parallelism. It doesn't about know about integer overflow.
- BeeOnRope 9y agoWhile I disagree with your other claims, I'm especially curious about this one: > no language level support for memory hierarchies By this, I assume you mean cache hierarchies (for example). What languages do?
- hoosieree 9y agoC is tightly coupled and co-evolved with the Von Neumann architecture. If you understand C you can better understand that architecture, but it's far from the only one. Beyond the world of single core CPUs, systems rarely hyper-specialize to the point that the C/Von Neumann system has (focusing all energies on ALU throughput). And the larger (and more distributed) systems we build, the less they resemble Von Neumann machines. So while it's realistic to embrace C for many tasks, it's wrong to convince yourself that "the rest follows" from C.
- dsjoerg 9y agoCan you recommend some non-Von Neumann architectures worth learning about? Maybe you agree with these suggestions I found by Googling, or maybe you have other ideas: https://stackoverflow.com/questions/1806490/what-are-some-examples-of-non-von-neumann-architectures https://stackoverflow.com/questions/1806490/what-are-some-ex...
- mettamage 9y agoI second this, I want to know some recommendations too. Are there university courses out there that teach non-Von Neumann architectures? And what are the application areas? I could Google myself but my experience with HN is that if someone knows a good course, then it is a good course. While with Google, not so much.
- carapace 9y agoThe Mill architecture: > the mill uses a novel temporal register addressing scheme, the belt, which has been proposed by Ivan Godard to greatly reduce the complexity of processor hardware, specifically the number of internal registers. It aids understanding to view the belt as a moving conveyor belt where the oldest values drop off the belt and vanish. https://en.wikipedia.org/wiki/Mill_CPU_Architecture https://en.wikipedia.org/wiki/Mill_CPU_Architecture
- 0xcde4c3db 9y agoThe biggest concrete types of Harvard architecture devices I know of are some older small microcontroller architectures (e.g. the PIC10 and PIC12 families) and purpose-built DSPs (e.g. Analog Devices SHARC and TI C6X families). I'm pretty sure that some GPU shaders are also Harvard architecture, but I've heard that mainstream vendors have moved to a von Neumann model.
- RcouF1uZ4gsC 9y agoC++ and Rust address most of the issues presented in the article (with the exception of being able to read the source code of existing software). My very controversial opinion is that C is obsolete for new programming projects. For example, everything that C can do, C++ can do and better/safer/faster. Rust is also getting there (if not there already). C is not Pareto optimal anymore.
- oconnor663 9y agoI think the article is arguing more for teaching C to new programmers for the educational value, and less for starting serious new projects in C.
- kqr 9y agoI have an issue with the idea of "teaching new practitioners X while telling them that X is not to be used seriously", for so many reasons. 1) It is doing a disservice to the students to tell them that you won't use much of what you are made to learn. 2) A nontrivial amount of people will attempt to use it seriously anyway, sometimes with disastrous results. 3) It usually indicates teacher laziness and/or disinteredness in finding alternative ways to teach. 4) Surprisingly often, when you are not supposed to use X, it is actually useless to learn X. (That is NOT the case in this situation -- there are reasons to learn C -- but the students can't know that unless told so.) 5) There are almost always better alternatives. I have never been unable to find a Y which fulfills the same criteria as X, yet in addition is also usable for serious things. It's just that sometimes you have to look a little harder for it. In other words, I think it is a teacher's categorical responsibility to find a means to teach what they want in a way that is practically applicable by the students right away. And failing to do so should be taken as a strong hint that what they want to teach may not be the thing they should teach. I wouldn't say this if I didn't firmly believe that you can teach most things in a way that grants the student immediate practical applications. And I don't say this in a political way -- of course everyone should have the liberty to teach whatever useless thing they want in whatever shitty manner they cn come up with. I'm viewing it more as requirements on any teacher who wants to call themselves good, or tell themselves they are doing their students a service and improving mankind.
- elihu 9y ago> Forsaking C means forsaking anything below the level of abstraction at which one happens to currently work. This is mostly true today, but I hope that over time we'll see more languages fill the gap between hardware and high-level languages. There's no fundamental reason why that middle layer has to be in C, we just have had a shortage of viable alternatives.
- inetknght 9y agoIf you truly believe that then I think it's time for you to go learn about some new languages. C++, Go, Rust... these are very viable alternatives to C.
- notriddle 9y agoC++ and Rust, yes, but not Go. Go is a lot closer to Java than it is to C++, since its growable stacks and garbage collector require marshaling overhead to call out to languages that don't know about them.
- asveikau 9y agoHmm, I thought a growable stack via a guard page that allocates more stack on a fault was common in C-based languages. (Though this would be an OS feature rather than a language one.) I routinely put very large buffers on stacks in C and C++ and don't generally run into problems unless I accidentally do infinite recursion.
- Rusky 9y ago> I thought a growable stack via a guard page that allocates more stack on a fault was common in C-based languages. It is, but that's not how Go's growable stack works. Go's is grown by the language runtime and relocated when necessary, using its GC infrastructure, so you really can't put non-Go stack frames on it.
- pcwalton 9y agoThere's no shortage of viable alternatives. C++ is significantly more popular than C these days, and the gap widens every year.
- tempodox 9y ago> There isn’t even a cute C animal in C’s non-logo on a C decal not stuck to your laptop. At least there is a cute image presenting “The C Programming Language” in the context of Plan 9: http://9front.org/img/000000wq9nh.png http://9front.org/img/000000wq9nh.png
- sotojuan 9y agoI guess Cirno counts, her name starts with C!
- kqr 9y agoI feel like this article makes two strong arguments in favour of C: 1. You need to know C because C is popular, and 2. You need to know C because C is a lowish-level language. I can't very well argue with the first point -- indeed, nearly everything fundamental is made in C or the C-like subset of C++ still -- but I oppose myself to the second. I do think you should learn a lowish-level language, but there are good reasons to make that language something like Ada instead; something high-level enough to have concurrency primitives yet low-level enough to force you to consider the expected ranges of your integers and whether or not you want logical conjuctions to be short-circuiting. Something high-level enough to have RAII managed generic types, yet low-level enough to let you manipulate the bit layout of your records. High-level enough to have exceptions and a good module system for programming in the large yet low level enough to have a built in fixpoint type and access to machine code operations. Unless you target C specifically for its popularity, there are other options out there, filling the same gap.
- Avshalom 9y ago>>Ada instead; something high-level enough to have concurrency primitives yet low-level enough to force you to consider the expected ranges of your integers In practice Ada programmers, because they actually have a proper method of expressing integer ranges, are going to be much more considerate of such things.
- tomcam 9y agoYour argument is compelling and crystallized similar thoughts I’ve had. If I ran a CS department I’d follow your recommendations. Practically speaking though another argument against Ada or whatever is drastically reduced reading options.
- krinchan 9y agoI still can point to the exact point in my college career that took me to a whole new level of understanding how to program in Java or Python to understanding how things like Garbage Collection, Threads, and other abstractions actually worked. It was an elective I took on Graphics Programming and it was all in C and OpenGL. Being without GC, I learned the trade offs. Obviously, being able to explicitly allocate and free memory was a big deal. But at the same time, I learned to appreciate the complexity and pitfalls of GC. Threads are great in Java (as are their parallels in other languages): this is the work to do, put the results here, and everything is cleaned up. Meanwhile, just trying to get the results back from a forked process was CRAZY. Implementing and managing my own shared memory to pass messages back and forth...wtfbbq. "Think like a computer," not really. More like, "understand what all goes into a thread, an async call, or a garbage collector. Gain more understanding into the corner cases and exactly how much this thing is doing for you. So maybe setting something to null or pre-allocating objects to reduce heap work isn't that big a deal." C taught me to be patient with higher level languages, to better understand what they were doing for me, be able to reason about how they may be doing these things wrong, and to think critically about how to coax these features into behaving the way I want them to. Really any lower level language can teach these things. The point here is that C is a nearly universal language that can teach you to reason about these things.
- fellellor 9y agoMost of the C language texts that I have come across just seem to teach how to use the language, say pointers etc. Maybe there is something about how to use make. I've found it hard to go from there to link up with the more abstract stuff. Not so with python, because the mental energy I spend reading python code is very little, which enables me to move very fast. Reading sklearn source has been a revelation to me. I can't imagine having to read a similar high level equivalent in C.
- seaurchin 9y agoThis is a really fun (and relatively short) c programming book: https://www.amazon.com/Expert-C-Programming-Deep-Secrets-ebook/dp/B00E0LASCU/ https://www.amazon.com/Expert-C-Programming-Deep-Secrets-ebo...
- nallerooth 9y agoThis book is really good, and I'd say that a couple of weeks after reading K&R - you should read this one (given that you fiddle with C during those weeks).
- x0re4x 9y agoI've heard C language was designed with the idea that the programmer knows what he is doing and the programming language shall not be standing in his way. For me the cost of forsaking C would be not to experience 100% programming freedom/power (which comes with 100% responsibility). And yes, C also gives you the freedom to do any nonsense :) I was always fascinated how little resources are needed to run C programs, here an example (not by me): https://github.com/barteksalsa/avr-tiny12-disco/blob/master/leds.c https://github.com/barteksalsa/avr-tiny12-disco/blob/master/... ATTiny12 mikrocontroller with: 1 KiB program flash rom, 32 bytes of "ram", 3 level hardware stack
- loudmax 9y agoThis is analogous to Unix commands assuming you meant what you said. 'rm /bin/bash' Ok boss, no questions, no confirmation prompt, done. One of the first things I do on a new Unix login is alias the rm, cp and mv commands to -i so they prompt before clobbering files. I spend a lot of my day at a command prompt, but I like my guardrails.
- x0re4x 9y ago... and just like aliasing commands you can place your own guardrails in C programs at places where you consider them necessary. P.S.: alias the rm, cp and mv - that I do too, I think everyone had his 'rm -rf $stuff' moment (-_-)
- joezydeco 9y agoThe infamous quote goes "The C language combines all the power of assembly language with all the ease-of-use of assembly language."
- x0re4x 9y agoDo you have a specific example? I wrote programs in Z80, AVR, x86/amd64 and MIPS assembly. In my experience writing C is MUCH easier.
- 9y ago
- smadge 9y agoLearn basic digital circuits. Learn an assembly language. Learn C. Implement a simple interpreted language. You don't have to reinvent every level of the stack and connect it all together(your imagination can fill in the gaps), but this removes the mystery of computing.
- karmakaze 9y agoTL;DR We give students four reasons for learning C: 1. It is still one of the most commonly used languages outside of the Bay Area web/mobile startup echo chamber; 2. C’s influence can be seen in many modern languages; 3. C helps you think like a computer; and, 4. Most tools for writing software are written in C (or C++) [Not really TL, but good context for reading comments referencing the numbers]
- SAI_Peregrinus 9y ago> Forsaking C means forsaking anything below the level of abstraction at which one happens to currently work. That's trivially true. Pick anything as your bottom abstraction layer, you can almost certainly find something below. Unless you're working on the foundations of mathematics or trying to come up with theories of quantum gravity you haven't hit the bottom of the abstractions. It's also not as though C is the bottom layer even for programming. There's assembly. Then HDLs like Verilog or VHDL. Then electrical engineering... You have to stop somewhere. My knowledge spans from some electrical engineering through C up to Python/Java/Lisp levels, but I don't (currently) know much of anything about Javascript or actual semiconductor engineering or more than basic physics... C is pretty good as a foundation for programmers. It's terrible as a foundation for computer engineers, and it's pretty much at or above the ceiling for what's expected of electrical engineers. It's not guaranteed to remain a good foundation for programmers. Massively parallel architectures like GPUs don't tend to fit well into C's abstract machine model.
- auvrw 9y agofor rubyists and pythonistas interested in writing more C while not losing the convenience of scripting, lua is probably worth picking up along the way. the following is the C-interop samples from Programming in Lua https://github.com/ransomw/exercises/tree/master/lleaves/plusc https://github.com/ransomw/exercises/tree/master/lleaves/plu... ... only gripe with this article is the couple of "... and/or C++" clauses: i personally hope to be forgiven for forsaking C++ for new projects, because it is not the 1970's anymore, and i suppose there are alternatives for almost every use case as well as externs for plain-C interop with existing C++ libs. it's more like C+{100} so many are the additional feature-ughs.
- fractallyte 9y agoNo mention of Forth? Small, close to the metal, easier than C, and just as capable. But it's from that alternative universe of computing (also inhabited by Lisp and Smalltalk). A couple of well-known articles/discussions about that universe: A Forth Story: https://news.ycombinator.com/item?id=3813966 https://news.ycombinator.com/item?id=3813966 Lisping at JPL: https://news.ycombinator.com/item?id=7989328 https://news.ycombinator.com/item?id=7989328
- purplezooey 9y agoC is like English. You know it without having to grab a book. It just flows out of you naturally.
- flavio81 9y agohow can one of the languages with the most tricky syntax to parse "flow naturally"? and I say this as somebody proficient in C.
- GoToRO 9y agoAbout not being updated: there are linters, and if you impose a rule that you can only check in code that passed the linter, then essentially you are writing a newer, better version of C.