Folks who prefer dynamically-typed languages are generally of the opinion that working with compiler error messages sucks. Now before anyone goes into a tired treatise about the virtues and benefits of types, think about the actual concern here. A lot of compiler error messages actually do suck. Some of them suck quite a lot. What happens when we accept that there is a problem here and try to do better?
Ease of use is a major priority in Elm, so I recently took a couple weeks to really focus on this. I learned that you can make a shockingly huge difference just by thinking about the user experience. I am not ready to claim that we totally solved things and have the best error messages ever, but many folks are very excited about our progress so far.
This post is going to go through a couple concrete user experience problems that show up in every compiler I have used, showing how Elm 0.15.1 is starting to improve the sorry state of compiler errors.
Finding the Relevant Code
Before you can resolve an error, you need to find the code causing it. Seems pretty obvious.
With many compilers you get a location like program.x:43:22
that you have to
decipher. Where is that file? Which one is the line? Which is the column? Okay,
let me scan through my code. You also often get a pretty-printed version of the
problematic code, but it looks nothing like the code you wrote. You again need
to do a mental transformation to find it. So a lot of time is lost:
- converting row and column numbers into an actual file position
- converting pretty-printed code onto actual code to verify that position
The new Elm 0.15.1 error messages combat both problems directly.