11 ms·
I'm quite bored by the obsession of some for replacing C. Yes, it does exactly what you tell it to do and that's dangerous. It was a high level language 25 yea
by colechristensen 9y ago
I'm quite bored by the obsession of some for replacing C.
Yes, it does exactly what you tell it to do and that's dangerous. It was a high level language 25 years ago, but today the metaphor should be assembly. Nobody would criticize assembly for letting you shoot yourself in the foot, C is much the same.
The biggest threat to the tech sector is Linus dying and being replaced by some charlatan who insists on replacing C and using Jira.
</offtopic>
- tonyedgecombe 9y agoYes, it does exactly what you tell it to do and that's dangerous. Exactly, if you could get all the benefits without the danger why wouldn't you?
- bluejekyll 9y ago> it does exactly what you tell it to do and that's dangerous. gcc: “hold my beer while I optimize out that block of code you clearly didn’t mean to be in your program”
- hashmal 9y agoThat's not because of C, that's because of GCC.
- adrianratnapala 9y agoIt's because of C as it has been redefined in recent times, but the kinds of people who write standards and compilers. The galling thing is that they did this to win a benchmark war against Fortran.
- int_19h 9y agogcc does it precisely because the C standard says that it can do so, and any program that's relying on not getting broken that way is not valid C (well, "undefined behavior", but it's the same thing in practice).
- pkolaczk 9y agoWhere exactly does C standard explicitly say it can do so? UB was introduced to allow skipping checks that otherwise might have added overhead, like array bound checks or null checks or to give more flexibility to how correct programs are optimized (e.g. freedom to evaluate arguments in any order). Therefore each compiler/library/os vendor could implement these cases differently. However, it was never meant to allow compiler to assume "ok, I can see your code is totally broken, so let's break it more, cause you don't care anyway".
- steveklabnik 9y agohttp://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf is the draft of the C11 spec, 3.4.3 undefined behavior behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message). ------------- Even if you want to argue over what "imposes no requirements" means, I'd argue that "ignoring the situation completely with unpredictable results" is very clear. The note also says (and elsewhere in the standard it reinforces this) that since there are no requirements, implementations could absolutely do things like perform runtime checks, etc. Compilers do not do this though. This isn't for no reason, but that's a separate issue.
- loup-vaillant 9y ago> However, it was never meant to allow compiler to assume "ok, I can see your code is totally broken, so let's break it more, cause you don't care anyway". That's nevertheless how compiler writers are interpreting the standard right now. Take integer overflow for instance. Stuff like this: unsigned u = some_computation(); int x = u; // because of reasons x += 42; // hmm this may overflow, let's check that if (x < 0) { // It's a 2's complement machine, this'll work handle_overflow(x); // now, let's deal with the overflow } Now here's how your optimising compiler see that stuff: unsigned u = some_computation(); int x = u; // x is always positive. x += 42; // signed integer never overflow if (x < 0) { // x was positive, no overflow... always false handle_overflow(x); // Let's delete this dead code. } Then, what actually happens: unsigned u = some_computation(); int x = u; x += 42; This is insane.
- DougBTX 9y agoThe example of optimizing in a block of code that is never explicitly called is even more fun: https://kristerw.blogspot.co.uk/2017/09/why-undefined-behavior-may-call-never.html https://kristerw.blogspot.co.uk/2017/09/why-undefined-behavi...
- jwilk 9y agoHN thread: https://news.ycombinator.com/item?id=15324414 https://news.ycombinator.com/item?id=15324414
- edmccard 9y ago>Nobody would criticize assembly for letting you shoot yourself in the foot, C is much the same. But I bet they would criticize programs for being written in assembly, if they didn't need to be. If you could have a language with all the performance of C without the footguns, why wouldn't you want that?
- chii 9y ago> a language with all the performance of C without the footguns, why wouldn't you want that? I've yet to see a language that actually delivered on this claim.
- bluejekyll 9y agoPerhaps you aren’t looking? Rust delivers on all these claims. And there have been others before it. Rust hits all the sweet spots for me.
- z3phyr 9y agoRust is very sweet, but it lacks the simplicity of C. I get that ML style programming is all the rage today, and ML itself is a simple language, but programming languages today carry a lot of baggage and styles, maybe to cater to wide range of programmers. But in the end, it complicates the language. I have noticed that a lot of people find Rust or Scala to be very hard because of these reasons.
- hsivonen 9y agoThe simplicity of C relative to Rust is an illusion in the sense that the main thing that makes Rust feel difficult at first ("fighting the borrow checker") relates to a concern that's relevant to C (allocation lifetimes), but in the case of C the burden of dealing with the issue is on the programmer and not on the compiler.
- Ygg2 9y ago> Rust is very sweet, but it lacks the simplicity of C. That's like saying a SawStop (http://www.sawstop.com/ http://www.sawstop.com/) lacks a simplicity of a sawblade. I mean - Yeah, sure, but sawblade also won't stop you from turning yourself into amputee. I understand Rust can be overly verbose, but main complexity comes from the borrow checker and the effect adding another kind of type, to track lifetimes. The lifetime system is the main selling point. There are other sources of complexity in Rust, but I am glad to say both Rust/Scala seem to be looking for a way to simplify things.
- danieltillett 9y agoI don't worry about Jira, but I do worry about someone replacing C.
- rbehrends 9y agoI would be (mostly) fine with C for the purposes it's designed for if each C compiler were required to have an option that makes the compiler use implementation-defined behavior everywhere. This would make C more like a portable assembler and less like the software engineering version of "do you feel lucky, punk?" As it is, lots of major C applications already do this on a piecemeal basis and use one or more of: -fno-strict-aliasing -fno-strict-overflow -fno-delete-null-pointer-checks with gcc to keep a lid on the effects of undefined behavior (and often more or even stricter options, such as -fwrapv). The problem is that even experienced C programmers can get tripped up by undefined behavior all the time. "Yes, it does exactly what you tell it do" doesn't really cut it when the vast majority of actual humans cannot safely predict the effects because they're so unintuitive. Or, in the words of Douglas Adams: "But the plans were on display . . ." "On display? I eventually had to go down to the cellar to find them." "That's the display department." "With a torch." "Ah, well the lights had probably gone." "So had the stairs." "But look, you found the notice, didn't you?" "Yes," said Arthur, "yes I did. It was on display in the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying 'Beware of the Leopard'."
- colechristensen 9y agoHow possible do you think it is to create a new language which is almost, but not quite, exactly the same as C? Edge cases that have evolved into it do have plenty of problems, but it's very difficult to create a new backwards-incompatible standard which is just a little bit different. Then again, the embedded (microcontrollers) world seems to be filled with slightly esoteric implementations of C and everybody gets along just fine.
- rbehrends 9y agoAs I said, I think that basically doing a global search and replace of "undefined" with "implementation-defined" in the standard would be a good first attempt (this should be possible, because that's how C compilers worked for a long time and – with optimizations turned off – generally still do). This wouldn't solve everything, but it makes the use case for C as a "portable assembler" better, which could then be used as a foundation to build upon.
- zokier 9y agoAs others have already alluded, the problem with C is not its low level nature or that it allows you to shoot yourself in the way asm does. The real problem are the arcane unintuitive rules of ISO C standard that in comparison to asm footgun is more like carrying a critical lump of plutoniun in your pocket that might go off at any point.
- stinos 9y agoI'm equally bored with the apparent obsession of some to hate on Jira. It's a dev tool like any other meaning for some it works wonderfully well with some quirks here and there. Hmm, like C, I'd say. And I use and like both.
- jsight 9y agoWell, in fairness, JIRA has tried to evolve well beyond the role of a mere bugtracker. Between the complex workflows of its large existing userbase, the huge complexity of the code, and the desire to use it for project management, it has become really slow and painful both to use and to develop. I've heard some horror stories and apparently the development team is pretty heavily pressured to fix a lot of things.
- booleandilemma 9y agoHas Linus ever talked about appointing a successor?
- pg_is_a_butt 9y agoyo momma
- throwme211345 9y agoI love you man.
- pjmlp 9y ago25 years ago it was a middle-level language. I hardly saw any reason to use it instead of Pascal dialects, besides being "the language" on UNIX systems. Thankfully Bjarne created C++.
- staticassertion 9y ago> I'm quite bored by the obsession of some for replacing C. That's fine... but the billions of dollars spent on security and the massive trove of user data that's been exfiltrated due to C is kinda a problem regardless of whether you are bored or not. > Nobody would criticize assembly for letting you shoot yourself in the foot, C is much the same. I wouldn't criticize a developer for writing bad code. I'd criticize the language for letting them, or the developer for choosing such a language. Same with C and Assembly. > The biggest threat to the tech sector is Linus dying and being replaced by some charlatan who insists on replacing C and using Jira. That is... not the biggest threat. It seems extremely unlikely that that is where linux kernel development would go.
- sidlls 9y agoIt isn't "due to C." This is a popular meme on HN, but it's incorrect in its focus. If anything replaces C I'm skeptical that more than a shift in the character of the attack surface (rather than the area) will occur. That is, there will be just as much to attack, it's just that the attacks will require alternate methods. Some attacks will be harder to employ, some less, but on average probably about the same quantity and seriousness will occur.
- staticassertion 9y ago> It isn't "due to C." This is a popular meme on HN, but it's incorrect in its focus. You can call it a meme but that doesn't change my opinion. > Some attacks will be harder to employ, some less, but on average probably about the same quantity and seriousness will occur. This is unfounded, I don't really know how to respond to it other than that nothing has ever really worked this way in security. You don't get less secure in one area because you were more secure in another.
- sidlls 9y ago> You don't get less secure in one area because you were more secure in another. I agree with you, however that doesn't address what I actually wrote.
- moosingin3space 9y ago> I'm quite bored by the obsession of some for replacing C. Well, I'm quite bored of the endless stream of memory safety vulnerabilities that can be systematically eliminated with memory-safe languages like Rust. Note that every single one of the CVEs disclosed yesterday in dnsmasq are memory safety violations, and the fact that buffer overflows, data races, and other related errors are not only pervasive, but also tend to sit around for years in codebases[1]. > Nobody would criticize assembly for letting you shoot yourself in the foot, C is much the same. It's completely acceptable to criticize the choice of any tool. I can and do criticize the use of C for any code that touches a network and in some cases consider it willful negligence, as using a non-memory-safe language to parse untrusted data is asking for trouble. [1]: https://twitter.com/johnregehr/status/914663997647069184 https://twitter.com/johnregehr/status/914663997647069184
- tempodox 9y agoWhen you speak of “parsing untrusted data”, do you mean to imply that “parsing trusted data” even exists? I for one would view any and all input as untrusted.
- moosingin3space 9y ago"Trusted data" can exist in theory -- on a closed network where you control all endpoints -- but does not exist in practice (as many devices eventually connect to the Internet or exchange data with Internet-connected computers). Therefore, it follows that re-writing parsers in memory-safe languages would provide a nice bang-for-buck.
- TheCoelacanth 9y agoIn some cases, say the parser for an interpreter for a general purpose programming language, I would consider the data "trusted". You are already allowing execution of arbitrary code, so there is nothing to be gained by exploiting the parser.