Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Tact and the Monastery

by Flexx (Pilgrim)
on Sep 14, 2002 at 22:36 UTC ( [id://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,
Flexx

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-20 15:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found