It seems like all the resources here are concerned with trying to whittle C/C++ into an appropriate choice of tool, rather than choosing a different tool. It seems like a 1980s-1990s mindset.
It seems like all the resources here are concerned with trying to whittle C/C++ into an appropriate choice of tool, rather than choosing a different tool. It seems like a 1980s-1990s mindset.
Units can help verify that a formula within a program is correct (velocity v = 0.5(metric_acceleration)9.8 t;cout<<v.to_metric();) won't compile, for example.
But it won't help with Program 1:
velocity_imperial v = 0.5(metric_acceleration)9.8 t* t;cout<<v;
Program2:
velocity_metric v; cin>>v; BurnFor(doSomeRocketScienceToCalculateEngineBurn(v))
A much more robust method (especially considering that this table was prepared in advance) would have been to have someone else to independently duplicate the work and compare results.
For how much longer?
The machines running self-driving cars aren't tiny little processors running single threaded code. They're basically full server racks worth of compute with multi-core cpus, gpus, and who knows what else.
The current approach of "use crufty-but-trustworthy hardware and never do anything too complex" doesn't scale to the next generation of "embedded".
One of the major hurdles to real Level 5 systems is proving their correctness.
There's the rub. They don't meet the standards of safety-critical code, but they are safety critical.
I'm not sure how this challenge will be addressed, but I doubt the answer is "write everything in C". That approach works when your code is relatively simple, but doesn't scale when the code is actually extremely complex.
https://hackernoon.com/five-skills-self-driving-companies-ne...
A team of software engineers can then implement that with static analyzers and run time checkers during development to give confidence to an implementation.
Can you prove stability of a deep learning system across all possible operating conditions it may encounter?
I was thinking more of self driving though.
> you don't trade away stability for performance on a safety-critical chip!
In a sane world, no. But we don't live in a sane world. We live in one where (on one system I worked on) it turned out a plane having an overheat (not fire) on one engine would cause the overheat on the other to fail to report to the pilots (corrected or I'd name and shame). And that wasn't just an issue of language, but of sound (or unsound in this case) logic. No one sits down and develops these things correctly. 10k lines of code (at most) on that project and most of it was just cobbled together in an ad hoc fashion.
The main problem is that C and C++ won the political war and many devs don't even bother to look elsewhere.
Actually even C++, in spite of its safety improvements over C, has issues to cater to embedded devs.
Thankfully the IoT of shame is already making people aware that another path has to be taken.
There are legitimate gripes about C/C++, especially in a space with hostile actors an unknown inputs, but that example was particularly weak.
That this is a mistake that is possible to make in any language, but nevertheless this is also a problem that could be caught by a sufficiently good type system, if it was put to sufficiently good use. In fact, part of the justification for allowing user defined literals in C++ was precisely to make it easy and convenient to avoid mistakes like the Mars Climate Orbiter. Bjarne Stroustrup himself used that as an example in at least one talk he gave about C++11.
https://blogs.msdn.microsoft.com/andrewkennedy/
https://channel9.msdn.com/Blogs/Charles/Andrew-Kennedy-F-Uni...
"Better" / richer / more refined (aiming/aspiring at least!) type systems than C/++/Java/C#/Go/etc aim to make it ever-more "powerfully convenient, effortless, and free-of-cost to denote eg. such different units as uniquely distinct (yet 'compatible' when explicit conversion is finally expressly (and visibly (and searchably)) called for) types" that all source code cannot possibly mismatch accidentally without the compiler catching it --- however the issue remains that we don't, and possibly can't have type systems that also enforce such styles (rather than just relying on a developer's/team's own discipline & resolve to adhere to such convention even in the face of deadlines & budget/schedule pressures) unless we actually totally forbid primitives like lone (semantics ambiguous) ints, lone (likewise) floats etc. Similar to "bool blindness", there's the general issue of "primitive/scalar-type blindness" always lingering. Probably some PhD candidate will write a Haskell extension for such a scenario some day soon.
Though of course the next thing the deadline-driven developer will do is construct a single "semantic" int type used for all different semantic sorts kinds and types of "ints"......
int temperature_a;
int temperature_b;
or even: Temperature a;
Temperature b;
you would have: Celsius a;
Fahrenheit b;
And an assignment between a and b would be an error, as Celcius and Fahrenheit are different types. Going along this path then, if you can extend the type system enough: Yards width;
Yards length;
Acre size = width * length; /* this would be okay */
Yards width;
Yards length;
Yards height;
Acre money_bin = width * length * height; /* error */
/* as acre is a measure of area, not volume */
Think of the type of calculations that the Unix command 'units' does, but built into a language instead of an application.You could wrap your value in a typed data structure:
enum LengthUnit {
Feet(f64),
Meters(f64),
}
And provide conversion functions between them, then only operate on one type, `LengthUnit::Meters` and throw errors if `LengthUnit::Feet` is passed in.I'm using Rust syntax here because it's fresher on my mind, but you could do the same with Haskell, OCaml, F#, etc. IIRC, OCaml would optimize away the outer structure so you wouldn't have much/if any performance hit. Presumably compilers for the other languages could/would do the same.
EDIT: for formatting and clarity.
So as weird as this may seem to you, that mindset is applicable much more recently than you might expect.
1. There was a spacecraft (MCO) and a module that was sending some data from the Earth.
2. The module was delivered late when MCO was on its way for 4 (!) months already before that staff manually calculated the needed data.
3. Some teams switched into "defensive mode" not willing to communicate and fixing the problem when it was clear.