5 ms·
Bad C code is bad C code. There's equally bad JavaScript, Ruby, and Python code too; none of those languages have particularly simple semantics. Moreover, thi
by colanderman 10y ago
Bad C code is bad C code. There's equally bad JavaScript, Ruby, and Python code too; none of those languages have particularly simple semantics.
Moreover, this particular example is due to compatibility issues across the multitude of platforms that Linux supports, necessitating support for versions of C older than any language you might like. Were Linux only ever to be compiled with a C11 compiler, this could be replaced with simply `static_assert(x)`.
And speaking as someone who's coded C for 16 years and makes a living doing so: it is rare that I write a macro; my Makefiles are about 5 lines long; I've never touched automake; and the only GCC flags I ever use (and use consistently) are `-std=gnu11 -Wall -Werror -O3`. Heck I wrote a cross-platform NES emulator last month following these rules.
There's a lot of bad C out there to find. Don't let that turn you off from writing good C.
- enraged_camel 10y ago>>Bad C code is bad C code. There's equally bad JavaScript, Ruby, and Python code too; none of those languages have particularly simple semantics. The problem is that C is in everything. OK, not literally, but you know what I mean. Bad JavaScript is easy to avoid. You just navigate to another website. Bad C though, not so much. Often times it's in the kernel or somewhere deep like that.
- pjmlp 10y agoAs a side effect of UNIX adoption in the industry. Like it happened with the browser and JavaScript, C got adopted thanks to UNIX. Before UNIX's adoption, many of us had a pleasant coding life using Turbo/Quick/Apple Pascal, Modula-2, Basic compilers.
- noir_lord 10y agoNo idea why you got so badly downvoted, your comment is pretty much spot on, bad C is hard to avoid.
- enraged_camel 10y agoI don't know either. It happens sometimes. I think it's just the bandwagon effect, and depends on the initial votes and their timing.
- noir_lord 10y agoI think that is the case, people see a faded grey and just hit down.
- bluetomcat 10y agoPeople often regard C code as inherently ugly because of nasty coding styles that were prevalent in the 80s and 90s – all local variables declared at the top of functions, lots of global variables, "space saving" indentation and often no whitespace between operators, bad separation of concerns. C can actually be a decent "high-level" language if you conform to a more modern style of programming. Codebases like Git and Nginx demonstrate that this is possible.
- adrianratnapala 10y agoI generally agree with you, but C even at it's nicest is not "high level" except in the trivial sense of being having a recursive grammar (which assembly doesn't have). The whole advantage of C is that it is a powerful, nice, and portable way to express roughly the same things you would otherwise express in assembly. Most of the really nasty undefined behaviour of modern compilers comes from forgetting this.
- bluetomcat 10y agoC is actually "high-level" in most aspects and we tend to forget that because of newer languages with lots of bells and whistles. C gives you a lot over assembly: functions with (mostly) no need to worry about calling conventions, automatic variables instead of dealing with registers and stack frame offsets, expression-oriented syntax that facilitates nesting of many operations within a single statement, structured programming support instead of scattered jumps and a rudimentary type system around values, pointers, arrays and structs. Nothing fancy, but it means that the language can be compiled in a straightforward manner without any runtime support and a programmer can easily have a complete mental model of it.
- pjmlp 10y agoCompared with languages like Ada, Modula-2, Turbo Pascal, Mesa/Cedar, Algol, PL/I, C is what we used to call a middle level language in those days. And Algol, PL/I and their respective variants are around 10 years older than C.
- 10y ago
- marcosdumay 10y agoI wonder at what point even Linux will have to abandon the older dialects of C.
- majewsky 10y agoWhy should it "have to"? (Honest question, I'm certainly not advocating keeping old styles for the heck of it.)
- marcosdumay 10y agoOld styes have a cost, and old compilers are not used very often. At some point, even for a compatibility focused project like Linux, that cost must get too big for the benefit it provides.
- palunon 10y agoAutomake is nice if you know how to use it. It provides a lot of things on top of a simple makefile... You don't need it to write C, but everything that uses it is not "bad C code".