Ask HN: Would it be educational to map error messages to common mistakes?
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/...
22 comments
[ 4.9 ms ] story [ 63.5 ms ] thread[1] https://en.wikipedia.org/wiki/Raku_(programming_language)
There are some for people coming from Perl.
Some for simple typos. There are some errors that it can't find until it runs your code. (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/Exce...
In practice, they can be very helpful and clear. But often they are too long, so I end up not reading them.
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.
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
Which is exactly the current situatuon.
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.
See this video for explainer and demo: 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/ru...
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.
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
There is a nice write up from the creator of Keras about this: https://blog.keras.io/user-experience-design-for-apis.html ...See "3 - Provide helpful feedback to your users."
(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/
I think such lists are very useful however. Back when I used C++, Parashift 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.
Run:
class Foobar end
f = Foobaz.new
Output:
NameError (uninitialized constant Foobaz) Did you mean? Foobar