23 ms·
Let’s Stop Bashing C
- coreyp_1 10y agoI like this short article for a few reasons: 1. It makes the case that just because you don't like something, it doesn't mean that there's not a good reason behind it. 2. Just because you like something, it doesn't mean that it is good (or bad). 3. The things that the naysayers constantly bring up just aren't really that bad to begin with. C is amazingly powerful, and I love it. I love JavaScript, too (especially since ES6!), but I don't confuse where I should use one rather than the other. I tolerate Python. ;) Languages are just tools, and you should use the one most appropriate for the job at hand.
- quanticle 10y agoTools should be ergonomic and should have guards and other safety mechanisms to make it easy to do what you intend to do, and difficult to do things that you do not intend to do. C tends to do the opposite of that. It makes certain things that you want to do more difficult than necessary, while making it very easy to do things that no reasonable person would intend to do. Evee's original post highlights that. In fact, if you look at this post, some of the so-called defenses seem more like indictments to me. For example, in the increment/decrement section, there is this: But look, there’s an even more direct argument: the ++ and -- operators are not even “one” operator. There is a prefix and a postfix variation of them that do slightly different things. The usual semantics is that the prefix ones evaulate to the already-modified expression, while postfix ones yield the original value. This can be very convenient, as in different contexts, code might require the value of one state or another, so having both versions can lead to more concise code and less off-by-one errors. Therefore, one can’t simply say that “++ is equivalent to += 1“, as it is simply not true: it’s not equivalent to at least one of them. In particular, in C, it’s not equivalent with the postfix increment operator. This illustrates exactly the point that Evee was trying to make. It's hard enough to justify having increment and decrement as their own operators (as opposed to a performance optimization implemented by the compiler). Having two variants, which work exactly the same in the vast majority of instances, but do subtly different things in e.g. if-statements and for-loops is complete and utter madness.
- accatyyc 10y agoI really disagree that this is madness. It may be madness to someone not used to coding in C. But if you code a lot of C you _will_ know when to use which one of these, and you will know that they're immensely useful. For example, iterating and adding stuff to arrays: array[index++] = object; instead of array[index] = object; index += 1; and the other way around: array[++index] = object; instead of: index += 1; array[index] = object; There is no way you will miss incrementing your index here, or do it in the wrong place. This is so common, that as a C-programmer you WILL recognize this pattern. It's even better when iterating pointers instead of integers. May I ask what the following means to you? float *float_ptr; float_ptr += 1; I think writing ++float_ptr here is just much more clear. Incrementing pointers by integers just feels wrong when what you really are doing is incrementing it with sizeof(float_ptr).
- pka 10y agoUntil the logic is complex enough and you screw it up. Then you write over '\0' in some string and have a root exploit. Congratulations! float *float_ptr; float_ptr += 1; is no more confusing than float float_ptr[...]; float_ptr[1];
- mfukar 10y agoThere is nothing subtle about the differences of prefix and postfix expressions. That is speaking generally, not only in C. Complaining about that might as well be complaining about parsing techniques, and that's where they would quickly be proven uninformed.
- defgeneric 10y agoC really is still a beautiful language.
- acidbaseextract 10y agoIn the same way that a chainsaw really is still a beautiful tool.
- abraae 10y agoWhat an inspired sentiment. I love C (well I used to last time I used it), and I love chainsaws too.
- nkurz 10y agoNo, C is more like a chef's knife. It will take your finger off if used wrong, it never should be used as a screwdriver, but in trained hands it's a precise tool for the right job. It's C++ that is more like a chainsaw: a noisy, smelly, clattering but effective tool, dangerous without modern protective gear, and an equally poor choice for tightening screws.
- steveklabnik 10y agoHere's a fun blog post about this particular analogy: https://www.schneems.com/2016/08/16/sharp-tools.html https://www.schneems.com/2016/08/16/sharp-tools.html
- nkurz 10y agoWonderful article, thanks! Looks like it hasn't been discussed yet, so I submitted it here: https://news.ycombinator.com/item?id=13092740 https://news.ycombinator.com/item?id=13092740. One of the things that I like about the chef's knife is that if you hold it correctly (http://www.seriouseats.com/2010/05/knife-skills-how-to-hold-a-knife.html http://www.seriouseats.com/2010/05/knife-skills-how-to-hold-...) the deep blade gives you both control and increased safety. People often think the bigger the knife the more dangerous, but often the opposite is true. Chainsaws on the other hand scare me despite their utility, possibly because my grandfather (a very experienced chainsaw user) had a horrendous scar across his neck and face from being stitched back together after an unexpected kickback.
- jetru 10y agoBashing C is like bashing English. Well, maybe Tolkien Elvish might have a better grammar system, but really come on now.
- throwanem 10y agoNatural languages and programming languages aren't really comparable. The former evolve and are beholden to their history, because you can't tell people how to speak. The latter are user interfaces, and to suggest that the only meaningful criterion in user interface design is that it should match what previous designers have done is just self-evidently silly.
- eternalban 10y ago> you can't tell people how to speak you can't tell machines how many bits to use.
- Annatar 10y agoActually if you're the engineer designing the hardware, you most certainly can tell the machine how many bits it's going to use.
- devnonymous 10y ago> The former evolve and are beholden to their history, because you can't tell people how to speak Think about that for a moment in the light of Python 2 - Python 3 or K&R C - C99 or original C++ - C++14
- throwanem 10y ago"The former" refers to natural languages, not programming languages. What you cite is one of the primary reasons I called the two classes incomparable. If programming languages worked like natural languages do, Python 3 wouldn't have been controversial, or exist.
- deleted 10y ago[deleted]
- pmontra 10y ago> Spaces are for the human eye, while braces are for the compiler and for the editor auto indenter too. I don't like doing the job of the compiler but this is an exception. I already wasted more time in a few months of Python by hand aligning and debugging code after I moved it around than it saved time for me by not having to type } or end at the end of the block. Note that Python has a { in most cases: it's a mandatory : And how about the time lost because of "IndentationError: unexpected indent" when copy-pasting code from the editor to the command line interpreter? To the point of bashing C, the post is an answer to a very few points of https://eev.ee/blog/2016/12/01/lets-stop-copying-c/ https://eev.ee/blog/2016/12/01/lets-stop-copying-c/ It's mostly about syntax and it's an interesting read. I particularly like "No hyphens in identifiers"
- pjc50 10y agoOh god, this is one of my least favourite parts of python. It is unnecessarily hard to restructure if-then code. It is risky to cut-and-paste from webpages. And as you say, you can't always paste from the editor to the interpreter. Python has an "invisible close brace" character, the newline, which closes a varying number of braces. When you think of it like that, it makes much less sense.
- voyou 10y ago"Python has an "invisible close brace" character, the newline, which closes a varying number of braces" The idea that the end of a block is invisible isn't really right, though. The newline doesn't end the block. The block ends at the next line containing non-whitespace text at a lower indentation level. In other words, it only ends when it becomes visible that it has ended.
- infogulch 10y agoI'm seeing several people complaining about this, but I've always found changing indentation very easy. Just select then [Shift+]Tab to [un]indent. I do this regardless of the presence of braces.
- 10y ago
- OskarS 10y agoI've always been a huge fan of the increment and decrement operators. I don't use them all the time, but they're very nice to have on occasion, and with operator overloading they can be made incredibly useful. I thought it was a very silly decision for Swift to remove them.
- Tempest1981 10y agoHere are some reasons that Python removed them: http://stackoverflow.com/questions/1485841/behaviour-of-increment-and-decrement-operators-in-python http://stackoverflow.com/questions/1485841/behaviour-of-incr... Edit: a nice write up by Chris Lattner: https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md https://github.com/apple/swift-evolution/blob/master/proposa...
- dap 10y agoIt's very unfortunate that attempting to use preincrement and postincrement operators in Python results not in a syntax error, but in code that silently does something very unexpected.
- pjc50 10y agoInteresting list of things to bash C and Algol-derived languages on. I really like Eevee's original approach of doing a comparative survey rather than talking about things in isolation. ( https://eev.ee/blog/2016/12/01/lets-stop-copying-c/ https://eev.ee/blog/2016/12/01/lets-stop-copying-c/ ) Point by point: - textual inclusion and macros: yeah, this technology was obviously chosen for ease of implementation on small systems and makes little sense. Now obsolete and a handicap. Especially in C++. - optional block delimiters: responsible for gotofail and similar errors. - modulo: symptom of C not having standardised maths semantics. Standardise your semantics, language designers! Don't just say "whatever the CPU gives us, I'm sure it'll be fine". - octal: Nobody uses goddam octal and it's a trap for people used to leading zeroes in decimal. If we're changing this then I'd like to appeal for some features from Verilog e.g. 8'b1101_1101 : leading width specifier, and the internal underscore which is ignored but provides visual clarity. - power operator: meh. - switch: actual operation is kind of bananas, see Duff's device. Should be block-based. - integer division: Careful. Huge argument here about maths. (tbc)
- dom0 10y ago> - octal: Nobody uses goddam octal and it's a trap for people used to leading zeroes in decimal. 0b..., 0x..., 0o... the latter is still a bit subtle (0Oo), but far more distinct and far less likely to happen by accident. > - switch: actual operation is kind of bananas, see Duff's device. Should be block-based. the goto-table semantics of switch are kinda useful in many instances, OTOH a compiler should be smart enough today to achieve the same degree of rather simple optimization.
- JdeBP 10y ago> e.g. 8'b1101_1101 : leading width specifier, and the internal underscore which is ignored but provides visual clarity ... some of which were extensions provided by Metaware's High C/C++ compiler back in the 1990s: 0x2x1101_1011 0x10x_bad_feed_face 0_777
- radiowave 10y agoI do wonder whether this might have missed the point. "Let's Stop Copying C" isn't a criticism of C, so much as a criticism of other languages that have applied a kind of conceptual copy-paste of C-like characteristics. Demonstrating that there are good reasons for those characteristics to exist in C talks entirely past the question of whether the sharp edges of some of those characteristics are still warranted in other languages with other design goals.
- m45t3r 10y agoThe author completely missed the point. It is pretty clear in the Eevee's post (hell, it is even in title) that she isn't saying that C is bad per see, however she thinks that modern higher level languages copying C design parts is silly because it really is. Heck, Java has a god dammit reserved goto keyword for the sake of it. For sure, the author takes the most controversy points of Eevee's points, that AFAIK are mostly (her) personal preferences. However it does not enter in the interesting parts of her argument, like weak typing, C-style loops* or textual inclusion. This post was much less interesting read than Eevee's post, that makes me wonder if the author did a click-baiting title just to try to get some clicks on his blog following Eevee's post... *: really, this is the most retarded thing of the whole C-family languages; it kinda makes sense in C, however if you're writing a modern language that only supports this kinda of loop (pre-ES6 Javascript comes in mind), you're retarded.
- IshKebab 10y agoWeak arguments. Integer division is misleading. It uses the mathematical division operator for something that doesn't behave in that way. Having a separate 'integer division' operator (e.g. //) is much clearer. Nobody could say that the pre/post increment aren't confusing. They feature heavily in 'trick question' C++ tests (along with undefined behaviour, type promotion and so on).
- dagw 10y agoInteger division is misleading. For dynamic languages I kind of agree, but with static languages I think integer division is the right thing. int+int, int*int, int%int and int-int all return an int, so having int/int returning a not_int (what type should it return? should 4/2 return a different type than 2/4?) would be equally confusing.
- IshKebab 10y agoSounds like a lack of imaginationg! I would suggest that it does not compile, and a different operator is required that makes it clear that it isn't 'normal' division. `//` is a good choice, except that is a comment in many languages. Maybe `_/` to indicate that it is a sort of 'floor division'.
- dagw 10y agoMaking int/int an illegal operation would solve some problems, but I doubt it would make things less confusing.
- IshKebab 10y agoI think it would simplify things. All you need to remember is: / = normal division _/ = division then round down Then the compiler enforces all the hard-to-remember rules, i.e. that you can't to normal division on integers. Floats would support both.
- 10y ago
- junke 10y agoRegarding integer division, the Wikipedia article about modulo operation has nice graphics. https://en.wikipedia.org/wiki/Modulo_operation https://en.wikipedia.org/wiki/Modulo_operation
- ekidd 10y agoI could care less about integer division and minor details of syntax, but that's not going to stop me from being grumpy about C's continuing popularity. Every C program I have ever worked on has been riddled with integer overflows, undefined behavior, buffer overflows and bugs. This was perfectly acceptable for a Vax or a Sun workstation in the 80s, and at forgivable in the mid 90s when plenty of developers still only had 8 MB of RAM and wasted half of that on Netscape Navigator. But we live in an age of Pwn2Own and ClusterFuzz, where even the tiniest of bugs can be used as step 4 in a 6-step exploit, and where C compilers reserve the right to completely and silently break your program at the faintest whiff of undefined behavior. I know my limitations: I'm not smart enough to write C code that deals with hostile data off the network. Neither are the authors of 99% of the C code that I've seen, with the possible exceptions of djb and a few OpenBSD contributors. It's long past time to invent and use better systems languages. Choose what you want, but choose something safer.
- Annatar 10y agoThat's an easily correctable problem: learn the living daylights out of programming in assembler, and then C will be like a walk in the park: no more overflows, no more pointer screwups, no more forgetting to free the memory, because you'll know exactly what will happen in the chip and the memory when that code compiles. You'll even start writing code which relies on integer overflow (rollover from #$ff to #$00 again) because, depending on the situation, it will give you a performance boost, or make the algorithm implementation simpler, or both, and you'll know it. It's long past time to invent and use better systems languages. I can't comment on Go, but the textbook examples of Rust and even treatises on the subject from recognized experts in the computer science field (Adam Leventhal) show it to be an utterly overcomplicated language for which there should be a criminal trial and a prison sentence of several decades. Immutables, borrowing, no, I have to stop; my head hurts already, and I'm getting a migraine thinking about solving even the simplest of classic input-output problems with such an overly complicated language. (And my head wants to explode when I compare Rust with AWK for solving input/output problems, the biggest reason why computers were invented.) So... C, C, and more C, because it's infinitely flexible and simple. I like simple, because simple is smart. Complicated and complex isn't. Let's all please be humane to one another and stop inventing more languages. We need less languages, not a bazillion variations on the one central task: making the computer do something. And for that, we already have all the languages we could ever want or need, and for the theoretical case where we don't, there is always the almighty assembler, in which exist no limitations as to what one can program with it.
- MaulingMonkey 10y agoGiven that the original article that this replies to starts with "It [C] works well for what it is, and what it is is a relatively simple layer of indirection atop assembly." I'm not sure "bashing" is an exactly accurate. Given that this reply also starts with "To begin with, I agree with most of the things Eevee wrote", I'm not sure "Let's stop X" is the right title to use, even if it matches the theme of the original article. The reply itself is... a decent alternative viewpoint, to a few of the points made, but I don't think it quite matches the title. And now some counter-counter points: > What’s Wrong with Integer Division? This is the wrong question. The right question is: What's wrong with integer division if and only if both arguments are integers, and ambiguously conflated with floating point division in syntax? I'm sufficiently used to it to not find it a big deal, but that's a poor argument for it's merits in new languages. Nobody thinks integer division shouldn't be an option. > However, the behavior of integer division is very useful. I would argue that in most cases, one expects it to behave just as it does. I've seen even professionals trip up over the semantics of this just regularly enough to be annoying - you read float a = x/y; and assume terrible things about x and y, things that were perhaps even once true. Even if you really did intend to round, you probably assumed unsigned 'round down towards zero' semantics and will have a bug to contend with when x<0 and end up rounding up towards zero. Personally, I haven't found it that difficult to adjust to languages that have a separate integer division operator, or languages requiring an explicit rounding operation, despite a long history of only using languages with C's semantics before them. > Unfortunately, Eevee seems to fall for the extremely common “++ is equivalent with += 1” fallacy. You can see it’s a fallacious statement when, in the end, even the author herself admits that there are things that can’t be implemented in terms of “+= 1“; for instance, incrementing non-random-access iterators. That Eevee herself points out that "++" is not always "+= 1" makes it quite clear that she hasn't "fallen" for any such fallacy. The point is that even including other unmentioned (ab)uses of overloading, there is always a way to rewrite things in an equivalent manner in terms of "+=", "-=", or custom functions - combined with either the abuse of the comma operator, or multiple statements. For the mentioned case of iteration - plenty of other languages have a separate, named function for iteration, even if they allow "++" and "--" to be overloaded. The only real point of debate here is how often the "++" and "--" operators produce concise code, versus how often they produce write-only code.
- piyush_soni 10y agoLet's stop bashing bashing.
- paulddraper 10y agoIs prefer to keep bashing bash, if possible.
- Pica_soO 10y agoHey, dont mock the wailing parade around the C-monument. This must be its 300 cycle and its still growing strong. Helping the inertia by self-sabotaging with over idealistic , non backwards compatible languages, the software architects and computer scientists lead the procession. Followed they are by self-flagellating programmers, trying to figure out who beat them to it again and again. Followed they are by the silent businessman parade, who search for the perfect compromise between throw-away code and reuse ability on hardware where the solder-lead is not stable yet. All hail the holy C, all hail the mighty procession of pain.
- hellofunk 10y ago> The only thing I can suggest you to do is to actually go program in C for some years, write some good software, and you will see what I mean. (from the OP's comments to another reader) Allow me to translate: Ok, let's stop bashing C. Let's start bashing people who have legit complaints about C. I don't think the above comment was warranted. Someone took the time to read your arbitrary article and attempt to offer a meaningful point and your response was to demean the fellow.
- bArray 10y agoI 100% agree with this article. I'm a student that has learned Python, Java and C - using each depending on what I need to do. Having taught as well, Python is not a language for beginners. They are punished for getting their spacing wrong, often confuse types, oo seems to have been an after thought and versions 2 & 3 are completely different languages. C can also be confusing for beginners, but not for the reasons mentioned. Teaching people about pointers spins heads for the first time. Java for me seems to be the middle ground. Good understanding of oo, portable code, solid types, well formed errors, beautiful garbage collection and well thought out (libraries, types, access, concurrency, etc). C is obviously an advanced language, but like PHP there is a good reason why it's not ready to be buried yet.
- defgeneric 10y agoOne of the things (among many) that does make python a good language for beginners is its short developer feedback loop. The pleasure of programming is important, so even if they're writing terrible code at first, there's a strong motivation to keep going. Along the way their skills develop.
- bArray 10y agoI agree, but this is achievable in other languages in the same way it is for Python - simply output something interesting via a package or library. First practical we have students drawing shapes in Java and crudely animating them.
- rtpg 10y agoSome of the issues defended here can be resolved if operator overloading weren't so prevalent. "++ is also used for iterators" Python has "next". I understand there's "*p++", but the semantics of ++'ing an integer or ++'ing an iterator are very different! Why should they share the same mechanism? (There's an argument that ++ on integers is iterating over N. Pedantically true) "Integer math is useful!" Floating point semantics are different, so why not use different operators for such? Caml has + for its, +. for floats. Impossible to mix different semantics together implicitly. -- I find saying "whitespace sensitivity makes auto-indentation impossible" to be a bit silly. The equivalent of auto-indentation in Python to C is auto-brace insertion! Just as impossible. There are definitely parsing difficulties with whitespace sensitive language (technocally, lexing difficulties). If you're willing to go for parenthetic function calls like in Python, it's not too hard. But go for Haskell-like function application and you're in for a treat! Would not want to have to parse Scala. I can see the argument to braces being better, though. It's such a subject of taste that if you don't want to be opinionated, going for explicit blocks is really your only choice.
- notacoward 10y agoEven more important, let's stop seeing bash. If somebody had set out to create a language prone to error and exploitation, bash would result. (It's fine for interactive use BTW, just not as a language in which to write anything complex or long-lived.) While it might not have C's pointer/memory problems, its lack of real types or scope rules and its other idiosyncrasies (e.g. making it nearly impossible to distinguish "" from an undefined variable or the whole $*/$@ mess) make it even more of a nightmare. I've actually gotten pretty handy with it because I had to, but it's a far worse crime against developer sanity than C ever was.
- seagreen 10y agoTotally agree! By the way, the Haskell community is working to make scripting easier in Haskell, so if you want to go from one of the most buggy languages straight to one of the least, now you can: https://docs.haskellstack.org/en/stable/GUIDE/#script-interpreter https://docs.haskellstack.org/en/stable/GUIDE/#script-interp... (Downsides: Haskell is weird (but good), you have to have Stack installed, and the first time you run the script it will take a while to download dependencies) More resources: https://github.com/Gabriel439/post-rfc/blob/master/sotu.md#scripting--command-line-applications https://github.com/Gabriel439/post-rfc/blob/master/sotu.md#s...
- nickpsecurity 10y agoIt was actually only recently that I realized how ridiculous bash was. I was looking for a formal semantics of it in reply to a comment here. I found nothing except a partial attempt by some academics plus a list of everything a real one would need. I thought "Holy crap, that's overcomplicated!" Interesting enough, a Scheme or even BASIC-like language with macros (eg 4GL) couldve handled about all that just as readably while building on a simpler, consistent core. Bash wasn't designed like that, though. So, I ditched it altogether except as compilation target.
- antiquark 10y agoAre people actually boggled by the "++" operator? If they can barely wrap their minds around that, why are they even in programming? Seriously!
- steveklabnik 10y agoThe problem with ++ is not understanding what it does. It's remembering exactly how to use it appropriately in the given context, and never making a mistake. And, the affect is multiplied by C's semantics, specifically, given that off-by-one pointer shenanigans can lead to Very Bad Things. So, tricky to use thing that blows up big when it does blow up. To make an analogy, I can perfectly understand null and what it does. My objection to null as a language feature is not based on not understanding it and what it does.
- SlySherZ 10y agoThere are two typical use cases for `++` and they should be considered separatly. Firstly there is simply the `i++`, which is redundant with `i+=1`, but it's also very easy to understand syntactic sugar. Keep it or leave it, no big deal. Then there is the more advanced and very subtle use of the return value: int i = 3; while (i--) { printf("%d, ", i); // What does this print? } This one is very controvertial. On one side, it simplifies and shortens code by a lot, but it also makes the code say too much at the same time. Can you tell by glance what this code would do? Personally, I prefer longer code and more expressive code, but I can also cut corners with the short version from time to time, when quickly testing something out. EDIT: Fixed code formatting
- drivingmenuts 10y agoIt seems to me that a lot of issues could be better handled if we weren't limited to programming in a subset of the ASCII char set. Unfortunately, the alternative is to completely retool the modern keyboard.
- dagw 10y agoWe've already been down that road: https://en.wikipedia.org/wiki/APL_(programming_language) https://en.wikipedia.org/wiki/APL_(programming_language)
- kstrauser 10y agoMy complaint against C is that some of the smartest people on the planet use it to write infrastructure that regularly fails catastrophically. If the experts who love it aren't capable of writing correct code, I have no chance whatsoever. Humans just aren't good at the fiddly bits (remembering to free(); not to free() twice; not to use after free(); accidentally adding a second clause to a non-bracketed if expression; how many times to we see these in vulnerability reports?). C is obviously very powerful. There's no denying that. But it does approximately zero of the things to help programmers that a modern language does. It's not even strongly typed in the usual sense (is there the equivalent of casting void pointers anywhere else?). Finally, C is slow. Yeah, you read that right. Its main problem is that it has no non-wizardry high level semantics for parallelism. For example, modern languages have map() to say "do this operation on all of these items". In C, you have to write that as "for each item in this collection, do this thing, then the next, then the next, ...". If the compiler is exceptionally smart, it might infer what's going on and help out. But with map(), you're explicitly telling the language "I want all of these things to be done" and it doesn't have to infer anything. I respect C. It's given us a lot of great stuff. But there's no way I'd willingly start a new project in C today given the alternatives. I am dumb, and given the choice between languages which help me and languages which are basically a small step up from assembler, I'm going with one that gives me a reasonable shot at writing safe, fast, and understandable code.
- dzdt 10y agoAre there any real world examples (with actual measurement) of languages where map uses hardware parallelisation to be faster than a c loop? Serious question! My impression is, no, outside of something like hadoop.
- lallysingh 10y agohttps://donsbot.wordpress.com/2007/11/29/use-those-extra-cores-and-beat-c-today-parallel-haskell-redux/ https://donsbot.wordpress.com/2007/11/29/use-those-extra-cor... This was a simple fib(), not a map(), but I think the point still stands pretty well.
- kutkloon7 10y ago
- pmarreck 10y agoIs there any room for a form of C with immutable semantics which forced you to jump through special hoops to get mutable data access (solely for performance reasons)... Or does Rust basically have this design goal already? The limitation of programming (from a bug-minimization perspective) is the programmer's ability to understand all the possible states his code and data can get into which means that the key to bug and security hole elimination is any pattern which reduces cognitive load
- pjc50 10y agoWell, you can sort of achieve that by writing C for a C++ compiler and sprinkling it with 'const'. Use of the standard library can then be inconvenient in places.
- saghm 10y agoI'm not sure I'd characterize it as "jumping through hoops", but Rust does lean strongly towards preferring immutabillity. Variables are immutable unless you give them the "mut" keyword when you declare them, and in cases where you need multiple pointers to the same data, it's impossible (outside of `unsafe` blocks, of course) to make one of them mutable unless you use a safe wrapper type like a`Cell` or `RefCell` (for single-threaded cases) or a `Mutex` or `RwLock` (for when you need to share access across multiple threads). But yeah, there's a strong bias towards immutability in Rust, although from what I understand this is more for safety than performance reasons.
- sidlls 10y agoI'm struggling to understand how requiring explicit mutability has anything to do with performance or "hoops." I mean, getting mutable access is trivial: let mut x = ... fn frobnicate(x: &mut...) The performance "problems" in Rust requiring "hoops" are in very narrow applications (e.g. certain applications of high performance numerical computing). I'm not a fan of the "unsafe-offset" idiom required so that every time access into a vector occurs doesn't waste cycles on a pointless boundary check (for example). But I must say for a given chunk of Rust code the equivalent C++ code is generally more bloated, because unless you're writing code begging for abuse you're going to have "const" and move operations everywhere, which is sort of inverted from Rust's model.
- kutkloon7 10y agoHating C because it has integer division is like hating haskell because it is functional. It is inherently low level. C's real problem is that is has undefined behavior in a lot of cases. C with some kind of compile-time memory protection and no undefined behavior (so basically Rust) would be a pretty sweet systems programming language.
- Manishearth 10y ago> What’s Wrong with Increment/Decrement? This sort of misses the point there. What eevee was saying was that "Usually you use ++ to mean +=1". It is equivalent to +=1 in those cases. Eevee then goes on to say "The only difference is that people can do stupid unreadable tricks with ++.". She is talking about postfix/prefix there. She never said that ++ and += are exactly the same, she's saying that they're mostly the same, except for some cases which often read to more unreadable code. Using i++ or ++i as an expression within a larger expression often leads to unreadable code. The author here then goes on to talk of off by one errors, but ++-as-expression is what causes a lot of off by one errors. https://news.ycombinator.com/item?id=13089663 https://news.ycombinator.com/item?id=13089663 explains this a bit too. --- The other two points also miss the point a bit. The post is not "why C is bad". The post is "Let's stop copying C". There are good reasons behind C having many of these features. These reasons do not necessarily port to other languages; yet they copy the feature.
- autognosis 10y agoI've seen these pixels before. C is a permanent fixture. It is not going anywhere in your lifetime. You can use it, or not. http://www.joshianlindsay.com/index.php?id=170 http://www.joshianlindsay.com/index.php?id=170
- agentgt 10y agoIn college (over 10 years ago) I used to think C was very viable. Sure it took longer to develop but the reward was fast execution and generally KISS like code (just an anecdotal observation I have of C is the tedium to write complex things forces simpler solutions... I mean who wants to malloc over and over). But near the end of college I had to write code using pthreads. It was awful. It was exceedingly painful. Banging on the keyboard cussing continuously painful. Maybe it was just pthreads (I'm sure there are nicer libraries) or my stupidity but that exercise killed my mild liking of C. Languages I like are heavily expression based but don't require braces (algol like languages) nor parenthesis (lisp like). As much I dislike braces and parenthesis (for blocks) I despise statement heavy languages more (sadly python). I wish the article of the "Stop Copying C" mentioned that (or maybe I only share that opinion).
- module0000 10y ago> But near the end of college I had to write code using pthreads. It was awful. For what it's worth, I don't think it's C's pthread library that is painful, but POSIX threading in general. Languages and libraries try to "simplify" threading by re-inventing pthreads. Eg: python's 'threading' module, erlang in general, java 'runnable' interface, golang's 'coroutine' thread manager...etc. The difference between all those languages specific threading implementation and POSIX threads, are that POSIX threads work across every language, and all those implementations are only relevant to the language itself. Working with "one size fits all"(pthread) tools is inherently more complex than a simplified tool specific to one language. Summary: once you learn POSIX threading [well] in C, using other pthread abstractions in other languages becomes much easier.
- agentgt 10y agoIf I recall it wasn't that I didn't understand the concepts but rather difficulty in debugging. At the time I was ignorant and ill experienced of proper tooling. Today when dealing with C I would probably not even bother with using threads and might just use multiple processes. I agree on the reimplementing POSIX threading and despite my rough experience pthreads was worthwhile learning about.
- 10y ago
- module0000 10y agoWriting performant interpreters is really hard. People wrote those performant interpreters in C because it was necessary. Rather than blog about what's wrong with C or C++, why not write re-write your Python or Ruby interpreter in Rust/Swift/Whatever - that should really show us dinosaur C/C++ programmers that we were wrong all along. PS: it's not as easy as you might imagine.
- Manishearth 10y agoThe original blog didn't blog about what was wrong with C or C++. It blogged about other languages blindly picking up design decisions from C even though they don't really have a reason to. And Rust has been consistently delivering software with performance on par with or faster than C counter parts. http://blog.burntsushi.net/ripgrep/ http://blog.burntsushi.net/ripgrep/ is a recent example. Servo is a more long term one.
- _petronius 10y agoFrom the original article: " Which is why we still, today, have extremely popular languages maintaining compatibility with a language from 1969 — so old that it probably couldn’t get a programming job." Yikes! How about "old enough to have a crapton of experience I'd really like to learn from/integrate with my company"? I know there is ageism in this industry (towards both people and tools), but sometimes the cavalierness with which people throw out the idea that "old == bad" and "good == new" comes as a shock. And besides that, shouldn't we be proud of half a century of stability and compatability? Isn't "well-designed systems that stand the test of time" a holy grail to reach for, rather than poke fun at?
- deleted 10y ago[deleted]
- VT_Drew 10y agoI will stop bashing C when C code looks as beautiful as Python code.
- smitherfield 10y agoOf all the problems C has, looking ugly isn't one of them, and most of the ugliness would be done away with if the language adopted a proper module system and C++ "constexpr". The Linux kernel in particular is quite nice to look at: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/kernel?id=v4.9-rc7 https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux....
- Pica_soO 10y agoOnly if C stops bashing us first- it started it.
- Pica_soO 10y agoAnd of course engineers and architects are blameless on this - we would not allow for gradual replacement, no, Sir , we need a revolution, tear down this Wall and build a brand new Castle in the sky. Nobody wants to weld new things to a rusty Compiler, until the Compiler is all rusty, but still fully able to bind all the legac inertia factor to his will.