17 ms·
Teaching C (2016)
- sacado2 8y agoC is a weird language, in the job market. It's at the core of all our electronic infrastructure, it's important to learn it if you want to be a serious developer, yet nowadays you can hardly find a job that is "pure C". So, in universities, you have either students who don't see the point, because they'll do java or PHP or JS at their daily jobs, or students who get a little too excited by it, almost specialize in it, and can hardly find a job that fulfills their excitment.
- ElBarto 8y agoThere are quite a few jobs available which are pure C. But obviously the industries/domains which require C are not the same as those which require Java/PHP/JS. In embedded software no-one is going to use Java or PHP, like in mobile/web apps software no-one is going to use C. That being said, Objective C is a pure superset of C (which C++ isn't).
- pjmlp 8y ago> In embedded software no-one is going to use Java Actually they will. https://www.ptc.com/en/products/developer-tools/perc https://www.ptc.com/en/products/developer-tools/perc https://www.aicas.com/cms/en/JamaicaVM https://www.aicas.com/cms/en/JamaicaVM http://www.microej.com/ http://www.microej.com/ https://developer.android.com/things/ https://developer.android.com/things/ https://www.ricoh.com/esa/ https://www.ricoh.com/esa/ Just a small overview, as I don't feel like posting all links from everyone active in commercial Java compilers for embedded deployments.
- ElBarto 8y agoThese seem mostly application level (i.e. high level) software running on embedded systems. I wouldn't call developing on Android "embedded software". The point being that the choice of language is strongly influenced by the domain the software is developed for. I graduated 16 years ago and I have always got jobs which were pure C, on state-of-the-art products as well. That's still the way it is, plenty of jobs available.
- pjmlp 8y agoNoted that I explicitly mentioned Java compilers and not JVMs, some of those platforms do run bare metal and require just a couple of MBs. Not everyone is targeting PICs with 8KB Flash memory.
- Uberphallus 8y agoHonestly, efforts to run Java/Python/Lua/etc in embedded are more about retrofitting developers into that market than anything else, the fact that embedded devices get more and more powerful only enables that. Embedded isn't unaffected by Wirth's law.
- pjmlp 8y agoUS and French military are some of the entities using Java based embedded solutions for weapons control systems, they surely know a few things about hard embedded requirements.
- Uberphallus 8y agoIf we're talking about Aegis, they replaced UYKs with PCs and the realtime constraints are very soft (hundredths of milliseconds); that's hardly embedded, unless you mean embedded in a ship. And yeah, Java works there way better than the CMS-2 they force fed engineers with before. In any case, those systems are far from having the physical and technical constraints of the actual system on a missile, plane or satellite; simply put, a 50ms delay to know the speed of a remote object is acceptable, a 50ms delay to know the speed within said object isn't. To this day, and to the best of my knowledge, 95% of hard realtime logic is C, C++ and Ada or a combination of them, when not custom ASICs and FPGAs for low latency and high throughput tasks. If we're talking about other systems, I'd like to know about them.
- jki275 8y agoCMS-2 really is a horrid language. I'm surprised to hear they're using Java though, I figured they would go to C or C++.
- pjmlp 8y agoYes Aegis is one of the examples, among other ones reported throughout the years by Aonix, before they got bought by PTC. Apparently embedded now means PICs with 8 KB, while anything else more powerful than a late 80's Cray is not embedded anymore.
- TickleSteve 8y agoYou can only afford to run Java on an embedded system when you are making limited-run devices, i.e. where the cost of the processor & RAM etc are negligible. For most embedded devices, this is not true. When you're paying for every device the code runs on... and that code wastes 80% of your cycles in abstractions and indirections then forces you to have 200% more RAM than the equivalent C code, that changes your mind. Saving a tiny amount on a processor adds up when the multiplier is (say) 1 million units.
- pjmlp 8y agoDepends if you only consider embedded PICs with 8KB or such then yes. Otherwise anything of ARM Cortex M class does have Java compilers available. Garmin devices use Monkey, which is their own Java like language. Ricoh and Xerox copiers use Java on OS stack for third party integration. Likewise Cisco conference call systems have their own Java flavour. Blu Ray players, Gemalto intelligent electricity meters, and plenty more of other examples are available.
- TickleSteve 8y agoThe same applies regardless of the processor (size). Less overhead will allow a cheaper device. Its worth noting that the java support on Cortex-Ms (Jazelle) is deprecated. If you're using a cortex-m class device, chance are you don't want to be running java on it. Note that I'm talking in general terms, there are always exceptions to the rule (such as for the rare sandboxed application).
- pjmlp 8y agoWhy are you talking about Jazelle?! There is this little feature of all commercial Java toolchains for embedded development called AOT compilation to native code.
- TickleSteve 8y agoof course aot exists, was just pointing out that java is not much of a use case in embedded sw, to the extent that once major features are now deprecated.
- varjag 8y agoI've seen an industrial switch running Node. Whenever it was collecting stats, the switching fabric was locking up.
- seabird 8y agoCan we hear a little more about this? It seems so far off the deep end that I'm morbidly curious about the reasoning behind it.
- varjag 8y agoIt was a managed industrial switch from a 2nd tier manufacturer that am not going to name. Was found out because it was breaking the fiber ring on site. My colleague opened it, hooked to a UART, accessed the system and found it's running a Node application for Web UI. On (self-refreshing) status page it was accessing exposed to userspace PHY registers to read out the stats and not in a clever way, blocking up the switch.
- fergie 8y agoI graduated university really excited that I understood pointers, and that I could implement about 10 data structures from the ground up. However when I got my first job at a large dotcom, I got treated as an unqualified beginner because I didn't know Java. 20 years later and I have never had to write so much as a line of code in C, and that makes me kind of sad.
- simias 8y agoA lot of low level embedded programming is effectively "pure C". I think the problem is that these aren't usually entry-level jobs for people without experience. It doesn't help that schools prefer to put the emphasis on languages like PHP or JS because they're easier and almost guarantee that people will find a job immediately regardless of their background. It's just the path of least resistance. But as somebody who mostly writes C for a living and specializes in embedded programming I can assure you that there's no shortage of employment offers.
- golergka 8y ago> these aren't usually entry-level jobs for people without experience This seems true in any software engineering job - but at the same time, open source or personal projects are experience too. I would be very surprised to find a junior developer CV that didn't mention any projects like that.
- yayana 8y agoEmbedded jobs usually get listed as C/C++, and most of the C developers I know stay away from them.
- yitchelle 8y agoWhy? I could guess that these jobs are not as "sexy" as using Java, Python etc?
- tom_mellior 8y agoI think your parent was saying that people using the term "C/C++" are often muddy on the considerable differences between these two languages, and that it is a red flag in a job description if the company cannot even manage to properly name the language they use.
- gameswithgo 8y agoIf you are pedantic enough that you get irritated by "C/C++", which clearly denotes that they understand they are different languages, and only implies they may disagree with you on how much crossover knowledge there is, you probably won't be happy anywhere on earth except maybe the linux kernel team.
- ChrisRR 8y agoMy last 4 jobs have been pure C. I've never had a problem finding a job
- glucose 8y agoI'm CS since 2015 and am graduating next year. Most of our programming classes were in Java, which was deemed outdated by some. But we still had an operating systems and an embedded systems course that used C exclusively. I think it's important to use the language that best applies to the course material. For example we looked at UNIX in the OS course and it really made sense to use C there. But when we did Algorithms and data structures we used Java for that. Using C really takes away from the point and bogs you down in language specifics in this case.
- TickleSteve 8y agoDisagree, the embedded world is still firmly routed in C and this world is larger than you realise. Consider that every electronic device you have has multiple microcontrollers inside running C code. I would argue that if you want to get your code in the most peoples hands, you have to know C. Just looking around the (engineering) office I'm in at the devices using C: - My PC. - The router(s) - The printer(s) - the USB hubs. - the mobiles and tablets - the lights (yes). - the A/C. - The door entry system - the microwave - the desk phones. - the monitors on my desk. - The dishwasher - The coffee machine - The clock The C world is much larger than most web people realise. (the list goes on and on...)
- sacado2 8y agoI agree, there is more C code used in everyday life than anything else. But, regarding job offers, there's a bias, because this code tends to be very stable. The code in your microwave was written 10 years ago, and didn't change since then. OTOH, even a rather stable webapp like HN changed a lot in the meantime. Maybe the guy who worked on your microwave's code moved on to several other projects, and produced code for dozens of objects in your office, while the guy working on your company's website has been working fulltime on it since its creation. Web stuff is maintenance heavy, so even a small webapp requires a lot of human work to keep working in the long run. Add this to the fact that, although most companies, even small ones, need a website that is more than a static single webpage, and/or a way to manage their customer / provider databases, there are rather few companies producing electronic appliances, and unless you live in the right place, most programming jobs you'll find are in high-level stuff.
- rayiner 8y agoC is much bigger than just the “embedded” world/microcontrollers. iOS and Android are still C from the kernel up through the window system/graphics layer. The router software at the core of the Internet are written in C. Vulkan or whatever underlies your game console is in C, as is the GPU driver. (The game itself is probably C++.)
- pjmlp 8y ago
- enriquto 8y agoIt is silly to start teaching in C. You must first learn assembler and then you understand the godsend that C is. When you write C, you should be thiking what happens in assembler, and then writing it beautifylly in C. In parallel to this low-level thread of learning, you have to learn other high-level languages, of course.
- FranzFerdiNaN 8y agoThis is just as dumb as learning C first before picking up Python or Java, just to appreciate what those languages do for you.
- paulriddle 8y agoHe is commiting basic fallacy which is when you discovered some benefit of learning something related to X, you want to tell everybody to learn it before they start learning X. It so common in programming discussions. It is a fallacy because oftentimes you can't appreciate something until you have a need for that or geniune curiosity.
- enriquto 8y agoI actually learnt assembler after a being able to code in a few high-level languages. Assembler was a sort of "liberation", an exhilarating feeling of understanding "so, that's it!". Even if you do not spend much time in assembler, being able to write a hello world and a program that prints prime numbers (or some graphical demo) is a valuable knowledge in computing. Programming without knowing anything about assembler is like driving without having ever opened the hood of your car and changed some oil. Of course, if you are a professional driver you will have specialist mechanicians that take care of all of it, but still it would be ridiculous if you could not do a few simple things.
- paulriddle 8y ago> being able to write a hello world and a program that prints prime numbers (or some graphical demo) is a valuable knowledge in computing. You are so wrong. It is not valueable at all. If you are able to do this, then you're just capable of signaling that you have been exposed to assembly and familiar with the very basics of it. But how is it any useful? If you could find some intricate bug, or optimize a program in a considerable way based on insight you gained from reading it's assembly code that would have been very valueable indeed.
- Insanity 8y agoI kind of want to say it's important for programmers to have some knowledge of C but frankly I'm not sure that's true anymore. There's only been once case in which I really needed C (because I was programming for a system from the 90s and I only could get C running with the tools I had). As others have said in this thread, it might be useful for you if you end up in embedded devices or other areas of development, but it won't help you for the bulk of applications written in Java / Python or some other higher-level languages.
- arendtio 8y ago> [...] on the (thankfully excellent) collection of tools that is available for helping us develop good [...] That statement could also have been made by someone teaching Javascript in 2018 :D Kinda funny how we 'fix' high-level languages by augmenting them with tools.
- pjmlp 8y agoIn my university, back in the mid-90's teaching C was already seen as outdated. First year students got Pascal in the first semester and C++ on the second one, followed by Caml Light, Lisp, Smalltalk, Prolog, MIPS and x86 Assembly, PL/SQL, while those taking compiler design classes would also dive into many other ones. OS design, data structures and distributed computing classes assumed that having learned C++, any student would be able to downgrade themselves into C level on per-case basis. C only became industry relevant thanks to the widespread of UNIX clones, and in platforms like ChromeOS, Windows, Android, its relevance is slowly fading away. Still it is going to be around for as long as we need to target POSIX platforms, which is why I follow with interest any attempt to make it safer, as I would wish my computing tools not to be weakest link, if they happen to be written in C for whatever reason.
- mlthoughts2018 8y ago> “C only became industry relevant thanks to the widespread of UNIX clones” It has always been deeply important in scientifuc computing, and even now it’s very valuable to know C underpinnings of Python & Python scientific computing tools. On the scientific algorithm side I don’t see C diminishing in importance at all, and many critical systems and libraries use it and require young programmers to know it to really use them (zeromq, Postgres C api, CPython, various things written in Cython).
- pjmlp 8y agoIn scientific computing all code that matters is mostly written in Fortran and some of it has been ported to C++. From the point of view of an ex-CERN, very few relevant packages are written in C.
- _n_b_ 8y agoFor the nuclear industry, this is true as well. A lot of it is because of the original codes were written in Fortran, and thus there is some institutional lock-in even for new stuff. Everybody in the organization already knows Fortran, it's quite fast, and there are good libraries for doing all of the standard number crunching. However, my unscientific and unsupported observation is that in fields that have emerged after Fortran went out of vogue as a general-purpose language, this same process happens again, but just with a more modern language. SciPy etc. are quite common in fields like genomic analysis, and I suspect that in 20 years, this will still be the case even if almost nobody else is writing new Python code.
- jasode 8y agoThe author's main paint is pedagogy of teaching C as opposed to industry relevance of C. >The other day Neel Krishnaswami mentioned that he’s going to be teaching the C class at Cambridge in the fall, and asked if I had any advice about that topic. Some googling found a C/C++ class by Neel Krishnaswami[1]. The description says 10 lectures so I'm guessing roughly ~10 hours of instruction. The prerequisites for the class are "none". You can also browse the pdfs of class lectures and past exams to get a feel for what the professor is teaching. With that in mind, we then consider Regehr's advice: >My main idea is that we need to teach C in a way that helps students understand why a very large fraction of critical software infrastructure, including almost all operating systems and embedded systems, is written in C, while also acknowledging the disastrously central role that it has played in our ongoing computer security nightmare. The noble goal of "traps/pitfalls/disasters of C" isn't really possible to weave into an introductory course if a class is currently structured with ~10 hours. You have some hard time constraints there. You'd have to remove some topics ... e.g. maybe remove linkers?, STL?, metaprogramming? -- or -- make the class much longer ... e.g. more hours?, more homework?, more case studies? An "Introduction to programming using C syntax" is one type of class that requires a baseline of time to each. An "Introduction to industrial-grade software engineering using C best practices" is another type of class with its own heavy time commitments. Teaching the topics of correct/incorrect uses of C would take even more time than the learning the syntax of C. Regehr's essay is well-intentioned ("hey, you should teach this very important topic <X-prime> related to topic <X>") -- but he doesn't actually tackle how to squeeze it all into a finite time-constrained class. [1] https://www.cl.cam.ac.uk/teaching/1617/CandC++/ https://www.cl.cam.ac.uk/teaching/1617/CandC++/
- unwind 8y agoGood points, but I don't think STL (which is, of course, the standard template library from C++) has anything to do in a course on C. Perhaps you just meant "the standard library"?
- de_watcher 8y agoBtw, C with STL algorithms is surprisingly good.
- blub 8y agoThe biggest issue C has is that there's no good answer to the second big question. No matter how you slice and dice C, its highest abstractions are functions, structs and pointers and all of them can fail catastrophically at each and every point of use. One can't even add two numbers or read from a variable in C without the possibility of triggering undefined behaviour. And there's nothing that will rescue you from that possibility except paying attention, which is something us humans can be pretty bad at. When using C, one is setting themselves up for failure, which already hints at the answer to the first big question - no. Go, Rust and C++ can do everything C does in a safer way.
- mayank005 8y agogood news
- z92 8y agoIf you intend to write extension for Python, Ruby, PHP, Lua, Node or most of any high level language, you need to write it in C. Want to build a library that can be used in any of the high level languages? Write it in C and provide binding. A library code written in PHP can't be used by Haskell. Not without a big overhead. Or vice versa. Write it in C and your are done. These are where C still comes handy.
- blub 8y agoUnless I'm missing something, any language offering a C FFI can be used to provide interoperability.
- humanrebar 8y agoDepends on what you are doing. You often need to pull in the other language's runtime while libc is typically already in use. You also have to be careful about ABI details like string representations, concurrency, and threading features.
- deleted 8y ago[deleted]
- __s 8y agoNode is actually a bit lack luster to write extensions for in C, as it prefers to go through v8's C++ abi. Same for LLVM: they have a half baked C interface to what's really a C++ abi. There's an alright attempt at allowing for Rust bindings in node: https://github.com/neon-bindings/neon https://github.com/neon-bindings/neon Because C is so raw bone, highly generic APIs from higher level languages can come off as rather lackluster when reduced to C's world view
- pornel 8y agoFortunately, you don't have to use C for this any more. Rust has bindings for making extensions for Ruby, Python, Lua and Node, and generally it's very well suited for making zero-cost cleaner APIs on top of C FFI. https://github.com/tildeio/helix https://github.com/tildeio/helix https://github.com/PyO3/pyo3 https://github.com/PyO3/pyo3 https://github.com/kyren/rlua https://github.com/kyren/rlua https://github.com/neon-bindings/neon https://github.com/neon-bindings/neon
- throwaway487548 8y ago> C is probably a poor first or second language. What does he mean by "probably"? How could anyone in PL and teaching community ignore decades of research and development of teaching materials in Scheme and Standard ML? Scheme (Racket) should be the first language. Standard ML or Haskell - the second. One will tap into two distinct whole sub-cultures (US and British respectively). Also this way of teaching C as a specialized implementation language which must be used together with special tools is the right way. It is useless to teach C without or prior to machine architectures and assembler language basics. C is by no means a general purpose language, even when the industry is using it this way and should be taught only as part of specialization in systems programming.
- throwaway487548 8y agoWhat exactly is wrong with this particular comment, please? Or it just hurt some people's feelings and makes one so uncomfortable and emotionally triggered that he pressed downvote?
- pjc50 8y agoC development, like most languages, isn't really "taught" at all. You might have some teaching on the structure of the language and a basic getting started course on main(), but that's just the beginning. Everything from there up seems to be self-taught, either from the internet, code examples, or working it out from first principles. There are a lot more risks in C than more recent languages. Koenig's book "C Traps And Pitfalls" https://www.amazon.co.uk/C-Traps-Pitfalls-Andrew-Koenig/dp/0201179288 https://www.amazon.co.uk/C-Traps-Pitfalls-Andrew-Koenig/dp/0... was extremely useful to me when I was learning the language (available at my local library!). I don't know if there's a more modern version that takes into account recent changes to the C standard. I note that a lot of the time in embedded work you don't get to use the latest version of the standard because you're using a weird or obsolete toolchain that doesn't support it. Or architectures like PIC, where your stack is hardware limited to 8 levels and indirect addressing is inefficient. I think a lot of the "pure C" people are disguised as electronics engineers - doing PCB design and microcontroller programming together.
- jackhack 8y ago>>Everything from there up seems to be self-taught, either from the internet, code examples, or working it out from first principles. But to be fair, can't that be said that nearly everything is self-taught? From Physics, to mathematics, to music performance and theory, to learning to ride a bicycle or drive a car -- we can read but it takes some time to internalize the structure of each discipline and "own" it. >>in embedded work you don't get to use the latest version I work in C77, and I'm reminded of how far C (and C++) has come each time I have to #define that fancy new-fangled "boolean" type. >>I think a lot of the "pure C" people are disguised as electronics engineers... Agreed, this is exactly right. Most if not all of the pure-c world is due to embedded micros with strict limitations (<1k RAM, etc.)
- tnova 8y ago> I work in C77 Do you mean C89? I've never heard of C77 and a quick Google search came up with nothing.
- 8y ago
- notacoward 8y agoIt's pretty important to note this is about how to teach C, not why. Should schools be teaching C at all? I would say yes, not as an introductory language but as a precursor to studying kernels or databases or compilers. Real-life examples of these are mostly written in C, and studying such systems is IMO a necessary part of a CS curriculum. Therefore, at some point students need to learn C. They should certainly have the option, so we still need to address the question of how it should be taught. With regard to that question, the OP seems pretty spot one. The identification of certain codebases as good or bad matches my own experience with most of them. The advice to use static analysis and to avoid preprocessor abuse is sound. There are only a few things I'd add. * You can't really learn C without also learning to use a debugger - probably gdb. That must be part of the lesson plan. * A more in-depth discussion of good error-handling and memory-management practices would be worthwhile, since C itself doesn't provide these. * It can be very informative to implement some of the features found in other languages in C. Examples might include a simple form of object orientation, or a map/dict/hash, or a regex parser. Besides their value as a form of practice, this would expose students to some of the issues and decisions involved in making these a built-in part of a higher level language.
- eternalban 8y ago> You can't really learn C without also learning to use a debugger News to me. I learned C in '85 from the K&R book and the project lead for our little startup's Fortran to C translator. No debuggers were involved as far as I can remember. [p.s. as to "why" teach C. I know many languages at this point, but that initial exposure to C necessitated a deeper understanding of 'the machine', memory management, etc. The core of C is fairly straight forward and imho an excellent pedagogical vehicle for a 'substantial' understanding of "programming".]
- canhascodez 8y agoThe machine being used is completely incidental to programming. Dijkstra used a fountain pen. Which is more fundamental, the machine, or its mathematical abstraction? Why should people learn C, and not Lisp?
- paedupeax 8y agoI wonder what his views are on using an IDE vs. using a plain text editor. Because getting to know the tools (compiler, build system) is important, I'd go for the latter choice.
- raymond_goo 8y agoI still have my university-library-xeroxed pages from Expert C Programming from 20 years ago... Seems like I got lucky since it was the second and only other C book I ever read on C, apart from K&R of course...
- tomcam 8y ago> There’s a lot of reading material out there. For the basics, I still recommend that students purchase K&R. People say good things about C Programming: A Modern Approach; I’ve only skimmed it. This early quote filled me with dread. The article fulfilled that dread. IMHO K&R was a classic book but C has changed far too much for that to be of service to students, who would have to unlearn as much as they learn. Then the author, a college teacher, offhandedly mentions another outdated book as if to recommend it but admits no firsthand knowledge of it. A serious programming student taking these recommendations has just spent a hundred bucks or so and a great deal of precious study time on material that will derail them from their studies with no benefit at all.
- docbrown 8y agoIs there any updated texts that you or anyone else would recommend for people new to C?
- MarvelousWololo 8y agoI'd love to know this as well.
- GolDDranks 8y agoI don't know whether you read the article through, but he later has strong stances against some books with outdated or bad advice. Furthermore, he is well aware of the fact that C (and systems programming, and systems themselves) has changed over the years. In general, John Regehr (a professor, not a college teacher, mind you) is very knowledgeable of C, compilers and especially systems programming languages, memory safety and undefined behaviour. I would say that his words have some serious weight.
- selftaughthelp 8y agoI'm self taught (well, related degree) so I missed out on OS and compiler classes that got into C beyond a basic level. What is the best resource out there for someone who is interested in learning C from a systems programming perspective? I would LOVE to dive in and learn everything I can about it, but there is so much contention out there about what to learn/where to learn it from that I get analysis paralysis and end up going nowhere with my interests.
- kita99 8y agoWhat books do you recommend for a newbie to C?
- writepub 8y agoMost people coding in C don't hang out on HN or SO. They are typically electrical engineers working for companies selling hardware. They tend to be less web savvy than the average CS/programmer types, but they're the ones building the guts of the infrastructure that runs the world. C isn't going anywhere, even in 10 years. People keep floating Rust and the like, but most targets for C have 16KB program space, and about that much in RAM budget. The C standard library itself is opportunistically linked on these platforms. The dependencies required for Rust, or even C++, are larger than the code space of 90% of the microcontrollers in your car
- steveklabnik 8y agoThe smallest binary rustc can produce is 148 bytes. You can get small binaries if that’s something you care about.
- dang 8y agoDiscussed at the time: https://news.ycombinator.com/item?id=11668396 https://news.ycombinator.com/item?id=11668396