Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: How would you indent this?

by GrandFather (Saint)
on Mar 18, 2021 at 02:02 UTC ( [id://11129879]=note: print w/replies, xml ) Need Help??


in reply to How would you indent this?

Using perltidy configured to my preferences I get:

my @headings = ( {key => 'k', name => 'Kanji', class => 'kanji'}, {key => 'skip', name => 'SKIP', class => 'skip-code'}, {key => 'co', name => 'Suggestion', class => 'skip-code'}, {key => 'disc', name => 'Discussion'}, );

which I'm pretty happy with. The cperl-mode default is awful.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: How would you indent this?
by no longer just digit (Beadle) on Mar 18, 2021 at 05:34 UTC
    The cperl-mode default is awful.

    It's probably a bug or at least unintentional behaviour. It seems like the consensus is that one should either have

    {key => 'k', class => 'kanji'},

    or

    { key => 'k', class => 'kanji', },

    but not

    { key => 'k', class => 'kanji' },

    so what I should do is to stop it from adding the newline after the {.

      { key => 'k', class => 'kanji' },

      is best here because it makes it easy to see the differences the rows at a glance.


      { key => 'k', class => 'kanji' },

      isn't too bad, since it's almost as good at showing the differences between rows. The extra spacing is a needless hindrance, though, so it's not as good.


      But it's definitely not as bad as what you posted in the OP.

      { key => 'k', class => 'kanji' },

      This is just plain weird.


      Finally, we have this:

      { key => 'k', class => 'kanji', },

      It offers no readability benefits over the styles, and makes it even harder to see differences between the lines. No good here. This would be used when dealing with with very long records, and when adjacent lines are substantially different (e.g. in a multi-level structure).

      Seeking work! You can reach me at ikegami@adaelis.com

        > Finally, we have this:

        { key => 'k', class => 'kanji', },

        > It offers no readability benefits over the styles, and makes it even harder to see differences between the lines.

        I'd say that's the reasonable default, the => should be vertically aligned tho.

        Everything else needs intelligent heuristics to determine if the data has a repeated structure requiring another presentation. (not all AoHs have a nearly tabular semantic like in the OP's case)

        That's why all these Data::* modules are so complicated.

        And only the author can tell what the best representation is.

        An editor shouldn't change manual formatting.

        Problem in this thread is that the OP is effectively asking multiple questions:

        • how should this be best written
        • how should my editor do it
        • what's the bug in my editor

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        You seem to place too much emphasis on needing "to see differences between the lines" esp at a glance -- source code is too verbose for that kind of analysis, instead use spreadsheet or printf

      My issue with first and last styles is that changes needlessly become cumbersome. That may be preferred to set infrequently changing defaults, or if one needs to save precious vertical space.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found