I don't know about you people, but I find it extremely anoying when someone posts a node with the CODE tags and text that will run off of my 1024x768 screen...

I haven't thought this through yet, but it could be a good regex exercize. I thought doing a substr on each line within a code tag and pumping in an extra \n might be a viable solution. I guess a good limit (in my case at least) would be ~ 200 chars. Sure the code would look ugly and loose its indentation, but then again, having to scroll sideways or having the nodelets run off the screen is worse, IMHO.

#!/home/bbq/bin/perl
# Trust no1!

Replies are listed 'Best First'.
RE: Wrapping long code tags
by merlyn (Sage) on May 29, 2000 at 19:12 UTC
    No, please don't. You cannot in general know where to insert whitespace in a Perl code line, not without applying more intelligence than is available without actually executing the code. Seriously. For details, look in www.deja.com/usenet for discussions that include "merlyn" and "sin" and "time" (an odd trio, but it pulls up exactly the note about why only /bin/perl can parse Perl).

    -- Randal L. Schwartz, Perl hacker

      After a bit of searching I found the post merlyn referred to:
      >>>>> "Damian" == Damian Conway <damian@cs.monash.edu.au> writes:

      Damian> Take a look at Text::Balanced -- in particular how the Damian> extract_quotelike, extract_variable, and extract_codeblock Damian> subroutines conspire to do a fair imitation of parsing Damian> Perl. It would be trivial* to adapt these three to compress Damian> Perl code by extracting comments and non-quoted multiple Damian> whitespace.

      Damian> * ...for sufficiently non-trivial values of "trivial"...

      Even with your disclaimer, I think not.

      As my repeatedly quoted example goes...

      $n = time / 2 ; # / ; # first hash starts comment $n = sin / 2 ; # / ; # second hash starts comment

      You can't strip comments until you can recognize that time is proto () while sin is proto ($). And there are seven other characters like "/" that have a "looking for term" vs "looking for operator" feature. And here we go with the non-deterministic part:

      use Faith; $n = wazzat / 2 ; # / ; # what is wazzat prototyped as? :)

      Yup. You gotta suck in everything that Faith.pm reads as well, thanks to user prototypes. And then we get the odd case:

      BEGIN { eval time % 2 ? 'sub wazzat ();' : 'sub wazzat ($);' } +$n = wazzat / 2 ; # / ; # what is wazzat prototyped as? :)

      Yup. Non-deterministic parsing. :)

      And while these are extreme examples, real life proggies get tripped up by the same things.

      Thus, only "perl" can parse "Perl" continues to be true.

          I would write a verse
           of haiku to show the point,
           but I'm not that good. :-)
      print "Just another Perl hacker,"
       -- 
       Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777
       0095
       <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
       Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
       See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
       training!


      vroom | Tim Vroom | vroom@cs.hope.edu
      Au contraire!

      not only /bin/perl can parse Perl, but my brain can do a pretty good job of it too! i imagine most of your brains do a decent job of it as well.

      after reading vroom's repost of merlyn's original usenet post, i realize that even using one's brain, sometimes there's just stuff that perl knows that no person can.

      by this, i am reminded of a semi-humorous Mel Brooks film from the late eighties:

      SPIRIT OF YOGURT: Use the Schwartz, Lone Starr. Use the Schwartz.

      LONE STARR: I can't. I lost the ring.

RE: Wrapping long code tags, probably a bad idea
by neshura (Chaplain) on May 29, 2000 at 22:44 UTC
    Purely from a user perspective, I don't want to see the script broken up. I am aware of the technical limitations introduced by merlyn -- the point is well-taken. But technicality aside, I think there is an element of keeping the scripts so that they look the way the author intended. One has to assume a certain level of facility of course, that the authors of code know where to put newlines and where to leave longer lines alone. My main concern though, is that everyone has their own unique style -- to my mind, adding newlines merely to make a script fit on a screen is kind of like correcting e.e. cummings' punctuation.

    e-mail neshura

      i'm already used to editing my scripts for character cell displays, since i work over SSH a lot. so, for me, keeping lines at a manageable length does not entail any additional cognitive effort.
        Same here, maybe that's why I find it so anoying!

        At any rate, the node I mentioned above was followed by a "Don't you use line breaks?" question, which I tought was in good order. Not only because of perlmonks aesthetics, but because the coding did look rather odd.

        I'm one of those guys that will do:
        my $foo = 'foo'; my $foobar = 'foobar'; my $foobarbaz = 'foobar and baz';
        instead of
        my $foo = 'foo'; my $foobar = 'foobar'; my $foobarbaz = 'foobar and baz';
        the contrary can be applied to my apartment tho. My living room looks much more like:
        my $foo = 'foo'; my $foobar = $foo.'bar'; my $foobarbaz = $foo.'bar'.' and baz';
        :o)
RE: Wrapping long code tags
by reptile (Monk) on May 29, 2000 at 12:44 UTC

    I think the <TT> tag wraps long lines. That might be an easier option (pending verification of this claim, of course).

    72656B636148206C72655020726568746F6E41207473754A