To drive my point home, I shall now reveal what the compiler tells the errors 
are. And boy, they are bogus.
    
    
    type MyTuple = tuple(a: int, b: int)
    # syntax...Error: invalid indentation
    
    var myTuple: MyTuple = [a: 10, b: 10]
    # syntax...Error: invalid indentation
    
    type MyObject = ref Object
      a: int
    # syntax...Error: undeclared identifier: 'a'
    
    var myObject: MyObject = MyObject(a = 5)
    # syntax...Error: invalid expression: 'a = 5'
    
    type MySpecialObject = ref object of MyObject
    # syntax...Error: inheritance only works with non-final objects
    
    var seqOfStrings: seq[int] = @[int]
    # syntax...Error: internal error: expr(skType); unknown symbol
    
    proc silentProc()* = discard
    # syntax...Error: invalid indentation
    
    proc inc(var a: int) = a += 1
    # syntax...Error: ')' expected
    

The issue comes down to 3 problems for a nim novice:

  * How can he trust the compiler (in production) when he cannot trust the 
compiler error messages
  * What's the use of top quality documentation when the compiler tells him to 
search for the solution at wrong place
  * How can he not be scared when a simple error triggers the compiler to 
produce something like core dump (no example on this behaviour above)



Because there is no 1:1 correspondence between syntax errors and their semantic 
consequences, this cannot be simply fixed by search/replacing existing error 
messages. This also should/could not be fixed by complicating the parser (but 
tinkering nimsuggest might be ok, I guess), because looking at the larger 
context is not it's job. That's why I proposed a separate " _common syntax 
error pattern detection tool_ ". I agree that this not something that the core 
devs should be doing at the moment, but this would be a nice project for some 
wannabe core dev out there. (And, eventually, a _quickfix on|off_ compiler 
switch would be nice).

Fortunately detecting all random permutations is not necessary; I believe that 
giving valid quick fix suggestions for the most common 20 syntax errors would 
keep 80% of the beginners happy.

Let me propose a simple short term fix: When the error message is not to be 
trusted, add a question mark to the error message. Instead of stately asserting 
"Invalid intendation", the compiler should politely suggest: "Invalid 
indentation?". This would save our beginner from spending his evening trying to 
fix the error by prefixing/removing leading whitespace (been there, done that).

> But if you do find a crash please at least make sure you report it on GitHub.

Did that. Yesterday my first forum post, today my first issue, tomorrow the 
world? When it comes to nim, I guess I'm now all in.

> the compiler's error message are constantly improving

True. To be honest, most of my beginner syntax errors I have collected long ago 
produce valid error messages now as of 0.18. For example, one of my pain points 
was confusing the usage of : and = operators. That the compiler now gives 
relevant feedback on this confusion is to be highly appreciated by nim 
beginners.

**Quiz 4** , strictly off-topic: try to guess the output 
    
    
    for x in [0..100]: echo x
    

Reply via email to