I have some new or newish programmers and am trying to pay attention to their roadblocks in learning Julia, so I may occasionally file issues which don't look like my usual fare.
Suppose you try to define a variable using a name that starts with a number:
julia> 2x = 22
ERROR: syntax: "2" is not a valid function argument name
A new programmer might wonder, why does this talk about a "function argument name"? I haven't called any functions (or so I thought).
Python is not great at this, but the differences are interesting:
>>> 2x = 22
File "<stdin>", line 1
2x = 22
^
SyntaxError: invalid syntax
>>>
"invalid syntax" isn't very helpful, but python partly makes up for this with the caret syntax showing the specific place in the line that causes the trouble. (In this case, disambiguating which 2 is the problematic one.)
C (gcc) is much better, though still lacks the key hint that variable names should not start with a number:
#include <stdio.h>
int main(void) {
int 2x = 22;
return 0;
}
$ gcc c.c
c.c: In function ‘main’:
c.c:4:9: error: invalid suffix "x" on integer constant
int 2x = 22;
^~
c.c:4:9: error: expected identifier or ‘(’ before numeric constant
Matlab isn't perfect either, but it goes out of its way to be helpful:
>> 2x = 22
2x = 22
↑
Error: Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or
other syntax error. To construct matrices, use brackets instead of parentheses.
Did you mean:
>> x = 22
(To clarify, that x = 22
is queued up on the REPL.)
To me, the biggest takeaway is that most other languages have decided that a caret mark is a crucial component of the parser's error-reporting.
Completely agreeed. I think it's the biggest usability problem we have with the language right now. https://github.com/JuliaLang/FancyDiagnostics.jl fixes this but has bitrotted. There is an ongoing effort to bring it into base, but it has stalled out a bit.
Most helpful comment
Completely agreeed. I think it's the biggest usability problem we have with the language right now. https://github.com/JuliaLang/FancyDiagnostics.jl fixes this but has bitrotted. There is an ongoing effort to bring it into base, but it has stalled out a bit.