5 ms·
My unexpected side benefit: some compiler error messages became comprehensible. Oh, an lvalue is required? Since I now actually know WTF that means, I can deal
by adrianmonk 4y ago
My unexpected side benefit: some compiler error messages became comprehensible.
Oh, an lvalue is required? Since I now actually know WTF that means, I can deal with it.
It also cleared up a situation that had always confused the hell out of me: sometimes I'd compile and get 1 or 2 errors, so I'd make corrections and try compiling again, but then I'd get 8 or 10 errors! Seeing that whatever I did made everything much worse, I'd conclude those most not be the right corrections, and I'd feel lost and maybe even get stuck.
After taking compilers, I finally understood why: compilers have phases, and my corrections allowed the parsing phase to complete, which meant the semantic analysis phase could happen and give me errors. So for example, if I finally fix enough syntax errors that the compiler can tell I've written a function with some variables in it, then it can start giving me errors that they're not the right types.
- deleted 4y ago[deleted]
- NineStarPoint 4y agoAgreed on this, by far the largest benefit from a utility standpoint from my programming language design course was increased understanding of errors.
- einpoklum 4y ago> Oh, an lvalue is required? Since I now actually know WTF that means, I can deal with it. That's not so much a compiler thing as it's a language thing. Perhaps even a C (and C++) language thing... https://en.cppreference.com/w/cpp/language/value_category https://en.cppreference.com/w/cpp/language/value_category
- CuriousCosmic 4y agoYes and no. That specifically is a C & C++ thing but the general concept you'll learn in a compilers course. If you intimately understand how a compiler works (even just generally), you pick up a really concise understanding of how the errors come about and how they tie back to the language. Understanding the lexer and the parser explains a lot of common errors (missing/ semicolon or curly bracket) and why they often point to errors in otherwise perfectly correct & unrelated code instead of their source location. Understanding the compiler itself and how it operates over an AST means that if you get an error regarding a particular set of semantics, you can quickly learn what the implications are and how that maps to your code. A good example (other than the GP's) is the massive, ugly template or overloading errors. They make sense and explain to you everything the compiler tried to do and how it failed each time it tried. The compiler doesn't know what is wrong and therefore doesn't have a more concise error to give you so it just tells you everything "it knows". From that you can work back and see where what you intended the code to do diverged from what the compiler thought the code did. So it is a language thing but you build the intuition to pick up those language skills by learning/understanding compilers in general.