in reply to Two simple code style advice questions
I like code that I can see exactly what is going on without going back and forth in the lines of code. Especially when a script becomes gargantuan. In your first case:
would be my preferred style. I could also go with:my %tests = map { $_ => 0 ) qw/ tfred tjock tfortytwo / ;
as long as those two lines are next to each other in the code. Passing a reference to a hash to subs later on is more readable to my eyes that something like:my $tests ={}; map { $tests -> { $_ } = 0 } qw/ tfred tjock tfortytwo /;
but that is a personal preference.callToSub(\%tests);
In your second case I am a big fan of
kinds of things. (Line right out of one of my projects). The term OK is the result of a stack of use constant OK =>0; sorts of things where I use constants to aid in my code's readability.my $errstr = ( $case != OK ? $msg[$case] : "" );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Two simple code style advice questions
by BrowserUk (Patriarch) on Jan 16, 2013 at 14:43 UTC | |
by blue_cowdawg (Monsignor) on Jan 16, 2013 at 14:50 UTC | |
by runrig (Abbot) on Jan 16, 2013 at 18:53 UTC | |
by BrowserUk (Patriarch) on Jan 16, 2013 at 15:33 UTC | |
by Anonymous Monk on Jan 16, 2013 at 15:01 UTC |