16 ms·
45 years since its creation. The C language still very popular
- alistproducer2 10y agoOne of my favorite jokes on HN was in a typical language wars thread where a guy wrote "real men write in C....without the standard library." That still makes me laugh.
- deleted 10y ago[deleted]
- LionessLover 10y agoHappens every day when writing code for small embedded systems. :-)
- duozerk 10y agoTo be fair, there is often some sort of limited version of the std lib available even for those (for example by the MCU manufacturer).
- LionessLover 10y ago"Availability" doesn't mean much. There are plenty of all kinds of libs available on all platforms (who wants to program WiFi access for the embedded sensor from scratch, for example?). Doesn't mean it makes sense to put any of them into the current project. The stdlib is one of many and not that often the one that is put in. The libs I use on my embedded system are much more likely to be for some specific piece of sensor or I/O device (like the mentioned WiFi module), I rarely have need for what's in the stdlib. Of course, embedded systems vary far more than the PC and server stuff so you can easily find people who will say the exact opposite.
- jotux 10y ago>I rarely have need for what's in the stdlib It has been my experience that people who don't know or use the C stdlib end up unknowingly re-implementing stdlib functions over and over again.
- marssaxman 10y agoA freestanding C implementation doesn't have to include anything but a handful of headers with some macro and type definitions. It's not uncommon to get a manufacturer-specific library whose features are specific to the particular controller architecture, not related to those defined in the full C library. And it's not uncommon for embedded software developers to ignore those libraries, which are frequently terrible, and write everything from scratch.
- ndesaulniers 10y agoSounds like writing kernel code.
- vardump 10y agoWell, except that in kernel you often can't use even many CPU features either in practice. At least if you use SSE2/FP/etc., you better ensure those FPU registers are saved and restored. But probably you don't want to do that in a IRQ handler! Save only SSE2 registers on an AVX system (higher 128 bits will be zeroed for currently executing usermode thread!) and receive "interesting" bug reports from the end users. If you refer to a vm page that's not present... well, bad things might happen. Etc.
- TickleSteve 10y agoBare metal C code is what is running on 99.9% of the embedded devices surrounding you right now...
- vardump 10y agoScary thought. I'd feel more at ease if it was Rust (or something analogous). Just disassemble/decompile some random firmware code... you wouldn't believe what one can find from those piles of err... binary dump.
- TickleSteve 10y agoThere is a lot of scaremongery around C.... don't believe it. If you know what you're doing (and you should) then C is the best tool for the job.
- Profan 10y agoBest tool is a stretch, it's a tool. If we can get tools like Rust which have better memory safety guarantees while offering much of the same performance, then hell, why not? It's easy to see why just by looking at the hundreds of CVE's throughout the years, often caused by memory unsafe operations. Not that I don't like C, but there's many better alternatives out there. And this is coming from someone who stubbornly sticks to writing D in C-style, but knows what Rust brings to the table.
- TickleSteve 10y agoOK, I'm biased as I've got over 20 years in embedded/real-time systems primarily written in C (and C++) and am currently architect for an embedded system containing ~million lines of code and rolling out to tens of millions of units.... (But I'm educated enough to also use Python, Clojure, C# and a variety of other systems). ...and C is currently the best choice for systems like this because of reasons not primarily to do with the language. Currently, if you suggest to use a language other than C you will be laughed out because the only available embedded guys are C based. Yes, momentum counts and C has massive momentum. There are also issues such as toolchains and tooling, familiarity, community, and of course the massive existing set of libraries, codebases and knowledge. Basically, C is 'good enough'. (although Rust is interesting and on the horizon, its a long way off yet). Although technically a better language, C's shortcomings are greatly exaggerated, for example memory management. In general this is not an issue in bare metal embedded systems as you don't have a heap, everything is statically allocated by design. There are many flaws in the C language (as in every language), but in day-to-day use, they are very easy to manage. So... don't believe the (bad) hype.
- andrewmcwatters 10y agoThis is surprisingly easy, though! Funny, nonetheless.
- rat87 10y agoObligatory link to the Story of Mel: http://www.catb.org/jargon/html/story-of-mel.html http://www.catb.org/jargon/html/story-of-mel.html
- andreapaiola 10y agoAh! I've thought instead to MEL (ancient Maya scripting language)
- andreapaiola 10y agoMaya the 3D software, not the people
- cperciva 10y agoAs a FreeBSD developer, I have to disagree. Real men write the standard library.
- rm_-rf_slash 10y agoC is the Latin of programming languages. The general syntax is easy to learn and communicates well across derivatives as diverse as Java and and Ruby. Before I learned Lisp and Haskell, I didn't even think non-C-style syntax existed.
- njharman 10y agoForth and Prolog are diverse. Ruby and Java are not. They are both algol (C) derived syntaxes. People only think they are much different because the lack exposure to languages from other (or no) heritages.
- rm_-rf_slash 10y agoIt doesn't matter how diverse the syntax is, just think of the vastly different worlds of people programming in C derived syntaxes: The enterprise app developer writes Java for her day job, and spends her nights creating iPhone apps in Objective-C. Her apps connect with an API on the website she built using Ruby on Rails, and handles front-end interaction in JavaScript. All four languages are syntactically similar, but each has vastly different application domains.
- njharman 10y agoDo you anything about Forth and Prolog and the languages you mention? Three are the same paradigm, the other two are very much not. This has nothing to do with syntax or "application domains".
- komali2 10y agoMy first serious introduction to programming was through Harvard's online CS50x course, which uses C. I think it was a fantastic way to introduce a newbie like me to what programming languages are doing under the hood with memory allocation, pointers, value vs ref, etc.
- georgeglue1 10y agoAlso note that nearly every computer science or electrical engineering grad of the last 30 years has taken multiple courses in C. This obviously gives it a big leg up for employer demand, etc.
- michaelwww 10y agoI will go to my grave loving C, from that first day when I read about it in Byte magazine as the high speed language of every new exciting computer application, to the day when C++ took over and began to assert it's high falutin notions of what a language should be.
- prewett 10y agoI can't help myself from rewriting your post, it's so close :) I will go to my grave loving C, from that first day when I read() about it in unsigned char magazine as the high speed language of every malloc() exciting computer application, to the day when C++ took over and began to assert() its high falutin' notions of what a language should be.
- rbonvall 10y agoI loved it, let me add: I will goto my_grave loving C, from that day[0] ...
- prewett 10y agoI knew I was missing something, nice!
- michaelwww 10y agoBe my guest, that was great.
- pcwalton 10y ago> [referring to Microsoft Word 1.1] It seems that this code is from a C project created recently in GitHub. No sign that’s a code from 25 years ago. I wouldn't necessarily say that. At a glance, there are some questionable idioms: assignment inside a function argument (especially problematic since argument evaluation order is unspecified), old-style argument declaration, a custom Boolean type, less-than-descriptive variable naming, etc. I wouldn't let any of that pass code review today. :) > The power of C is its stability over years, it remains basic, no advanced mechanism was introduced to the language, the code still simple to understand and maintain. Not when you take the arcane undefined behavior rules into account. C semantics are anything but simple.
- gajjanag 10y ago> Not when you take the arcane undefined behavior rules into account. C semantics are anything but simple. Maybe, but note that simplicity should be viewed in a relative sense. I am curious as to which language you think has simpler semantics than C. For example, I have not found Python, Julia, MATLAB, C++, Verilog, or shell script simpler than C. Same goes for my initial explorations of Rust. Even if one includes the arcane corners, the spec is < 200 pages (excluding the stdlib).
- pcwalton 10y agoIf you don't count the unsafe sublanguage, Rust, SML, OCaml, Scheme, Java, and Lua all have simpler semantics than C, and that's just off the top of my head. It's debatable, but I would even argue that Haskell and Swift do. Undefined behavior is really subtle, and there are parts of the spec that compiler developers haven't even come to consensus regarding the meaning of.
- tikhonj 10y agoStandard Haskell (ie Haskell 2010[1]) certainly is. Most of its features are just syntax sugar over a tiny core language with simple (although not 100% formalized) denotational semantics. The language itself isn't very big and it's pretty well-specified. GHC Haskell with all extensions... euh, I don't know. Many extensions are either syntactic sugar or straightforward changes to the base language, sometimes even making it simpler. But I'm not confident about all of them, and I'm not sure how the semantics of some low-level libraries (ie for concurrency) work out. I've written code in essentially just the standard subset and it's a pleasant language—there aren't any extensions that you absolutely must use in real projects. That said, people use lots of them anyhow because most make the language nicer without adding too much complexity. Since the extensions aren't organized in a unified way and have to be split up (since they can generally be enabled or disabled independently), it's hard to figure out how complex they make the semantics of the language as a whole. [1]: https://www.haskell.org/onlinereport/haskell2010/ https://www.haskell.org/onlinereport/haskell2010/
- peter303 10y agoYou can backpropagate "modern" CS techniques like modularity an encapsulation to most ANY language like C or LISP or FORTRAN. But if have language and compiler support for these, it makes it easier and more reliable.
- gp7 10y agoEncapsulation is done better and is easier to manage in C than it is C++.
- ArkyBeagle 10y agoYes. I have entire code bases where the interface to a "capsule" ( because encapsulation, see :) is one function with void parameter and void return. Of course there's a central data store. But that's okay.
- nickpsecurity 10y agoThat's funny about capsules. More consistent when people discuss encapsulation, though. Far as OOP in C, it's definitely doable with quite a few approaches and even books dedicated to it. Example: https://www.cs.rit.edu/~ats/books/ooc.pdf https://www.cs.rit.edu/~ats/books/ooc.pdf Many think C++ with its benefits and problems are relevant to OOP in C but not entirely. That's because they think C++ was about adding OOP to C. It wasn't. Stroustrup used safe, OOP languages like Simula that he wanted more of. He intended to leverage C's popularity and tooling but transform it into something with benefits of other languages. So, the result is C-like but not quite C and complex. Just doing OOP in C, on other hand, is much easier and cleaner problem to solve. ;)
- jasonpeacock 10y agoMy manager (a long-time-ago former dev) once told me: "I can write C in any language." And it's true. He could write beautiful C code in Perl, Java, Ruby, etc - whichever language the current project was using - when he needed to hack something (usually gathering data for business metrics).
- codemac 10y agoWe used that quote as a joke for not learning new languages well enough. Do you mean that he would write C and link it to each implementation?
- jasonpeacock 10y agoHe'd just stick to the basics and write C-style code in the given language, he had no knowledge of any of the language idioms and didn't need them if he kept his code simple enough. Basically only using if/for/while and function/return constructs. It was strange to open a Perl script and see "C" code, with single-letter variables (declared at the top), etc.
- acveilleux 10y agoHonestly, writing perl in "C" style is really a good idea. At least if not pushed to extremes. It avoids a lot of unreadability and confusion. Other things I think make for good perl style: * Never use unless, especially as the after-statement conditional and/or with a negation. (I once spent a whole day ripping my hair out to figure out that an unless with a negated clause that was itself ambiguously named did the exact opposite of what it seemed to. Think [...] unless not $unregulated;) * Do use foreach wherever possible. * Keep reference usage to where it's really needed. * When in doubt, don't write new OOP code. (The benefit to the caller has to be much greater than the extra complexity in implementation.) * Lists are the core data-structure and regex are first class construct. * Avoid the use of implicit $_/@_. * Avoid the use of explicit $_. * Use map / grep / sort and similar in pipelines but don't nest too deep on a given line.
- gbrown 10y ago
- hyperpape 10y agoEvery so often, I think about the meme of the 100 year language. The idea is that we need to start working towards the languages we'll use in 100 years. Instead, I wonder how many we already have. Fortan: 59 C: 43 C++: 33 Python: 25 Php: 21 Javascript: 20 Java: 20 It's still a long time until any of those languages reach 100. But longevity seems to be the rule, not the exception. How many languages that were widespread actually died?[0] I don't pretend to know all the languages that have ever been popular, but not many that subsequently died come to mind. Cobol, maybe some lisp dialects, if you don't count Common Lisp as their successor? Is PL/1 dead? Was APL big enough to make the list? Probably some of the languages I listed above will die before they're 100. Others might be niche, like Fortran already is. But I wouldn't guarantee it. [0] Where dead doesn't rule out someone being paid to maintain ancient code. By that standard, it's unclear whether anything will ever die (https://www.snellman.net/blog/archive/2015-09-01-the-most-obsolete-infrastructure-money-could-buy/ https://www.snellman.net/blog/archive/2015-09-01-the-most-ob...)
- rm_-rf_slash 10y agoThe more I think about it, the less I'm sure certain languages like Java will ever die. Java is a really good language for systems of mind-boggling size, and just as it's easy to write, it's also easy to manage and measure people writing it. Java strikes a good balance between extensibility (easy to implement design patterns; cross-platform JVM) and safety (auto garbage collector; no memory access). Even if technology did rapidly change (nanomachines!) there would still be a business case for a Java-style language. Given how used to C syntaxes we are, it might end up looking like Java. Or Java might just be here to stay, for a long, long time. Side note: a lot of "dead" languages nowadays are ones that were written before memory and processing power were abundant so they had a lot of (what we in the glorious future might call) arbitrary character limits. sp(a,b); might have been sufficient back in the slow-old days, but we don't really consider character limits anymore, and so we can actually learn what a given line of code does by reading it. SubmitPostOnHackerNews(commentID,messageText);
- wry_discontent 10y ago> just as it's easy to write, it's also easy to manage and measure people writing it I think you nailed why I don't care for writing Java perfectly.
- fauigerzigerk 10y agoC was my first language, but I hadn't used it (outside of C++) for a long time. In recent days it suddenly crashed my little "use new cool languages for the heck of it" party. I was experimenting with Swift, trying to make it fit my rather performance/memory critical string processing needs. As it turns out, you can use C code from Swift about as easily as you can use Java code from another JVM language. So I implemented a variant of the short string optimization in a few lines of C code. It's amazing how well C fits the bill as a lingua franca for code that does questionable things to bits and/or is meant to be used from other languages. There's very little competition for C in that role.
- cm2187 10y agoMost popular and most used are not exactly the same thing. Half of the population pay their taxes, I don't think one can claim taxes are very popular.
- blueatlas 10y agoC should be the defacto language for 1st year CS students. It is not highly abstracted from hardware, and much easier to grasp Assembly knowing basic C. The syntax uptake is pretty quick, and would allow students to focus on the problem at hand (e.g. algorithms) rather than language nuance. Not to mention the advantages to the graduate starting their career in software development. It's also easier to go up the stack to object oriented languages, particularly Java. The second chapter, first edition, of David Flanagan's Java in a Nutshell is still, in my opinion, the best intro to Java after having some experience with C.
- feklar 10y agoIt is as some schools, Harvard (CS50) and CMU (15-122) both cover C in first year.
- kuschku 10y ago(Scheme, ASM), (C, Java), (), (Haskell) is the usual I heard of (seperated by semester).
- nightcracker 10y agoI think people should learn Scheme or Python to learn programming, and C to learn our architecture.
- IndianAstronaut 10y agoDefinitely. Beginner programmers are struggling with for loop syntax. You really don't need to start them on pointers.
- pcwalton 10y ago> The syntax uptake is pretty quick, and would allow students to focus on the problem at hand (e.g. algorithms) rather than language nuance. I don't agree. What's the benefit in having to painstakingly write trivial string operations using string.h and manually allocated buffers? What's the benefit in learning the ins and outs of undefined behavior?
- jcadam 10y agoI learned C via this excellent book: http://www.amazon.com/dp/067230399X/?tag=stackoverfl08-20 http://www.amazon.com/dp/067230399X/?tag=stackoverfl08-20, which I picked up from a local bookstore on a whim. I had just started high school, and up until that point my programming experience had been limited to BASIC-type languages (starting with Apple ][ basic when I was 6, then AMOS on the Amiga 500, then QBasic on DOS... actually that last one was a bit of a downgrade from AMOS :) ). C was my introduction to "real" programming -- it forced me to actually learn memory management, pointers, etc. Funny thing, I only took one C course while I was in college. By the time I started college, Java was the new hotness, and I was in the first incoming freshman class to get Java instead of Pascal in our introductory programming course. I took an immediate disliking to Java back then (and still don't like it), so naturally it's the language I have to use at work :O
- yoodenvranx 10y agoI admire C for everything it teached me about programming, but nowadays I actually hate writing it. For all my personal projects I switched over to Python years ago because I just don't want to waste a single more minute dealing with basic stuff like strings in C. I love the batteries-included mentality of Python because it lets me concentrate on implementing actual solutions to my problems instead of fighting against the build system or reliably converting strings into integers. If there would be some kind of batteries-included version of C then I would certainly look into it again, but for now Python is just my preferred tool to get stuff done. (yes, C++ is better in this regard than C, but it is still to cumbersome for my use case of rapidly playing around with new ideas).
- krisdol 10y agoHmm... Rust might be in that ballpark. Certainly more "batteries included" than c and at about the same level of abstraction overall. It depends of course on how cumbersome you consider the ownership system
- yoodenvranx 10y agoRust is on my Todo list! At the moment I do a lot of image and audio processing via SciPy/matplotlib and I think that Rust is lacking in that department at the moment.
- nimmer 10y agoYou seem to be describing Nim.
- witty_username 10y ago> The C language still very popular The C language is still very popular
- throwaway2016a 10y agoI love working with C. The power it gives me allows me to write hyper-optimized applications in terms of memory usage. Using it we process terabyte files ridiculously fast using less than 1K of non-program memory. However, when I don't need to hyper-optimised it is not my first choice due to being way behind other in languages in terms of package management and I'd rather not deal with pointers if I don't have to.
- pnathan 10y agoHave you looked at Rust? It is very good for those design cases.
- throwaway2016a 10y agoRust is definitely on my list of things to learn. I haven't gotten around to it, unfortunately.
- pjmlp 10y ago"Although the first edition of K&R described most of the rules that brought C's type structure to its present form, many programs written in the older, more relaxed style persisted, and so did compilers that tolerated it. To encourage people to pay more attention to the official language rules, to detect legal but suspicious constructions, and to help find interface mismatches undetectable with simple mechanisms for separate compilation, Steve Johnson adapted his pcc compiler to produce lint [Johnson 79b], which scanned a set of files and remarked on dubious constructions." http://www.netzmafia.de/skripten/unix/chist.html http://www.netzmafia.de/skripten/unix/chist.html -- Dennis M. Ritchie
- elliotec 10y agoC is nearly inaccessible to me. It really is like the Latin of programming languages, insofar as JavaScript is the new English of programming languages which is the world I have been living in for some time now. Its like you can see the Latin roots of a lot of English, but reading it is like reading lorem ipsum. Same with C vs. JS with me.
- mwfunk 10y agoIronically it's the other way around for me. C is not just modern English but some 1000-word subset of modern English. JS feels like Esperanto or something- a synthetic language that was informed by English (and other languages) but is really its own thing, and was designed for a very specific purpose. (Those are my subjective feelings about those languages, not actual analysis of any real properties of those languages :) )
- derekp7 10y agoJust out of curiosity, which elements make C inaccessible compared to other C-like languages? The base structure is identical to the later derivatives (if/else, for, while, operators and precedence, use of curly braces). Is it the manual memory management (malloc/free)? Or is it keeping aware of a variable's data type, knowing when and when not to use pointers and references? Or is it the limited number / scope of functions included in the standard libraries? (I'm mainly curious, as C seems to be the most comfortable language to me since I've known it for the last 25 or so years).
- ape4 10y agoWhy would it go away? We still need to write low-level or fast applications.
- gravypod 10y agoC has kind of become the evident defacto standard. There isn't anything we can really do to change that. It just did what it was meant to do very well with all of the flashy bells and whistles removed. The underlying instructions generated by the compilers are simple to follow. Reasoning about what will be generated is an easy enough task (so long as optimization is turned off).
- kensai 10y agoLua + C == welcome to C in the 21st century. :) Seriously enough, Lua adds all those scripting high-level aspects that are missing from C. I know it's another language but its interplay with C gives strength to both of them. A good alternative of the C + Lua paradigm is of course Python.
- fanf2 10y agoTcl + C == welcome to C in the 1990s :-)
- deleted 10y ago[deleted]
- sverige 10y agoHey, now hold on a minute. Are you people telling me that there are languages people actually use other than C !?
- enjones 10y agoNo school like old school!