Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Style, style, style

by dws (Chancellor)
on Sep 08, 2002 at 02:19 UTC ( [id://195959]=note: print w/replies, xml ) Need Help??


in reply to Style, style, style

1. while (<>) { ... } or while (my $line = <>) { ... }? I use both, depending on whim and my assemement of readability. 2. -w or use warnings;? -w, but only because of muscle memory. 3. sub CONSTANT () { ... } or use constant CONSTANT => ...;? use constant CONSTANT => ...; 4. my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;? I always shift $self. Whether or not to shift the other args or use array assignment kind of depends. Whim again, I'm afraid. 5. for (@array) { ... } or foreach (@array) { ... }? foreach. My undergrad degree was in Math. 6. print 'foo'; or print('foo');? No parens unless needed for precedence. 7. 'simple string'; or "simple string"? Double quotes. 8. glob '*' or <*>? opendir(); readdir(); closedir(); 9. readline *FOO or <FOO>? <FOO> 10. for (keys %foo) { $_ and $foo{$_} } or while (my ($key, $value) = each %foo) { $key and $value }? Depends on whether or not %foo is tied to a DBM. I use the 'each' form on DBMs, having been burned once by pulling all keys into memory on a big DBM.

Replies are listed 'Best First'.
Re: Re: Style, style, style
by Anonymous Monk on Sep 08, 2002 at 03:51 UTC
    4. my ($foo, $bar) = @_; or my $foo = shift; my $bar = shift;?

    What about my ($foo, $bar) = (shift, shift);?
      What about my ($foo, $bar) = (shift, shift);?
      Yuck.

        I regularly see one of these in a co-worker's code:

        sub blah { my ( $foo, $bar, $baz ) = ( shift, shift ); }

        Perhaps not too bad in a short list of shifts. But terrible when invoked as:

        shazam ( 0, 6, 7, $index, $arrayref, $hashref ); ... sub shazam { my ( $foo, $bar, $baz, $bup, $quz, $pig, $cow ) = (shift, shift, shi +ft, shift, shift, shift); }
        Quick, was $cow passed in via @_ or simply instantiated?

        update: added another egregious example, shazam

        blyman
        setenv EXINIT 'set noai ts=2'

      maybe in Obfuscation, not in production code.

      - cybear

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found