http://www.perlmonks.org?node_id=999474


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

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

  • Comment on Re^2: 78/80 chars perl line still a meaningful rule

Replies are listed 'Best First'.
Re^3: 78/80 chars perl line still a meaningful rule
by Anonymous Monk on Oct 17, 2012 at 08:11 UTC

    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

Re^3: 78/80 chars perl line still a meaningful rule
by Anonymous Monk on Oct 17, 2012 at 09:32 UTC
    # 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.
Re^3: 78/80 chars perl line still a meaningful rule (,)
by tye (Sage) on Oct 17, 2012 at 13:37 UTC

    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