4 ms·
This would make debugging hard, as debuggers are very much line number based. Step commands move one line at a time, breakpoints are for specific lines, and sta
by zeroimpl 6y ago
This would make debugging hard, as debuggers are very much line number based. Step commands move one line at a time, breakpoints are for specific lines, and stack traces from exceptions include line numbers but not character offsets.
That’s why for function calls passing multiple arguments where each argument may be non trivial, it’s a good idea to put each argument on its own line.
- Semaphor 6y agoNot always. I can set the breakpoint in jetbrains rider to a function in a multi function line. And Java stacktraces certainly contain character offsets.
- zeroimpl 6y agoI’ve seen character offsets for JavaScript (which requires it due to minimization), but never Java. I’m pretty sure that data is not available in Java bytecode, nor most compiled languages.
- yellowapple 6y agoThe editor could show both the final line number and "sub-line-numbers" after a decimal point or something. E.g.: 1 /* A function that does something */ 2.1 int do_something(int foo, 2.2 int bar, 2.3 int baz) 2.4 { 2.5 return foo + bar + bam; 2.6 } Which would condense to: 1 /* A function that does something */ 2 int do_something(int foo, int bar, int baz) { return foo + bar + bam; } When you try to compile this, the compiler will complain about line 2, which you know from your editor's line numbering encompasses lines 2.1 through 2.6. As an alternate strategy, you could use column numbers instead of sequential sub-lines, like so: 1 /* A function that does something */ 2.0 int do_something(int foo, 2.26 int bar, 2.35 int baz) 2.44 { 2.46 return foo + bar + bam; 2.70 } And then, if the compiler reports a column number or offset into the line, you'll immediately know "well the compiler's complaining about line 2 column 65, which is between 2.46 and 2.70... golly gee willikers, I fat-fingered the third addend in the return statement!". You could get even more abstract than this, with "line numbers" instead being local to a given scope, and the compiler reporting erroneous line numbers relative to said scope. If the compiler tells you that the syntax error is in the first (in this case also last) statement in the function do_something, then it should be apparent where to look.