10 ms·
> If you know what you're doing (and you should) then C is the best tool for the job. Empirically, nobody knows what they're doing, if "knowing what you're doi
by pcwalton 10y ago
> If you know what you're doing (and you should) then C is the best tool for the job.
Empirically, nobody knows what they're doing, if "knowing what you're doing" is defined as "writing large-scale C code without memory safety problems".
I hear a lot from C and C++ enthusiasts that there are lots of programmers out there who always write correct C and C++ code, and therefore we don't need new languages. But I've never found one of those programmers. Can you name one?
- TickleSteve 10y ago(see the reply to the above response). Basically, in day-to-day use, the flaws in the language are easily manageable. Resource (memory) management is a skill that should be a given. Yes, there are well publicised failures in this regard, but consider the number of problems versus the actual number of lines of code written.
- pcwalton 10y ago> Yes, there are well publicised failures in this regard, but consider the number of problems versus the actual number of lines of code written. I think that's a pretty misleading metric when you take into account: (1) widely used codebases constantly increase in size constantly; (2) it only takes one exploitable mistake for an attacker to achieve remote code execution. One exploitable vulnerability per 10,000 lines means 1,200 remote code execution flaws in a codebase the size of Chromium.
- jjnoakes 10y agoNo one "always writes correct large-scale code". I have worked with many who write large-scale C and C++ code with no undefined behavior. Is that what you meant?
- pcwalton 10y agoYes. I've never seen it. All large-scale C and C++ codebases I've ever seen, from large companies to small ones, have had memory safety/undefined behavior problems [1]. If "just hire better programmers" were a workable solution, surely one company out of {Google, Apple, Microsoft, Facebook} would have succeeded at that strategy by now. It's very easy to write C and C++ code that looks like it's free of undefined behavior, but in every case I've seen they end up falling when attackers actively try to look for problems. [1]: Maybe qmail is the one exception, though even that had a famous debate related to overflow.
- jjnoakes 10y agoHave you ever worked with teams who use aggressive static analysis tools to detect and catch undefined behavior? Because I have, and it works incredibly well. Of course, the caveat is that once you turn up the static analysis aggressiveness (assuming you use a good static analysis tool), you will need to put in plenty of assert(index < len), ownership annotations, and other such items in your code to satisfy the checks. But once you do, it's really hard (probably not impossible, but really hard) to trigger undefined behavior without the static analysis tool catching it. Because if the tool decides it can't prove there's no undefined behavior, it is configured to complain, and you adjust the code until it stops. I'm not saying many teams do this, but I am disputing that no teams do this.
- vardump 10y agoWhat tools do you recommend?
- jjnoakes 10y agoUnfortunately I have never used one available commercially which meets my needs. We author one in-house.
- nickpsecurity 10y agoYour tool is better than Astree Analyzer and Polyspace? I think you should consider GPLing or licensing it with commercial support. Judging from their prices & effectiveness, you'll make a killing doing better while undercutting their licensing.
- jjnoakes 10y agoThe problem is usability and licensing costs. Our in-house tool is amazingly powerful and fits our needs but the usability would need improvement (no surprise) and we license some of the utility code we use (which is cheaper if we don't resell our tool).
- VLM 10y ago"large-scale C code" I hope to never own a microwave oven with a large scale codebase. Also my basement dehumidifier. And my waffle iron. And my clothes washer. And my digital dial caliper in my workroom. There's a surprising amount of money in "you are now a timer" and "you are now a thermostat" and "you are now a thermometer" and very close analogies.
- vardump 10y agoWashing machines actually have quite a bit of code. Car ECUs have even more. Elevator control systems are pretty big. Medical devices have huge codebases. You'll definitely use or own something that has a somewhat large codebase.
- nickpsecurity 10y agoMine doesn't. When my washer broke, I called some locals that have a warehouse full of them and repair them. I asked whether it was their opinion, being experts, that my observation about the older ones being more reliable was true? The guy confirmed that older ones easily last a decade or so with new, computer-filled ones breaking all the time. Said they're good business for him. Sold me what he claimed was a good model of older ones he had for under $100. I was surprised when he told me the one that broke was around 20 years old. That is both reliability and return on investment. :)
- imtringued 10y agoThat is mostly because the newer washing machines replace what used to be steel with plastic to cut costs.
- nickpsecurity 10y agoI'd believe it. He said the electronics screw up, too. He was fixing a control system on one that was just a few circuits in the knob on older ones.