6 ms·
Ask HN: Would it be educational to map error messages to common mistakes?
This question is just a musing, a "shower thought" if you will.
I have a JS/Python/Java background (side projects can be much lower level though such as C++ or x86-64 ;-) ). I'm currently learning Go from Learn Go With Tests [1]. And I sometimes make silly mistakes such as testAdder instead of TestAdder (lowercase t vs capital T). In that example I got back "testing: warning: no tests to run". I had to use a search engine to find out why. I don't find it a big deal, but I am simply wondering if there is a more efficient way to deal with this problem of understanding "cryptic" error messages when you're starting out in a new language.
So, might it be useful to have a site for programmers starting out in a new language that could give potential causes when a particular error message is displayed?
[1] https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/integers https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/...
- brudgers 5y agoSome people believe the best place to handle this problem is the compiler or runtime themselves by generating non-cryptic error messages. I believe Raku takes this approach.
- mettamage 5y agoWow, it has quite some history behind it [1]. [1] https://en.wikipedia.org/wiki/Raku_(programming_language) https://en.wikipedia.org/wiki/Raku_(programming_language)
- b2gills 5y agoIt certainly does. (Or rather Rakudo the compiler for Raku does.) There are some for people coming from Perl. say $^V; ===SORRY!=== Error while compiling: Unsupported use of $^V variable; in Raku please use $*RAKU.version or $*RAKU.compiler.version ------> say $^V⏏<EOL> Some for simple typos. my $morning = DateTime.now.truncated-to('day').later( :9hours ); say $moroning; ===SORRY!=== Error while compiling: Variable '$moroning' is not declared. Did you mean '$morning'? ------> say ⏏$moroning; There are some errors that it can't find until it runs your code. say $var.length; No such method 'length' for invocant of type '...'. Did you mean any of these: 'elems', 'chars', 'codes'? (I omitted the type because it doesn't really matter.) The reason Raku doesn't use `length` is because of the common Perl error of calling `length` on an array. In Perl `length` is a string operation. It would turn your array into a number representing the number of elements, and get the count of characters in that. So it would give you a number representing the order of magnitude of an arrays length. In order to catch this error, and to reduce the number of times it happens, `chars`, `codes`, and `elems` were chosen instead. (Functions in Raku are intended to do a single operation on a single type. If the argument isn't that type it often coerces into that type. `elems` for example is a list operation, so something like `Str.elems()` always returns `1`.) Most exceptions are in https://github.com/rakudo/rakudo/blob/master/src/core.c/Exception.pm6 https://github.com/rakudo/rakudo/blob/master/src/core.c/Exce...
- roetlich 5y agoCheck out the kind of error messaged you get from Elm: https://elm-lang.org/news/compilers-as-assistants https://elm-lang.org/news/compilers-as-assistants In practice, they can be very helpful and clear. But often they are too long, so I end up not reading them.
- karmakaze 5y agoI've seen a number of things that relate to this: 1. a printer troubleshooting site where the only question is "What brand/model of printer do you have?" It suggests the most common problem, and most often it's the rignt answer. 2. Sorbet is a static type checker for Ruby that will make suggestions for typo's similar to your example. It also has an autocorrect option, but use with care because sometimes it will choose the closest but completely unrelated name. 3. Error messages that are/have clickable links, which take you to a site that has entries from people who got this error and what they found caused and if known fixed it.
- gamerDude 5y agoWoah. #3 just blew my mind. What if we had a package for every language that linked the error to the top stack overflow thread or equivalent.
- vuciv1 5y agoI wanted to make this for myself in my terminal. It would read error output, search in a database I have, and then output how I fixed that error last time I received it. I am not quite sure how to intercept and inject terminal output though
- kubanczyk 5y agoI prefer we had generic search engines for the raw textual error messages. This reduces the fragility and vendor lock-in (like SO). Which is exactly the current situatuon.
- melvinroest 5y agoI prefer having both. Perhaps there's some opt-in/opt-out flag that allows you to not make clickable links. But having a database with most common errors sorted by programming experience in that particular language might be quite useful. I wouldn't be surprised if it would allow a programmer -- being a beginner in a new language -- quickly find his/her mistake most of the time.
- brundolf 5y agoThe rust compiler does this, and it’s been generally well-received: https://rustc-dev-guide.rust-lang.org/diagnostics.html#suggestions https://rustc-dev-guide.rust-lang.org/diagnostics.html#sugge...
- ivan_ah 5y agoThere is a very cool "explain the exception traceback" package for Python: https://github.com/aroberge/friendly https://github.com/aroberge/friendly See this video for explainer and demo: https://www.youtube.com/watch?v=TmLnX7opisQ&t=678s https://www.youtube.com/watch?v=TmLnX7opisQ&t=678s It's based on case-by-case analysis and recognizers for the most common mistakes: https://github.com/aroberge/friendly/blob/master/friendly/runtime_errors/import_error.py#L20-L50 https://github.com/aroberge/friendly/blob/master/friendly/ru...
- maerF0x0 5y agoBasically this is the concept of stackoverflow. People (hopefully) post their error messages and then others answer. That being said if it could so easily be answered, then one might wonder why it the computer doesn't fix it for you? I would suggest that there is often sufficient ambiguity about what the programmer desired that the compiler (or other tools) cannot just correct it.
- azhenley 5y agoThere’s been several dissertations on this topic and a lot of research tools. Compiler errors are [slowly] getting better.
- neolog 5y agoCould you link one or two to give us a hook?
- gumby 5y agoThe trade off is that sometimes only the highly technical answer can give insight, and the more experienced the developer the more useful the technical answer is. That being said, gcc and clang have started to put in suggestion-like responses. Answers don’t have to be obscure, especially not for obscurity’s sake. But all is not lost. You (or somebody) could write a utility that read the compiler output through a pipe and gave more verbose messages
- gothungry 5y agoDefinitely, whenever I come across informative / helpful error messages I'm able to move faster. There is a nice write up from the creator of Keras about this: https://blog.keras.io/user-experience-design-for-apis.html https://blog.keras.io/user-experience-design-for-apis.html ...See "3 - Provide helpful feedback to your users."
- indrax 5y agoInform7 has very educational error messages: (Each time Go or Replay is clicked, Inform tries to translate the source text into a working story, and updates this report.) Problem. The sentence 'This is a book' appears to say two things are the same - I am reading 'This' and 'book' as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that 'John is Paul'. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance 'Abbey Road is a lighted room' says that something called Abbey Road exists and that it is a 'room', which is a kind I know about, combined with a property called 'lighted' which I also know about. Because of this problem, the source could not be translated into a working game. (Correct the source text to remove the difficulty and click on Go once again.) http://inform7.com/ http://inform7.com/
- x0n 5y agopowershell does this with the suggestions component. The easiest way to trigger it is to try to execute something in the current working directory without the ./
- skocznymroczny 5y agoI don't know about other compilers, but in D, the compiler can suggest simple typos, so you'd get something like "Undefined identifier testAdder, did you mean TestAdder?". I think such lists are very useful however. Back when I used C++, Parashift C++ FAQ https://www.parashift.com/c++-faq/ https://www.parashift.com/c++-faq/ was very helpful for me. It helps with trickier parts of C++, for example the "most vexing parse" which doesn't have obvious error messages.
- jaredsohn 5y agoRuby does similar: Run: class Foobar end f = Foobaz.new Output: NameError (uninitialized constant Foobaz) Did you mean? Foobar
- Doxin 5y agoD also dispenses advice with some errors. I've mostly ran into these when accidentally doing C-style type declarations. e.g. when you try to compile int foo[3]; The D compiler will tell you Error: instead of C-style syntax, use D-style `int[3] foo` Which makes D positively a delight to learn if you know C already.
- skocznymroczny 5y agoYes, there are some errors designed for people coming over from C. Similarly, (void)somePointer gives you an error saying "instead of C-style cast, use cast(void)somePointer instead".