in reply to 78/80 chars perl line still a meaningful rule

I just skimmed through some code I'd written recently on my netbook and checked the line lengths. (not counting indentation, currently set to tab width of 2)

I'm happy with the 200 char confess, because the important bits of it are all in the first 40-60 characters. Then there's a bunch of hash lookups which only matter after they've been interpolated into an error message. Then comes the conditions, which should have been clear from the English in the first 40-60 characters. It's a netbook, so why waste vertical space on unimportant stuff like that?

Note: I am not using a fixed width font, so the lines appear narrower than they otherwise would be.


Comment on Re: 78/80 chars perl line still a meaningful rule
Download Code
Re^2: 78/80 chars perl line still a meaningful rule
by McA (Deacon) on Oct 17, 2012 at 07:35 UTC

    Good morning,

    thank you for looking at your code.

    One thing I'm really intersted in is how would the others break up and concatenate these long "confess-strings" if they don't want to violate the 80cpl rule?

    Best regards
    McA

      perltidy does

      confess "Insufficent data in X from {hash lookup} through {hash lookup} so +urce data file {hash lookup}" unless $condition;
      which seems reasonable, although these days I prefer "condition or" to "unless"
      $condition or confess "Insufficent data in X from {hash lookup} through {hash lookup} source + data file {hash lookup}";

      I've tried my hand at concatenation

      $condition or confess "Insufficent data in X from {hash lookup} " . "through {hash lookup} source data file {hash lookup}";
      And I it is pleasing to the eye, but I wouldn't do that by hand typing (editor IDE should handle it automagically). This also makes searching source code slightly more keyboard clicks but its not a deal breaker for me.

      I also like

      $condition or confessn "Insufficent data in X from {hash lookup} through {hash lookup} source data file {hash lookup}";
      where confessn would do some newline squashing

      But mostly I just let it go past 80 chars cause is the least hassle and works with all editors :)

        Is it only me, but I think personally that the perltidy solution looks really ugly. The manual splitting looks best in my eyes, but exactly this is cumbersome.

        Better solutions desired... ;-)

        Best regards
        McA

      # Given. confess "Insufficent data in X from {hash lookup} through {hash lookup +} source data file {hash lookup}" unless {condition};

      I prefer sprintf when there are more than 1 or 2 simple variables are involved. Using sprintf sans () with post condition check is awkward, so used or. I would use map or hash slice if the 3 instances refer to the same hash (reference). First argument to sprintf would be on single line.

      {condition} or confess sprintf "Insufficient data in X from %s through %s source da +ta file %s" , {hash lookup} , {hash lookup} , {hash lookup} ;
        I would have split the long text-string into two more convenient strings, concatenated together, and put the "unless" on a separate line, with each subsequent line neatly-indented from the first. I would particularly want to be sure that the presence of the "unless" line was not missed. I might for that reason say "unless (condition) { ... confess ... }" to make this important point all the more obvious to the reader. Being "obvious" is essential.

      For 'confess', it is trivial:

      % perl -MCarp=confess -e"confess 'this ', 'is split'" this is split at -e line 1

      If it isn't something that can deal with a list of strings, then I use join the vast majority of the time (because '.' has lousy precedence for such, 'sprintf' quickly leads to action-at-a-distance, '<<' can't be sanely indented, etc.).

      - tye        

Re^2: 78/80 chars perl line still a meaningful rule
by tobyink (Abbot) on Oct 18, 2012 at 16:26 UTC
    $condition or confess sprintf( "Insufficent data in X from %s through %s source data file %s", $hash{lookup1}, $hash{lookup2}, $hash{lookup3}, );
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'