8 ms·
C was famously well designed. The problems it was well designed for have disappeared and its good ideas are so well understood that, like many great early works
by roenxi 7y ago
C was famously well designed. The problems it was well designed for have disappeared and its good ideas are so well understood that, like many great early works, they are cliches that can no longer be recognised for their brilliance because everyone is doing that.
C's flaws are real, but they exist in the context of that design. For example, C has bad memory management because it was built when programmers had kilo- to mega- bytes to play with and needed perfect control.
I'm not sure anyone could ever accuse anything related to the internet of being 'designed'. Even being standardised is a stretch. Javascript isn't C, because C is an extremely focused attempt to solve specific problems. Javascript simply does not attempt to tackle the same problems as C and it doesn't attempt to tackle them in the same way.
It may be that they are both fail to solve the big problems in web development, but that is not really a thing worth comparing languages on.
- notacoward 7y ago> like many great early works, they are cliches This, a thousand times. It's just so easy for people to fall into the trap of thinking the current list of things to do or avoid has always been obvious. The path is always obvious after a million people have trodden it. But at one time it wasn't. At one time people had to figure out things we now take for granted - like network APIs or concurrent programming models or, most relevantly, memory management. At the time manual management of object lifetimes was the only feasible option for a systems programming language, and it was feasible in part because control flows were simpler. Yes, even in things like OS kernels. They were kept simple by design in part to keep lifetime management tractable. Many of the things that make that approach non-viable today - e.g. massive concurrency, callbacks, exceptions - weren't part of the idiom then. They were irrelevant to C's design. C was good for its time. Go ahead, take a look at PL/I and BLISS. See whether you'd rather program in those. It might or might not be relevant today, but C was better designed in its context than anything most of its modern critics have ever designed (or will design) themselves.
- laumars 7y ago> C was good for its time. Go ahead, take a look at PL/I and BLISS. See whether you'd rather program in those. I don't think that's a fair comment. Pl/I wasn't really the same domain as C and there were other alternatives to PL/I (such as FORTRAN, COBOL, ALGOL, Simula, LISP etc) In fact by the time C was released, there were already literally dozens of programming languages. And C itself an evolutionary progression because it took ideas from B, ALBOL and a few others. Also Pascal pre-dates C as well. I don't mean the following as a criticism against C because I do quite like the language but it does sometimes feel like it's put on a pedestal because it ended up dominating the industry -- either directly or via other languages heavily inspired by C. I do wonder if we've be seeing the same rose-tinted comments had UNIX been based on Pascal and Object Pascal not lost to C++.
- notacoward 7y ago> by the time C was released, there were already literally dozens of programming languages Hundreds, actually, I was there, but writing a compiler in COBOL or an OS kernel in FORTRAN would have been quite an exercise. For those kinds of domains, there were few alternatives and assembler was still a common choice. C was certainly an improvement on that.
- mark-r 7y agoPascal was my favorite language for a number of years. But it was completely inappropriate for systems programming because it was too protective, it kept you from doing the things that are regularly required at an OS level.
- laumars 7y ago> Pascal was my favorite language for a number of years. Likewise :) > But it was completely inappropriate for systems programming because it was too protective, it kept you from doing the things that are regularly required at an OS level. I guess it depends on what systems you're programming. I seem to recall Pascal was heavily used in the early days of Windows and Macintoshes. Albeit my memory is hazy so perhaps that was "just" user applications with the lower level stuff being done in assembly?
- wbl 7y agoThe Lisp machines were contemporaneous with Unix, as were Wirth's Pascal based systems, the Burroughs with its bound checks, Algol 68. Dont get me wrong: C gets the job done. It's successful in a wide number of domains, and I do like using it. But its success was not inevitable and involved a lot of external and soft factors.
- notacoward 7y agoLisp machines were contemporaneous C was introduced in 1972. Lisp machines started in 1975, so can't have influenced C without some time travel. > Wirth's Pascal based systems Pascal predated C by only two years, so it's not clear how much it could have influenced C's design. (Side note: Wirth originally intended Pascal to be a pure teaching language, and was reportedly furious when a TA wrote the first compiler to make grading easier.) More importantly, Wirth's Modula machines could not have existed until at least 1979 when the language itself was introduced. > Burroughs with its bound checks That's a machine, not a language. What language(s) were its OS and compilers written in? > Algol 68 Now we're getting somewhere. Yes, Algol 68 had existed for a whole four years. Was it suitable as a systems programming language? Not in its canonical form, but there were certainly members of its family (e.g. Wirth's PL/360 and ALGOL/W) that were worthy alternatives to C. > its success was not inevitable Never said so. I'm not even trying to claim that C was the best possible language at the time. The question is whether it was well designed for its time, with specific reference to the issue of memory management. I'd say it was, and leave it as an exercise for the reader to determine what strategies those other alternatives - even if they were superior in some ways - used to deal with heap-allocated memory.
- wbl 7y agoC was not born in a day. ANSI C introduced a number of significant features like prototypes, and commercial compilers also evolved it.
- notacoward 7y agoDid any of those subsequent changes affect the basic memory-management model?
- eru 7y agoWhat most people see as manual memory management in C, malloc and free, doesn't even give you that much control. Stuff on the stack also gets handled pretty automatically. You can however implement completely manual memory management with C. I think the Linux kernel does a lot of that. (Though mostly do it via libraries they've written, of course. Manual doesn't mean you have to do everything with copy-and-paste.)
- skohan 7y agoIt's a greater degree of control than you get with most languages. For instance, in most high-level, garbage collected languages with RAII, allocations and frees happen at a fairly granular level when objects are created and destroyed, and the programmer has zero ability to ensure things like cache-friendly, contiguous memory layouts. For things real-time applications, or even video games, this can make the difference between success or failure.
- eru 7y agoYes. Though funny enough, most implementations of malloc/free are not suitable for hard real time code. One of malloc or free usually has an unbounded worst-case runtime, because of the data structures for keeping track of free memory they keep.
- skohan 7y agoBut you could, for instance, allocate arenas at the beginning of execution and then do virtual allocations inside this for the rest of execution, no?
- stjohnswarts 7y agoI'm not sure what arenas are but you can certainly use pre allocated memory pools to bound a custom malloc/free in both time and space.
- eru 7y agoYes, you can do that. It's just not native malloc / free anymore. Of course, you need to be careful about your manual approach. Both to avoid mistakes, but also to actually achieve the performance goals you have.
- SilasX 7y agoMostly agreed about C, but buffer overflows aren’t an excusable failing justified by design constraints.
- liveoneggs 7y agojavascript is perfectly suited for its problem set too: <a onclick="..." It's all that other stuff that it's so bad at
- jspash 7y agoIMHO, we already had way to do that. It looks like this <a href="..." I would argue that the code you provided did nothing but cause a generation of developers to look one way while trying to go another.
- Iv 7y agoJavascript is a bad solution to a problem we should never have had.
- gatherhunterer 7y agoThis seems like a response to the title, not the article. He is comparing his experiences with using and eventually moving past these languages.
- chriskrycho 7y agoC is an amazing language, and I’m glad that I spent the first five years of my career writing it pretty much every day. (Some days I was writing FORTRAN, of an era when it actually was capitalized, or working on some very bad late 90s C++. But most days, C.) The fact that it was a phenomenally well-designed language doesn’t mean we can’t try to improve upon it. My love for it doesn’t mean I don’t want to improve on it! Quite the opposite in fact.
- skohan 7y ago> The problems it was well designed for have disappeared I think C is still an incredibly relevant language. There are still plenty of cases where it's useful to have a very simple, un-opinionated language for working close to the metal. I think C as "portable assembly" is still incredibly useful, and no other language has really filled that slot perfectly. > C has bad memory management because it was built when programmers had kilo- to mega- bytes to play with and needed perfect control. I don't think C's memory management is bad. It's not right for heaps of problems where it's not needed; for example for things like front-end work, or server software where the main concern is stability, manual memory management is unnecessary. But for domains like computer graphics, or for optimizing compute-bound workloads, manual memory management is still completely relevant. To me, the parts of C which seem a bit dated are the lack of some basic "quality of life" features we take for granted in most languages. For instance, I would be happy with a language almost exactly like C, but with a slightly more powerful type system first-class optionals, and some syntactic sugar for dealing with arrays (i.e. counts, map/reduce/filter functions etc.)
- makapuf 7y agoI think that manu of C issues come from the APIs rather than the language. You could do safe memory management by only using refcounts in the api and sticking to it. You could have bound checking in the strings library. But strings are 0 ended (more an API design since strings are not in C). Not saying that its bad design because it allows >256 length strings with only one byte of overhead. But it is a compromise that made sense but has its drawbacks. There are a few stdlib complements in C (strlcpy, antirez sds lib for strings) but it's a shame a more modern lib/runtime has not been established as a standard while keeping C strengths. Or maybe I'm ignorant.
- ReptileMan 7y agoThe only real flaw in C design is strings and I would argue the preprocessor. The rest is working as intended.
- david-gpu 7y agoThe difficulty of dealing with strings in C is an specific instance the larger problem of missing the key idea that an array shouldn't be just memory, it should be memory plus dimensions. C would have been a much better language if its arrays/buffers were always sized. It would have made its stdlib and application APIs much safer and would even have enabled having bounds checking as an optional compilation flag.
- thrower123 7y agoPascal-strings were not uncommon in C at one point, rather than null-terminated strings. They lost, but in a sense, they didn't, since all the string-manipulation functions we use nowadays take a length parameter anyways.
- zoomablemind 7y agoThe notion was that strings would be consumed fully, thus the starting pointer could be used for iteration, and null char is a natural end condition. Here it is, saving an int and cycles for tracking length. It's just coding in such way appears to be too low-level. Pointer in programmer's hand became akin to neuro-surgeon's scalpel... casually performing surgery often on 'self' and with shaky hands. Sure, take this length to limit potential damage.
- megous 7y agoPeople usually add their own or use existing libraries for strings with bounds. All I'd argue is that it's somewhat annoying that C standard library donesn't have these, so there are too many variants of basically the same thing out there, because most programs benefit from having strings with (unchecked) bounds.
- sjy 7y ago> I'm not sure anyone could ever accuse anything related to the internet of being 'designed'. Even being standardised is a stretch. I think you are talking about the ecosystem surrounding JavaScript, which was created in 10 days for incoherent marketing reasons, not the Internet, which was designed via a rigorous standardisation process. The Internet protocol suite is a beautiful and lasting design that dates back to the 1970s, and it's proved flexible enough for everything from the dial-up era to modern wireless video streaming.
- roenxi 7y agoI suppose I could have been fairer. HTML/CSS/Javascript does not grow in a controlled way and the standardisation tends to be reactive rather than proactive. Most of the components that aren't presenting data to the user are quite well designed. That being said, the internet is very much a sum of parts and is more reminiscent of a naturally forming compost heap than of anything is planned out. And the TCP protocol is a very interesting study from a design perspective and an unusual example in my book of excellent engineering; middling design. The original protocol was not good enough (eg, congestion collapse) but its evolution was quite something.
- kdmccormick 7y agoI think the designed vs. cobbled-together distinction can be drawn at Internet vs. Web (generally, of course).
- vectorEQ 7y agoc has no memory management, its for the programmer itself. so if i a c program has bad memory management it's not the language but the programmer. (admittedly not easy to get right if you need to do it yourself.) C is specific in that it tries to give a good direct interface with hardware. If working within other software like an OS, it's tedious, as there's a lot of things outside of C itself to take into account. Again, not a downside of a language, but the way it is used. Javascript has no relation whatsoever to C, in its design nor implementation. it's a scripting language :/. C is far superior than a lot of languages, but it's often badly applied giving it a bad name. It has a more limited scope in todays world of rapid development on top of operating systems. For embedded / bare metal systems it rules the day and there's barely an alternative unless the bare metal provides excessive resources to allow for things like c++ or rust which add a lot of overhead to systems to provide more ease of use. (i.e. not always worth it / possible depending on the system its targeting.) assembly would be a good alternative to C, but it's incredibly more tedious, where C is a good high level repalcement for assembly, which is what it was designed to be. C is great, just don't use it if you don't need to use it.
- mynegation 7y ago> c has no memory management You might argue that C's memory management is simplistic, lacking, or error prone, that it is not automatic, that there is no garbage collection, but to say that C has no memory management is objectively wrong and detrimental to the understanding of how C works. Stack memory is tracked by both compiler and - in some cases - runtime (see "alloca") by creating a code that manipulates a set of registers. The memory in the heap is managed by a minimal set of calls: you can allocate a chunk of memory of a certain size, you can release it, or you can attempt to re-allocate it. Each of those calls maintains a data structure for tracking available chunks of memory in the raw address space, which programmer does not have to write. This is memory management.
- kbenson 7y ago> C was famously well designed. The problems it was well designed for have disappeared and its good ideas are so well understood that, like many great early works, they are cliches that can no longer be recognised for their brilliance because everyone is doing that. Another way of looking at this is that C is a step on a staircase. There were many steps before it, and there are many after. It's okay to pause on a step for a while and catch your breath. Pause too long and you might start thinking this is a good place to stop, since the steps in front of you seem more trouble than they're worth. You may be tired of climbing, and that's okay. No one person has to keep climbing, but we need people to continue on, so we can see what's at the top of the staircase. So even if some of us decide to make our step a cozy place and settle down, let's be sure to cheer those continuing on, and not try to convince them all to stop with us.