Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by McA (Curate)
on Oct 17, 2012 at 07:35 UTC ( #999474=note: print w/ replies, xml ) Need Help??


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
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 (Cardinal) 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        

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2014-09-20 05:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (153 votes), past polls