3 ms·
I'm not convinced lack of side effects is the thing that lets you build tools that prompt removal of code in this way. In OCaml, if you had an unused variable l
by sweeneyrod 6y ago
I'm not convinced lack of side effects is the thing that lets you build tools that prompt removal of code in this way. In OCaml, if you had an unused variable like in the example you would get a compiler warning about it, and 99% of the time the compiler is right that you should delete the code. It's perfectly possible in principle that computing the value could have side effects. But in good (OCaml) code, you should very rarely have functions that have side effects and return a value other than unit. So the compiler is almost always right in practice (and you can still use side effects when you want to interact with the outside world, which is handy).
- habitue 6y agoThe difference between "should be safe if your ocaml code is good" and "is safe" is the thing that allows you to use tooling to delete the code. Otherwise the best you can do is lint and rely on a human to use their best judgement about whether to remove it or not.
- kazinator 6y agoAnd then there is C++. The C++ language allows temporary objects to be generated and/or optimized away. Those objects can have constructors and destructors with side effects, and those side effects appear or go away together with the object to which they are attached. If your program depends on whether a temporary object does something or not, you are officially screwed.
- sweeneyrod 6y agoelm-review still has a confirmation prompt though, right? You don't want to instantly remove an unused value, because you might be in the middle of writing code and about to use it.