3 ms·
Rust will generate a lot of guarding code similar to what ada does.
by nurettin 6y ago
Rust will generate a lot of guarding code similar to what ada does.
- kibwen 6y agoThe only "guarding code" that I can think of Rust generating would be for bounds checking on array access, which isn't going to be any significant contributor to binary size. When it comes to generated code, I can imagine the panic unwinding code being a noticeable contributor to the size of a Rust binary, but since D has exceptions I imagine the D binaries have comparable code for unwinding.
- nurettin 6y agoYes, it will generate Exception unwinding and bounds checks and godbolt seems to agree. Anything else you can think of? I think D is less strict when optimizing out exception code.
- mhh__ 6y agoException unwinding is not particularly cheap on the compiler although I think it's in the sense that it muddles the CFG and the register allocation rather than inserting huge amounts of code. The LLVM codebase has exceptions turned off for those reasons and binary size (it plays a role at their scale) although its quite hard to compare exceptions Vs error codes or monads for obvious reasons (LLVM's coding standards are rightly or wrongly a C++ sleuths dream with their custom dynamic casts etc.)
- mhh__ 6y agoD also generates significant amounts of said code (unless you turn it off, obviously) One feature D stole from Ada that is an absolutely inexcusable ommision in a modern programming is contract programming. Every time I start a new python script I end up writing helpers for function pre and postconditions because otherwise I can't rely on anything in the language's syntax. Invariant clauses in D (e.g. this integer in my struct must be less than 5 when the struct is in a valid state) are an absolute godsend although they do not aid compiler optimisations despite some people saying otherwise (it could have changed but last time I checked the invariant does not make it's way to LLVM or GCC)
- ponsin 6y agohow is that different than in c/c++ simply adding asserts at the start and end of functions?
- mhh__ 6y agoIt's the same but it's a different switch to turn it on and off. Having separate syntax is also very useful because it's much easier to see through my usual spaghetti to find what the code is actually supposed to do in the abstract (i.e. if the string should be a valid email, check it in the in {} clause rather than in the middle of the function)
- noch 6y ago> One feature D stole from Ada that is an absolutely inexcusable omission in a modern programming is contract programming. Incidentally, Walter Bright considers contracts to be a low value feature of D that he considered removing. [0][1] [0]: https://youtu.be/p22MM1wc7xQ?t=1h34m30s https://youtu.be/p22MM1wc7xQ?t=1h34m30s [1]: https://digitalmars.com/articles/hits.pdf https://digitalmars.com/articles/hits.pdf