Elm 0.19 does a great job of not compiling code in your Elm modules that you don’t actually use.
At the same time, there is a long convention of using let expressions with Debug.log to check the values of things during development:
let
_ =
Debug.log "what is this?" something
in
div [] []
The above code will render an empty div, but will also log the message to the browser console.
My question is: does Elm 0.19’s dead code elimination ever optimize out let expressions like the one above? Perhaps when building with --optimize (were Debug.log is not allowed, of course)?
I’m wondering if leaving unused let expressions lying around bloats the compiled output, or if the compiler cleans them up along with any other unreferenced functions in the module.
From Evan’s blog post (Small assets without the headache), dead code elimination in elm is function based. Let expressions not being a function, it makes sense that they are not eliminated.
elm-analyze already detects and marks unused declarations inside let so, I would not be surprised if this kind of dead code will be removed in future versions of elm.
There are no concrete plans to change the behavior at some specific time, but as the optimizations in the compiler improve, we will likely be able to strip out more and more. To enable those kinds of optimizations, I think it would be necessary to give a “unused variable” error in cases like this so that people do not spend an hour wondering why the code they wrote is not executing. This would need to be in a major release though, so anything in the 0.19.x series should be the same.