20 ms·
The cost of forsaking C
- musha68k 10y agoNobody is "forsaking" C. As mentioned in the article it is still a good way to learn about computers and it's the true "lingua franca" of our times - that said it needs to be put to rest for infrastructure software now. I for one welcome our new Rust writing overlords.
- AstralStorm 10y agoTo an extent, so does C++ help think like the machine, but you can skip a lot of syntactic red tape. Until you get to advanced uses of templates. It is also useful in order to show how those "smart" things in higher level languages work, using standard library as examples.
- anta40 10y ago>> Learning about operating systems would be much harder without C. The operating systems that we use are mostly written in C, the C standard library is tightly coupled to the syscall interface, and most resources dealing with operating systems concepts assume knowledge of C. I wonder what if Kernighan, Ritchie et all decided to write UNIX in Pascal, not in C. Hmmm.... :D
- unwind 10y agoI don't think that was ever very likely, it kind of seems like Mr Kernighan didn't like Pascal: https://www.lysator.liu.se/c/bwk-on-pascal.html https://www.lysator.liu.se/c/bwk-on-pascal.html. I'm not at all clear about the detailed timeline, but this link is a pretty good answer to that thought. :)
- pjmlp 10y agoOn that famous rant he selectively chosed to ignore all Pascal dialects that offered the features he complained about, while at the same time ignoring that outside UNIX there weren't full C compilers available, rather dialects.
- kabdib 10y agoPascal. Dialects. That was the problem. Pascal was designed as a teaching language, then people realized it sucked as a language in the real world, so they extended it. There were quite a few Pascal variants in the late 70s / early 80s, and none of the useful code you could write in them was portable. C had all the features you needed in an OS-level language, without resorting to variants (the X86 near/far bullshit notwithstanding, you used macros and typedefs to shift that stuff around). So Pascal more or less died in the industry. I was at Apple when they converted from a Pascal shop to a C shop. There wasn't any big managerial push, just individual engineers or small teams realizing that the nightmare was over and they could use a language that sucked a lot less.
- pjmlp 10y agoHowever I remember the chore that was writing portable C code when you could not rely what compiler was available, specially outside UNIX. For those of us in MS-DOS and Windows, only Turbo Pascal mattered, to the point it was more relevant to be TP compatible than supporting ISO Extended Pascal, which also sorted out most of the complaints. Complainants which were nonexistent in Modula-2 anyway. The industry choose the easy path, now we all pay with our mainstream OSes built on top of a quicksand language.
- Roboprog 10y agoIt's a shame Modula wasn't available until the early 80s (as far as I know), but unfortunately, you are right. C is vastly preferable to writing assembler on multiple platforms, though. The real tragedy is IT Managment(TM), which insisted on C++, and after that inevitably failed (for most things outside of video games), insisted on Java due to all the core dumping craziness. Can't find the original source doc, but here goes: https://blog.acolyer.org/2016/09/07/the-emperors-old-clothes/ https://blog.acolyer.org/2016/09/07/the-emperors-old-clothes... At least K&R took quicksort(), even if they didn't take the array subscript bounds checking part (etc) to heart.
- Roboprog 10y agoOne other C inspired tragedy: WHY, OH WHY, did they insist on putting identifier names AFTER (most of) the type information??? Algol had it right, why screw it up? I guess it doesn't matter if your (optional) type is word^H^H^H^H int, but this has descended into chaos in Java land.
- MaysonL 10y agoOr if Wirth had had the marketing nous to call Modula Pascal+ and Oberon Pascal++.
- pdw 10y agoThere was TUNIS in the early 80s, an operating system binary compatible with V7 Unix and implemented in a Pascal-like language. I've been meaning to find more information on it, but there's almost nothing online. It might be the only Unix clone that isn't implemented in C/C++.
- anta40 10y agoThat's why I think UNIX was a very good marketing vehicle for C. In the 1970s, universities began to adopt C. Since UNIX was written in C, academists/students began to learn C, and that was how the rise of C, now known as "the lingua franca of computing", started. Personally, one valid reason for me to learn C today is to understand/hack stuffs written in it. A fine example is the Linux kernel. I still don't get the "C is close to machine" mantra. If you want to understand the machine, why don't just learn assembly instead? :D
- joezydeco 10y agoIn my experience, assembly makes you do a lot of busywork over and over to achieve certain constructs. Loops and function calls come to mind immediately. They're not hard things to do in assembly, but you'll need to write those every single time you need one. So then you start making macros to handle this for you. By that point the conceptual leap to C isn't very far.
- pjmlp 10y agoThey would have re-invented, Burroughs OSes from 1960's and made computing a safer world. :)
- jimjimjim 10y agoif anything c is more popular now than 5-10 years ago. not c++ but normal c. especially with the pendulum swing away from oo it's almost an ideal hipster language.
- sidlls 10y agoUgh, that's the last thing I want to see. I didn't start diving into Rust until very recently for two reasons: 1) the instability of the language and 2) the terrible, juvenile hatred for C and C++ that seems to almost be a pre-requisite for participation in the ecosystem. Rust until recently was an anti-C hipster's wet dream ("upstart"-y, not really yet ready for wide-spread use, and a convenient goto for folks wanting to have a bit of trendy "bash C (or C++)" fun. Both items have diminished considerably lately, though, and that's something I can appreciate.
- Manishearth 10y ago> the terrible, juvenile hatred for C and C++ I'm surprised (and sorry) to hear that. The Rust community tries very hard to avoid language zealotry. If you see it on any of the Rust forums (can't speak for other sites), please report it. I've seen lots of well-reasoned complaining about UB and other issues that C/++ are prone to, but not much juvenile hatred.
- pjmlp 10y agoI hate C since 1992. By now juvenile is something I surely am not.
- Manishearth 10y agoTLDR: Goto last line of this comment > It is still one of the most commonly used languages outside of the Bay Area web/mobile startup echo chamber; Fair. > C’s influence can be seen in many modern languages; Saying that that's a reason to learn C is a non sequitur. Why? > C helps you think like a computer; and, So does C++. And Rust. And D. All the stuff about databases can be done in any of these languages, C doesn't have a monopoly over letting you be close to the metal. It's one of the only languages that pretty much forces you to be close to the metal, but that's not a plus point. > Most tools for writing software are written in C (or C++) True. Hacking on your tools is great. But hacking on your tools rarely requires proficiency in a language (unless you're doing something major, which you're not), I've hacked on tools written in all kinds of languages that I don't know. And the justification behind this point follows the same flimsy reasoning as the previous one, the reasoning that C is the only low level language out there. The post gives "browsers, operating systems and languages" as examples, but all three of these exist in Rust (Servo, redox/intermezzos/a bunch more, and rustc). I'm sure that D is up to the task for such software too, if it doesn't have them already. C++ of course has all of these. Sure, you need to know some C when doing low level programming and/or FFI. But nobody's arguing against that. "Everyone “has been meaning to” learn Rust or Go or Clojure over a weekend, not C." is a false dichotomy. With Rust for example it's pretty easy to learn enough C to manage once you've learned Rust (there are tons of folks in the Rust community who have done this). You're not forsaking C, you're just focusing on something better. You can learn enough C to be able to read code and do FFI, and you're pretty much set for writing databases or operating systems or networking stacks or whatever. Reading C isn't too hard and if you speak another low level programming language you can pick this up over a weekend. The only valid argument I see here is that C is is still used a lot in existing codebases, and you should be proficient if you want to be able to contribute significantly to them. Of course. But cut all the crap about C being the only language that can handle these use cases.
- kibwen 10y ago> The post gives "browsers, operating systems and > languages" as examples Actually, I can't think of any browsers that are written in C. Unless, wait, does Lynx count? :)
- adrianN 10y agoIsn't K&R's book littered with code examples that were canonical in the 80's but have glaring security holes? I wonder whether it's a good idea to have students work through "the bible". Hopefully they provide extensive exegesis in the lectures.
- aisofteng 10y agoIntroductory programming language texts do not concern themselves with "security holes" usually. This is a strange criticism.
- Manishearth 10y agoSure they do. To clarify, GP here is probably talking about UB security holes, not stuff like XSS. Most intro texts I've seen have "watch out!" notes all over the place.
- adrianN 10y agoTeaching C without teaching buffer overflows and undefined behavior is reckless.
- taneq 10y ago> I wonder whether it's a good idea to have students work through "the bible". That's probably a pretty good analogy - it's useful maybe for historical value, but it has to be understood that some of what's listed is no longer best practice and you can't, for instance, go around stoning adulterers and amputating thieves' hands.
- pjc50 10y agoNeither K&R nor K&P include any network-facing or security-boundary-crossing code, if I remember rightly.
- MrBuddyCasino 10y ago> C helps you think like a computer I recently bought K&R, doing a bit of micro-controller stuff without the Arduino abstractions, and this I can agree with. I now have an idea how code really gets executed on a CPU, and how the contract between the bare metal and the assembler code for doing so looks like. That the concept of a stack is built into x86, and why calling conventions are important, all of this stuff I had no idea doing Java development for all these years. What do I need a linker for? Object files, what? I don't really like it, but there is something strangely beautiful about it - if you look hard enough, you can see the machine shining through the unforgiving cold blue ice that is C.
- leppr 10y ago>calling conventions are important Curious what you mean by that, in what way learning C made you understand this better than Java or any other language did?
- MrBuddyCasino 10y agoAs mentioned, I don't particularly like C, so I've explored Rust a bit. I tried to expose a Rust function to C, heres the signature: #[no_mangle] pub extern "C" fn count_substrings(value: *const c_char, substr: *const c_char) -> i32 So I came at it from the opposite direction, and once you go down the rabbit hole of what "no_mangle" and "extern C" does, thats where it leads you. Along the way you inevitably pick up topics like alignment and struct packing.
- pjmlp 10y agoI had the same experience with low level machine control using compilers for dialects of Basic and Pascal, back in the mid-80's early 90's.
- rvense 10y agoIt's hard to over-estimate the historical importance of C, and the amount of groundbreaking work and important knowledge codified in C codebases. Also, it can't be denied that there will always be areas where the exact control of memory layout that C gives you is not just nice-to-have for performance reasons, but a prerequisite for a good implementation or understanding of some algorithm. Neither of those points, however, mean that C is the only suitable language imaginable for doing low-level work, or that the past forty years of programming language research are irrelevant to the spaces that C excels in. I think Rust shows quite succintly the immense value of the combination of an expressive type system and C-like zero-overhead abstractions. Learning C, like learning some assembly languages, to some extent is probably necessary if you're serious about understanding computers, just to understand what's going on. But when it comes to actual use in production systems, I am glad that we are seeing serious alternatives to a language so prone to simple bugs as C. Think of all the time and money that have been lost to buffer overflows and segmentation faults.
- bluetomcat 10y agoThe huge advantage of C (before the advent of LLVM) was that it was relatively straightforward to write a C compiler for any exotic or not-so-exotic system, since the language has very simple semantics and many operations would correspond to single machine instructions. There are literally hundreds of production C compilers written to this day. The syntax of the language is also designed to help the compiler writer and not the user – think of "declarations mirror use", the irrelevance of the order of type specifiers, etc.
- kevinnk 10y ago> The syntax of the language is also designed to help the compiler writer and not the user – think of "declarations mirror use", the irrelevance of the order of type specifiers, etc. Err, I would agree with the statement that the syntax of C (mostly) favors the compiler writer, but "declarations mirror use" is decidedly not a good example for a couple of reasons: 1. The grammar for type declarations is actually quite complicated[1] 2. Agol, which inspired C's type system, actually had a much more "compiler friendly" type syntax[2]. C's syntax is designed to be more programmer friendly. 3. Dennis Ritchie makes it pretty clear that "declarations mirror use" was intended to make use and declarations visually similar, which implies that it was done for the benefit for the programmer[3]. [1] Compare https://www.lysator.liu.se/c/ANSI-C-grammar-y.html https://www.lysator.liu.se/c/ANSI-C-grammar-y.html to [2]. [2] http://www.csci.csusb.edu/dick/samples/algol60.syntax.html#5.%20Declarations http://www.csci.csusb.edu/dick/samples/algol60.syntax.html#5... [3] "Analogical reasoning led to a declaration syntax for names mirroring that of the expression syntax in which the names typically appear...In all these cases the declaration of a variable resembles its usage in an expression whose type is the one named at the head of the declaration." from http://www.jslint.com/chistory.html http://www.jslint.com/chistory.html
- justinlardinois 10y ago> 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. This is an odd argument. C has hardly changed or evolved since 1988, so there's not really a need for a new edition.
- vu3rdd 10y agoThe essence of the language has not changed. But C99 came out with a few nice things. There is also C11 which brought in a few new things as well. It would have been nice to bring the book up to C99. "Modern C" is a good book on some of the new features. http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf
- justinlardinois 10y agoAfter reading up on C99 I take back what I said. I definitely thought some of those features were older than they are.
- kensai 10y agoAlthough there is little need for C to evolve (apart from certain security holes), I think there is space. Thankfully, there are still persons that care about its evolution. The K&R is a classic, but it shows its age, especially as we have reached C11 by now. And C2x might be right around the corner. A third edition of the book won't be that bad. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2021.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2021.htm
- sohkamyung 10y agoThere are other books on C besides K&R. My current reference is C: A Reference Manual, Fifth Edition [1], which I usually pull out when I need to check on syntax and standard libraries. - http://careferencemanual.com/ http://careferencemanual.com/
- mankash666 10y agoQuick question: would the c loving crowd like an AWS lambda type offering supporting coding in C? You know, to quickly supplement your embedded projects with some intelligence and data processing on the server side, without having to learn a new language or fussing with server infrastructure and scaling
- PaulRobinson 10y agoGetting serverless PAYG patterns working in any language is going to be useful. Thing is, this exists. It's AWS Lambda. It allows running of arbitrary executables in the sandbox: https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/ https://aws.amazon.com/blogs/compute/running-executables-in-...
- mankash666 10y agoWhat you mention has more overhead that being able to directly run in the main process. Though, I don't know if it's noticeable for most use cases, especially given how fast processors are today
- conjectures 10y agoWhile K&R is a nice book, it's really not sufficient to become productive with C. IIRC it doesn't cover things like make, valgrind and libraries. There's a book 21st Century C which does the job of addressing that.
- Roboprog 10y agoI ended up with a book, back in the late 80s, called (I think) "C, An Advanced Introduction". To me, the K&R book was just too "circular", as the authors were too close to the subject.
- ninjakeyboard 10y agoContrast with http://chrisdone.com/posts/dijkstra-haskell-java http://chrisdone.com/posts/dijkstra-haskell-java
- tempodox 10y agoVery good reading, including the two links after the transcript. I feel that both the OP and Dijkstra are right in their own respective way. I do hope that Rust, for one, will turn out to be part of a path to better practise.
- jorangreef 10y ago"Early in the morning he [Jesus] came again to the temple. All the people came to him, and he sat down and taught them. The scribes and the Pharisees brought a woman who had been caught in adultery, and placing her in the midst they said to him, “Teacher, this woman has been caught in the act of adultery. Now in the Law, Moses commanded us to stone such women. So what do you say?” This they said to test him, that they might have some charge to bring against him. Jesus bent down and wrote with his finger on the ground. And as they continued to ask him, he stood up and said to them, “Let him who is without sin among you be the first to throw a stone at her.” And once more he bent down and wrote on the ground. But when they heard it, they went away one by one, beginning with the older ones, and Jesus was left alone with the woman standing before him. Jesus stood up and said to her, “Woman, where are they? Has no one condemned you?” She said, “No one, Lord.” And Jesus said, “Neither do I condemn you; go, and from now on sin no more.” The Bible is useful certainly not just for historical value, but for making you wise for salvation. The Bible is God's master plan for forgiving you, and restoring you to friendship with himself, through Jesus' suffering, death and resurrection explicitly on your behalf. "Believing" in Jesus is not believing whether he exists, or whether God exists. "Believing" in Jesus means not claiming to be without sin, but rather acknowledging your sin, and trusting Jesus' work on the cross alone to save you from it.
- jasonkostempski 10y agoIf you believe it's god's master plan how do you choose weather to stone adulterers or not stone adulterers? It says you should do both. I'm hoping your answer will help me choose where to put my open braces.
- duncan_bayne 10y agoUnfortunately, Islam has an answer to this sort of question - the doctrine of abrogation. Basically, all conflicts are to be resolved in favour of the latest version. I say unfortunately because this gives precedence to the Medina verses, which are marked by cruelty and violence.
- sctb 10y agoWe detached this subthread from https://news.ycombinator.com/item?id=12642207 https://news.ycombinator.com/item?id=12642207 and marked it off-topic.
- noelwelsh 10y agoI agree John Regher's take on teaching C: http://blog.regehr.org/archives/1393 http://blog.regehr.org/archives/1393 In summary, it's a useful skill to have but you're not doing your duty as an instructor if you don't make your students aware of its many shortcomings. I particularly want to take issue with the claim in the original post that "C helps you think like a computer". C's machine model might have been a good model for the machines at the time at which it was developed, but it hasn't been an accurate model for a long time. A simple example is C's assumption that memory is flat and all locations have an address. With multiple layers of caching and nearly a couple hundred registers in current CPUs this is far from the truth. If you think programming in C is programming at the machine level you are deluding yourself.
- m_mueller 10y agostill better to have some concept on how memory works though, even if it's still an abstracted version of what happens on the machine. If all you ever see is Java or Python, the mental step to understanding memory optimization and caching becomes much larger.
- bluetomcat 10y ago> With multiple layers of caching and nearly a couple hundred registers in current CPUs this is far from the truth. Add to that the aggressive optimisations performed by modern compilers and that mental model breaks completely. It may be a good conceptual model, but it's not the model under which your program actually executes. However, even programming in assembly keeps you very "far from the truth", since modern CPUs are very complex beasts internally and that complexity is mostly not visible in the ISA.
- sigjuice 10y agoYup. Caches, prefetching, NUMA, out-of-order execution, speculative execution etc.
- planteen 10y agoThe thing about speculative execution and out of order execution to remember is that you always get the expected result from a single threaded perspective. If you throw in interrupts or threads, you know you must tread cautiously in C. Few things have made me more nervous in my career than seeing a ISR making use of C++ standard library features. When I asked the engineer how they were sure this was safe and worked under the covers, I was immediately dismissed as "the compiler takes care of all that." The project only ever worked at -O0 and was still buggy. The engineer blamed the hardware.
- fauigerzigerk 10y agoC has one quality that no other language has. You can write libraries in it that can easily be used from all other languages on every platform.
- pjmlp 10y agoThat is only true if the OS was written in C. What many wrongly call the C ABI is actually the OS ABI.
- fauigerzigerk 10y agoThe ABI is certainly helpful, but I don't think it's the only reason why C libraries are easier to call than libraries written in other languages. C doesn't have generics, inheritance or a GC, all of which make integration a lot more difficult.
- pjmlp 10y agoA set of features shared by many other, safer, system programming languages. Their OSes didn't had a C ABI, rather an ESPOL, NEWP, Modula, and so forth ABI.
- fauigerzigerk 10y agoSure, theoretically there could be viable alternatives to C.
- pjmlp 10y agoWhat makes many of us sour, is that it isn't theory, rather already proven in the past, back when C was only a UNIX language and barely relevant outside it. It was the commoditization of UNIX in the industry that pushed C outside UNIX, just like we nowadays have JavaScript outside the browser.
- 10y ago
- Nursie 10y agoAh, C, the love of my life... Want minimal syntactic sugar and a language that's not prone to feature-of-the-week hipsterism? C Want to make tiny binaries for some obscure system with virtually no storage or RAM? C. Want to know where every last cycle goes and explicitly control everything? C Want to trivially import any of the huge array of existing libraries? You guessed it... Want to do something you really shouldn't, and any 'sensible' language might attempt to stop, but is called for right here and now... It's not the safest language, it's not the most expressive, but the syntax is small enough to hold in your head and the body of existing, available work is HUGE. I've been working in C for 15 years and, while I enjoy forays into other languages, it will always be my love.
- jbb555 10y agoAgree entirely with all this. You know what you get with C and it just works as you expect always. I always feel refreshed after writing C. There are perhaps a few very minor enhancements I'd suggest, but I'd be very reluctant to open the floodgates and ruin it.
- zigzigzag 10y agoIt always works as you expect? Really? C is one of the few languages, along with C++, that revels in undefined behaviour. It can be very hard to reliably know what a C program will do if it's not written very carefully because there are so many constructs that look benign but which are technically wrong, and the compiler will mercilessly exploit in order to optimise your program into nonsense.
- deagler 10y agoThis, While C and C++ are both very powerful languages and could still be considered the "industry standard"(loosely used) It is definitely not a language that will make your applications work as expected, I would say that C#/Java or higher level scripting languages like Lua or Javascript are languages that will let you make "code it and it works" applications
- sargun 10y agoSo, I quite like C. I don't use it very often, but I think that it's like a sharp knife. I don't quite see the point of C++ though. Can someone explain me why we should continue to bow into it?
- adrianN 10y agohttp://programmers.stackexchange.com/questions/29109/is-there-any-reason-to-use-c-instead-of-c-perl-python-etc http://programmers.stackexchange.com/questions/29109/is-ther...
- johannes1234321 10y agoThe really short summary is that C++ provides abstractions, which allow to write more complex code simpler while many of those can be eliminated by the compiler leaving no runtime overhead. Sure there are things (i.e. virtual classes) which cause an runtime overhead, but even when doing the same thing in C you'd need similar logic to what the C++ compiler produces for you.
- fredsanford 10y agoIf you're interested in modern C++... https://www.youtube.com/watch?v=zBkNBP00wJE https://www.youtube.com/watch?v=zBkNBP00wJE
- RossBencina 10y agoIf you want a C-level sharp knife, and you want to work with abstraction (not just OO and abstract data types, but also generics and metaprogramming), then C++ is one of the few choices. D is maybe another option (if you can live with GC). Maybe in the future also Rust, but my impression is that the Rust generics and metaprogramming story is not quite there yet. C++ is mature, so it's a safe choice in that respect: large installed base, ISO standardised, mature tooling with multiple vendors. If you don't need the C-level sharp knife, then there are a lot of options -- and a lot of reasons to choose them over C or C++. Personally, I value that C++ is multi-paradigm (I can use classes when they are a good fit, generics when they are a good fit, asm when it's a good fit, etc.), also: trivial interop with C and assembler, no GC, runs directly on the metal. These are reasons to use C++, but not necessarily reasons to "continue to bow into it." Did I mention generics and metaprogramming? Even if you don't use these directly, their availability makes for flexible and powerful libraries. The STL container library is the obvious example, but modern C++ metaprogramming goes way beyond that.[0] [0] For example, see Hana: CppCon 2015: https://www.youtube.com/watch?v=cg1wOINjV9U https://www.youtube.com/watch?v=cg1wOINjV9U https://github.com/boostorg/hana https://github.com/boostorg/hana
- delegate 10y agoThe author uses C and C++ interchangeably, but these are two distinct languages. Although technically a superset of C, C++ has constructs and paradigms which make you think in totally different ways. In fact C++ introduces many language features which (should) protect programmers from 'C' mistakes in their C++ code. For example, in modern C++ you shouldn't manage memory directly, but use smart pointers and containers. You can, but you shouldn't. And there are dozens of such recommendations. Which is the right approach, imho. You can still do the low-level dangerous stuff if you feel brave, but officially you should stick to the 'safe' paradigms that the language now offers. However, the paradigms that C enforces on you are the paradigms of how to do things fast. You wear no protection so you are much more nimble, but much more vulnerable at the same time. Which is good for some types of projects, but not for all.
- palunon 10y agoC++ is not even technically a superset of C... `auto` has very different meanings in both languages, and you can't omit the return type of an int-returning function in C++
- david-given 10y agoHave you ever tried to compile an old C program which extensively used variables called 'old' and 'new' with a C++ compiler? I have. Also, C++ doesn't allow implicit casts from void* to any pointer type, which is a common C idiom.
- deleted 10y ago[deleted]
- kbart 10y ago"The author uses C and C++ interchangeably, but these are two distinct languages" Sure they are. C/C++ are often cobbled together in a sense that they are both low level, non-memory safe and non-type safe languages, as opposite to high level, safe, memory managed (aka "modern") languages.
- 10y ago
- Marazan 10y agoC helps you think like a certain 1970's abstraction of a computer. I really hate the "C is how a computer really works" argument in favour of learning C.
- Rusky 10y agoThat 1970s abstraction is certainly closer to modern computers than any higher level language, and is quite a nice introductory route to learning more accurate models. We still start with the Bohr model in chemistry for the same reasons.
- bryanlarsen 10y agoDo you teach assembly language too? It's a lot better at #3 (teaching you to think like a computer) than C is, and it makes it a lot easier to fully grok C concepts like the strange equivalence between pointers and arrays, between character arrays and strings, et cetera. C is trivially easy to learn if you know Assembly Language plus any other imperative language. My school taught assembly language as a full semester course (along with other low level concepts). That and an intro to computers course that used either Pascal or Fortran were requirements for the 200/300 level courses on operating systems etc. that used C but didn't actually teach it. They made seminars available for those who wanted to be taught C rather than having to learn it themselves. I believe that this is the right approach. Of course, soon after I went through they fell victim to the hype wagon and switched to Java.
- varjag 10y agoFrom TFA: > Most engineers should take head of reason three, although our students also learn computer architecture and at least one assembly language, so have a firm mental model of how computers actually compute.
- bryanlarsen 10y agoThanks, I missed that. Do they learn assembly language before or after they learn C? Are they explicitly taught C or do they learn it while using it in a course like Operating Systems or Data Structures?
- partycoder 10y agoAda and Pascal are not dead and are viable alternatives to C. If you don't know them, check them out. The C philosophy "the programmer knows what they're doing" does not necessarily scale. It works when your team is strong or well supervised, but if that is not the case due to location, budget or whatever reason, unless you can afford a static analysis tool like Klocwork that can weed out mistakes while not sacrificing productivity, by going low level you have picked a hard battle. C gives you a lot of power, but also a lot of rope to hang yourself with. I don't even want to imagine what kind of apocalypse I would see if you give multithreading and memory management powers to the caliber of people I've seen recently.
- dreta 10y agoThere’s a lot of problems with C, like the fact you have to break out of case statements, or string concatenation, or overuse of the static keyword. These are actual problems, which C++ doesn’t even begin to try and solve, instead introducing useless features and bloat. C is still one of the few popular languages that allows you to talk to the machine directly. It’s a language that doesn’t rely on hidden run-time logic, or hidden implementation costs. It doesn’t enforce any particular programming style on you, and lets you do anything a process is capable of doing. Software engineers these days are so lost in abstractions and design patterns that they forget that at the end of the day a program is just data, and a set of operations that transform that data. There’s huge value in writing code that does everything explicitly from top to bottom, both from a readability, and from a debugability standpoint. Instead, these days, software is designed using UML diagrams and OOP concepts while pretending that objects are ideas that float in some abstract disconnected space. All in the name of concepts envisioned by people who write books instead of programming, and who never saw even a glimpse of a problem you’re trying to solve. Languages like C will never become obsolete. There’s always a new frontier of hardware that needs fast, tailored software. Few years ago that was phones, and watches, next it might be tiny implants. Anybody who thinks languages like C is obsolete should ask themselves “why was my Comodore64 more responsive than a PC i bought in 2016?”, or "why is my dual-core Android smartphone with 1GB of RAM barely usable after a year”. Modern languages and programming practices have this amazing ability to completely negate the massive progress hardware has made.
- Avshalom 10y ago>>Few years ago that was phones, ObjC and Java >>Anybody who thinks languages like C is obsolete should ask themselves “why was my Comodore64 Assembly and Basic.
- mikejmoffitt 10y agoSurely Basic is not responsible for the Commodore being responsive. Java was a total dog on phones for a long time, too.
- 10y ago
- drvdevd 10y agoSo I dropped out of college long ago and it is actually so ironic and yet also refreshing to me to hear this viewpoint from a college professor. What a beautifully explained rationale for a subject that I find so hard to articulate to my colleages in our echo chamber. I'll definitely be pointing to this in the future.
- quantum_state 10y agoBesides the reasons already listed, one more is C can be used to program almost all of the micro controllers, an essential electronic element in modern life.
- tdb7893 10y agoWith GHz level processors getting so cheap and developer time being so expensive, I wonder if that will always be the case. I've recently moved from using microcontrollers and C to using raspberry pi and beaglebone with python and it's made my hobby projects more pleasant. I'm curious about whether I'm going to run into issues later, though.
- ArkyBeagle 10y agoIt'll always be the case because of size-weight-power constraints. I have a project on right now where we need it to run on a CR2032 style coin cell for year or two. The OO nature of Python can also get in the way of certain things.
- pjmlp 10y agoThere are also Basic, Pascal, Ada and Oberon compilers available for such processors.
- kabdib 10y agoIs C really this disparaged in Silly Valley?
- alfalfasprout 10y agoYes. Keep in mind the vast majority of people on HN only work on end-user software (native and web apps). Yes, there are much better choices for the web when you need security, etc. In certain enterprise applications C are still the best choice. In finance, where I work, C and C++ still reign supreme. Why? There's already a huge multitude of great libraries developed over decades that are mature and battle-tested. Sure, you can write bindings for Rust/Go/D/whatever. But that's a ton of work for minimal benefit. Fact is, when you get on a plane the avionics software was likely written in C. NASA extensively uses C. The automotive industry extensively uses C. Oh, and a lot of this C is embedded so forget easy software updates. I think a lot of the hate for C comes from the fact that it lets you do bad things without alerting you. C is a language that mandates solid engineering practices. A good C codebase can be elegant, correct, and fully testable. The language doesn't force this, however. But a nice, well written C library will stand the test of time.
- kabdib 10y agoPretty much what I thought. (I've been programming C since 1979, and C++ since 1987, but left Silly Valley 15 years ago).
- Animats 10y agoThe industry took a giant step backwards when C displaced Pascal. The original Macintosh apps were in Pascal and the MacOS API were all Pascal-oriented. C has three fundamental issues: 1) How big is it? 2) Who owns it? 3) Who locks it? C's lack of help in dealing with all three is the main cause of most memory-related program bugs. I once tried to fix #1 in a backwards compatible way. See [1]. After much discussion on some mailing lists, there was general agreement that this was technically feasible but not politically feasible. (I once had hope that Rust would replace C, but Rust has gotten too fancy, with too much input from the functional programming people, the template enthusiasts, and the type theorists. Rust isn't bad, but it's at least as complex as C++.) [1] http://www.animats.com/papers/languages/safearraysforc43.pdf http://www.animats.com/papers/languages/safearraysforc43.pdf
- S_I 10y ago>The original Macintosh apps were in Pascal and the MacOS API were all Pascal-oriented. Yeah, i remember using the Mac OS written in Pascal. Strangely enough, i remember it being buggy as hell and crashing pretty often (no memory protection at all).
- rpeden 10y agoI've read that large bits of it were written in 68k assembly too, so those parts might be responsible for the crashiness.
- ArkyBeagle 10y agoYou can't write systems programs in Pascal without escape-to-assembly. My first big 'C' project was a significant quality improvement over the Pascal it replaced, partly because of this.
- pjmlp 10y agoFunny I managed to do that in Turbo Pascal. Also C standard library cannot be implemented without using Assembly, unless one makes use of extensions not defined in ANSI C.
- bkjsbkjdnf 10y agoI would apologize for my second sentence, pat you on the head and call you a good girl, if I was your mommy and I gave a shit.
- sctb 10y agoWe've banned this account for repeatedly violating the HN commenting guidelines, and detached this comment from https://news.ycombinator.com/item?id=12643960 https://news.ycombinator.com/item?id=12643960.
- deleted 10y ago[deleted]
- zeveb 10y ago> It is still one of the most commonly used languages outside of the Bay Area web/mobile startup echo chamber Is C all that commonly used these days? I rather suspect that it's an unforced error to start a new project in C, and that many wise organisations are replacing buggy C software with slightly-less-buggy software in safer languages. > C’s influence can be seen in many modern languages True, but … is this actually that important in a learning situation? Knowing Java will help learning Go (or vice-versa) about as much as learning C would, I think. > C helps you think like a computer Like a computer, sure, just not like the computer actually running on one's desk or in a data centre. Modern computers really aren't anything like the C model. > Most tools for writing software are written in C (or C++) I suppose that's true, because lots of people have used C, and that really is a good reason to know enough to get around in it, but … maybe one should teach students to use better tools in better languages (Lisp & SmallTalk come to mind). Seriously, in 2016 it's obvious that C is just wrong.
- gravypod 10y agoYou can just say something is wrong because its obvious in 2016. Please say why C is wrong. Is it because it doesn't fit your problem domain? That doesn't mean it's wrong for everything. Every language has a strong and weak point. Knowing how to use their strong and weak points to elegantly solve any problem is important. No language is "wrong" or "right"
- zeveb 10y ago> Please say why C is wrong. I think it's obvious, or should be: manual memory management and poor types. There's no problem domain for which I'd ever want to write C again: not for OSes, not for word processors, not for shell utilities, not for mathematics, not for graphics. C's strong point is that Unix assumes it. > No language is "wrong" or "right" Counterpoints: JavaScript; PHP. Quod erat demonstrandum.
- jly 10y agoHave you ever written a program for a 50 MHz microcontroller with 128 KB of RAM? This is a problem domain in which C is well-suited, where manual memory management is quite important. In fact, there are not many alternatives. It turns out there are a lot of these out there in the world. The world of software development is a lot bigger than PCs running high-level operating systems.
- nickpsecurity 10y agoMost of this just says C was a popular implementation language following UNIX’s fame. So, many things are written in C. So, knowing C will help you understand how they work. People doing cutting-edge work that pick C are usually clear that they pick it for compiler and talent availability, not technical superiority for problem at hand. Now for the No’s. You don’t need to know it for systems programming as plenty of better languages exist for that. It barely contributed anything to good programming languages compared to ALGOL, Simula, Modula, or LISP. Many key designs pushing OS’s forward were not in C: Burrough’s ALGOL, IBM’s PL family, MULTICS in PL/0 & BCPL (UNIX started as MULTICS subset), VMS in BLISS, LISP machines in LISP, Smalltalk-80 in Smalltalk-80, Oberon systems in Oberon dialects, Spin in Modula-3, JX in Java, and recently unikernels in Ocaml. So, C is a necessary evil if you want to understand or extend legacy systems whose authors preferred C. It’s also trendy in that people keep it mostly like it is while defending any problems it has. That’s a social thing. Like COBOL and PL/I are with the mainframe apps for companies using them. It’s not the best language for systems programming along a lot of metrics. One doing clean-slate work on a platform can use better languages to do better in the long-term. Short-term benefits matter, though, so such projects often compile to C or include C FFI to benefit from legacy stuff.
- CocoaGeek 10y ago'C' stickers do exist: http://www.unixstickers.com/stickers/coding_stickers/c-programming-language-shaped-sticker http://www.unixstickers.com/stickers/coding_stickers/c-progr... 8)
- coleifer 10y agoLol u mad
- sctb 10y agoPlease don't comment like this here, we ban accounts that continue to do so. We've detached this comment from https://news.ycombinator.com/item?id=12644986 https://news.ycombinator.com/item?id=12644986.
- coleifer 10y agoYou're right, I could have tried harder to express my disagreement without resorting to "newspeak" or "memespeak". Duly noted with apologies to the commenter and for lowering the discourse.
- ievahanordah 10y agoLearn c because you'll know how computers work unlike wimpy Python. If your choosing what language to learn based on what's cool your a moron.
- Annatar 10y agoWhile everything that the author wrote is true, and I will forever love C, sometimes I wonder if I didn't get short changed by never having been taught ANSI Common LISP at the university. LISP is worth learning for a different reason — the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot. http://www.catb.org/~esr/faqs/hacker-howto.html http://www.catb.org/~esr/faqs/hacker-howto.html Functional language? Check. Stateless? Check. Reentrant? Check. Has a compiler which can generate machine code ELF binary executables? Check. That's not to say one shouldn't learn C - after all, C is the contemporary portable assembler. But if one should also learn C, one should learn assembler too, preferably on a processor with an orthogonal instruction set architecture, like a Motorola 68000. Understanding both, we come back to the author's point - without understanding how the machine works, fast, small, efficient and elegant software will remain forever elusive.
- ArkyBeagle 10y ago"Most of our students use interpreted languages with popular implementations written in C." Well, guess what? Most of the 'C' code I've written in the last ten years pretty much reflects the selfsame reality - next to nothing is done directly in 'C' but rather as posts of "transactions" to an interface. These may or may not be in text form but it's not much work to make 'em be in text form. By the way - 'C' is excellent for text manipulation, even using the crufty old library calls. If you do this and you do it carefully, all the horrors of 'C' become at least manageable. Done carefully enough, you don't even need all the new "safety" furniture. I blame nobody for not wanting to do this, but can we at least self-identify as "will" or "won't" and behave accordingly? 'C' is no bugbear and your favorite interpreter can't save you from a bugbear that doesn't exist. When problems occur, it's because people didn't take the fifteen minutes or fifteen seconds to prevent them. I just find myself gobsmacked that people feel so utterly powerless against the language.
- kensai 10y agoC + Lua == 21st Century "C Programming" There is no silver bullet for everything, obviously, but for me the above combination is a match made in heaven. Lua is small and adds only the necessary tools to take care of higher abstrations in many different paradigms. Even if these two are different languages, they are amazingly complementary. I feel that a good introductory CS course could simply teach in one semester C and the next Lua. By the end of the year students will be able to tackle a huge amount of problems, as well as learned a useful systems and scripting language.
- anthk 10y agoC + Scheme (with Guile) can be more fun. Try it.