Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re^2: Tact and the Monastery

by Flexx (Pilgrim)
on Sep 14, 2002 at 22:36 UTC ( #197941=note: print w/replies, xml ) Need Help??

in reply to Re: Tact and the Monastery
in thread Tact and the Monastery

OTOH... ;)

I personally think the second of your examples really is more readable. But maybe I'm just a bit nuts.

Myself, I use as few temporary (synthetic) variables as possible, I think they often make things harder to understand. Even if I immediately get the idea what @chars is, I would glance back on every occurance of it, to make sure what your idea of "characters" really is (with or without underscore, hypen, etc.). If the code spreads out, things become even worse...

In your second example, it's right there.

Which brings us back to the topic of this thread. While I am sure that there are some style ideas, any good Perlmonk would propagate, some other things really are a matter of taste.

For example, my block statements look like this:

if($foo) { print $bar; }

A pattern I am quite sure most here don't use, even If they'd call it acceptable. Although I'm a developer for longer than I'd admit to an attractive young lady, ;) I still absorb other's styles from time to time. The monastery, CPAN and the like are good places for such inspiration. Just lately I saw a hash initialization like so:

my %hash = ( one => 1 , two => 2 , three => 3 );

A new pattern I didn't see before, but I liked and absorbed it instantly. It's unprobable to drop a comma on it, and optically, it's much nicer than my old style:

my %hash = ( one => 1, two => 2, three => 3 );

So, IMHO the bottom line is: Tastes are different. The important thing is, that you have style, wich one, matters less.

So long,

Replies are listed 'Best First'.
Re^3: Tact and the Monastery
by Aristotle (Chancellor) on Sep 15, 2002 at 08:00 UTC
    I don't like the comma-prepending style. You can easily add a new line at the bottom that way, but not at the top. It might be fine for languages that are inflexible about their commata, but Perl is not - you can append one to the last value with no harm. My formatting looks like this:
    my %hash = ( one => 1, two => 2, three => 3, );
    Note the "errant" comma after the last value. Separating the assignment and closing bracket on their own lines adds more convenience. This way, I can add a hash key anywhere - even at the bottom or the top - without having to edit any other line than the one I'm on.

    Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://197941]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2018-06-22 21:30 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.