The new error message (1) suggests a fix and (2) gives examples to help teach the overall rules.
I encourage you to try to make naming errors in a language you are already familiar with. Can you imagine making that mistake when you started with the language? How is the error message? Would you know what it meant if you were just learning to program?
Survivorship Bias
Trying to improve error messages seems like a worthwhile idea, so why is it uncommon for compilers to have syntax error messages like this? And why did it take so long for Elm to prioritize this project? I think part of the answer is survivorship bias.
Syntax errors are highly concentrated in the first weeks with a language, and people are particularly vulnerable in this time. When a beginner asks themselves why something is hard, it is easy to think, "Because I am bad at it!" And it is easy to spiral from there. "I heard it was hard. I was not super confident I could do it anyway. Maybe I just suck at this. And if this is what programming feels like, there is no chance I want to be doing this with my life!" People who fall off the cliff cannot share their perspective in meetups, online forums, conferences, etc. They quit! They are not in those places!
As for people who make it past the cliff, many do not shake off that initial confidence blow. They use the language, but not with enough confidence to think that their problems should be handled by a language designer. "Oh, that again. I will never learn!"
So language designers never really hear about this problem. I only understood its magnitude once elm/error-message-catalog
got going. That repo solicits confusing error messages in hopes of finding ways to improve. I think projects like that legitimize the idea that "error messages should be better" such that I started hearing from a broader range of people. (Not just the very non-random sample of users that participate online!)
I personally think survivorship bias is a huge trap for language designers when it comes to prioritization. "Everyone is telling me to work on something else!" I find it really hard to put that aside even when I know "everyone" is actually a very particular sample, and I imagine it is only harder for language designers at the big firms with bosses prioritizing adoption by existing programmers over everything else. "Is this language bringing developers to our cloud services? Is this VM bringing people to the default search provider in our browser? Is the reputation of this project making talent acquisition cheaper?" People who work on programming languages understand the implicit conditions of their employment, and it varies a lot by project.
Point is, I hope this work on syntax error messages will help make Elm more friendly and accessible, and I hope it will help make space for other language designers to prioritize this kind of project!
Try it out
If you are interested in exploring the new syntax error messages with Elm 0.19.1, you can experiment with examples in our online editor or start working through the The Official Guide.
I am sure there are ways the messages can be improved further, so I encourage you to share any confusing error messages in elm/error-message-catalog
if you run into a tough one while learning!
I appreciate folks taking the time to give Elm a shot, and I hope it is fun to explore!
Thank You
A lot of folks helped out testing Elm 0.19.1, but I want to specifically thank @jfmengels for stress testing the syntax error messages and @hrk for reading the 5800+ line syntax error file straight through! Both found a bunch of ways to improve the error messages even more.
I also want to thank the folks who have reported confusing error messages to elm/error-message-catalog
over the years. It has been extremely helpful in inspiring and guiding projects to improve error message quality.
Thank you!