Page 1 of 1

Auto Line Numbering in [PHP] code

Posted: Mon Sep 23, 2002 7:56 am
by jonsyd
Have you noticed how any posting containing more than 10 line of code (LOC) is 30% redundant replies just trying to work out which LOC is being referred to/broken.

I vote for the

Code: Select all

parser to include line numbering, what do you think?

In fact, show me the source and I'll do it for ya.

Jonny

Posted: Mon Sep 23, 2002 8:04 am
by twigletmac
Considering that often what's posted is a snippet of the code then even with automatic line numbers you still wouldn't be able to work out which, out of 30 lines, line 105 was. Probably better if people posting code could be encouraged, by those trying to help them, to identify the line in question (as a few already do) with a comment like

Code: Select all

// This next line is line 105
Mac

Posted: Mon Sep 23, 2002 10:42 am
by jonsyd
... see your point, but in most cases the initial poster doesn't know where in code the errors are, so they can't mark it up.

Alot of errors which confuse newbies are quote and bracket-related syntactical stuff, where the line number given in the error message doesn't identify the source of the problem, just where the parser gives up.

Having line numbers allows people to refer back to the exact line, rather than having to quote a whole LOC each time - good example is MySQL related code, there will normally be loads of:

$result = mysql_query($query);

where the $query s can look very similar, so you have to hunt through the code rather than just going to the line (human full text search vs index?), and then correctly quote the LOC.

As for your example, isn't it just as easy to quote the error message and say it refers to line 15 of the snippet, as to quote the error message and add a comment to line 15 of the snippet?

Jonny

Posted: Tue Sep 24, 2002 4:34 am
by twigletmac
jonsyd wrote:... see your point, but in most cases the initial poster doesn't know where in code the errors are, so they can't mark it up.
Well if it gives a line they can at least indicate which line that is.
jonsyd wrote:Alot of errors which confuse newbies are quote and bracket-related syntactical stuff, where the line number given in the error message doesn't identify the source of the problem, just where the parser gives up.
I know that but when someone posts a 30 line piece of code from a longer script it helps to know where the parser's reporting the error so you can ignore the code below, or ask for the code above if they haven't supplied it.
jonsyd wrote:Having line numbers allows people to refer back to the exact line, rather than having to quote a whole LOC each time - good example is MySQL related code, there will normally be loads of:

$result = mysql_query($query);

where the $query s can look very similar, so you have to hunt through the code rather than just going to the line (human full text search vs index?), and then correctly quote the LOC.
In your example surely the person just adding a comment to say 'This is where PHP says the error is' means you don't have to search through all the code. If they just post a bunch of code and say 'please fix this' the best reponse is to ask them exactly what needs to be fixed.
jonsyd wrote:As for your example, isn't it just as easy to quote the error message and say it refers to line 15 of the snippet, as to quote the error message and add a comment to line 15 of the snippet?
It's probably about the same amount of typing sure.

One thing I forget to mention yesterday but I think would be relevant if line numbers were added to the PHP code block - how would it affect the fact that I copy and paste a lot of the code into my editor in order to check how it runs and whether what I think the problem is is the only one. With auto-linenumbering would I have to remove those numbers each time else face a parse error every time PHP reached one?

Mac

Posted: Tue Sep 24, 2002 10:03 am
by jonsyd
I guess that's the clincher, line numbers would ruin copying of code which has to be more important (although I always run a filter to properly format and strip gremlins and numbering from copied code anyway :wink: )