After seeing a few newer monks post their code in <CODE> tags as appropriate, but refer to a line number that is not specifically indicated in the text, I'd like to suggest a possible addition to the CODE tag, "numbering" (or a new tag altogether, NCODE), which will automatically number the lines between the matched tags, as is already done in the Craft sections. (While having the numbering option on by default would be most beneficial when newer monks post, enough of us toss <CODE> around that adding the code to turn it off would be annoying).

Of course, vroom's TODO list may be pages long already, so that this might be gotten around to in about 20 years... :)


Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
  • Comment on Suggestion: Optional Line Numbering Tag for CODE

Replies are listed 'Best First'.
Re: Suggestion: Optional Line Numbering Tag for CODE
by clemburg (Curate) on Apr 23, 2001 at 16:48 UTC

    You want to make sure to make newcomers read the UNIX "cat" command help page first. Most "cat" implementations will have switches to display numbers. E.g., for the GNU "cat" found on Linux boxes, use -n (number all lines) or -b (number all non-blank lines). For those trapped on Win32 machines, the following one-liner will do the thing:

    perl -pe "s/^/++$i.' 'x4/e" filename

    OTOH, will a newbie read the docs on the new proposed tag or on all the other countless ways to do this seemingly innocent task (vi: set nu, etc. ...)? Probably not. Thus: why bother, I'd say.

    Christian Lemburg
    Brainbench MVP for Perl
    http://www.brainbench.com

Re: Suggestion: Optional Line Numbering Tag for CODE
by arturo (Vicar) on Apr 23, 2001 at 16:52 UTC

    This is an interesting idea, but I can see a problem with it: newer monks are more apt to leave out crucial information, and while they're also more likely to post a whole script (not being so confident in their abilities to localize the problem), if they *don't* post the whole script -- and do so verbatim -- the line number they give in their error message many not correspond to the one listed in their posted code. So I'm not sure that generating line #'s is going to be that helpful.

    Still, it might be nice to have as an option for those times where it would help.

Re: Suggestion: Optional Line Numbering Tag for CODE
by elusion (Curate) on Apr 24, 2001 at 00:19 UTC
    If it does get added it would be nice to make it possible to cut and paste code without getting the line numbers. This could be done by placing the code and numbers in a table, preferably an invisible one, in different cells. We would then retain the ability to cut and paste with only a little trouble (all those darned +'s).

    - p u n k k i d
    "Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

      The 'd/l code' link allows you to copy/paste or save the code from a node, without all the +s and what-not. It appears just below the 'comment on...' link, when the node contains CODE tags.
      #!/usr/local/bin/perl print "Just another Perl hacker\n";
Re: Suggestion: Optional Line Numbering Tag for CODE
by knobunc (Pilgrim) on Apr 25, 2001 at 19:07 UTC

    Yery cool idea. It would also be nice to be able to have code numbering continue from one block to the next (obviously under some user control). For example:

    1 # This is the start of the code where we set up stuff 2 my $frob = 'gibber'; 3 my $handle = 'hum';

    Then some descriptive narrative explaining what is going on. And I pick up from where I left off:

    4 # Start doing the real work 5 do_the_real_work($frob, $handle);

    Of course sometimes you want the first block and the second to be numbered separately, and you may want to interweave one set of numbers with another. So I would propose amending the syntax to be:

    <NCODE section="some_name" start_line="1" order="1"> insert code here </NCODE>

    All three attributes are optional. Each named section would have a running counter. The start_line attribute allows you to specify the starting line number of the section. Finally, the order attribute governs the order of the section in the resulting code. The order attribute allows you to talk about a chunk of code that is deep in the body then talk about the stuff that appears before it and have the line numbers make sense. Of course this is all becoming very similar to the Literate Programming stuff, since the "download code" link should reconstruct the code blocks into the right sections and into the right order (possibly with # line statements if lines were skipped).

    Of course this is all very complex and tangled and vroom is probably way to busy to do something so frivolous. So how can I help? Is there a cadre of hand picked workers who help maintain the Monastery? Can I get my hands on the current source code through some CVS share and hack it in and submit patches?

    -ben