in reply to Two simple code style advice questions
So there is a personal preference and a $work preference...
So clearly (a) is better as long as speed doesn't matter, even for me the $_ => 0 part evidently signals a hash assignment to my visual cortex. And this construct is easily changed to other meanings.
The only exclusion to that rule may be this idiom @ntests{@tests} = () to assign undef.
Anyway in aforementioned work context even map was risky.¹
So maybe
my %ntests; $ntests{$_}=0 for @tests;
would cause the least problems.
For me (a) is an obfuscation hack. It goes to deep into brain loops about numeric type casting.
So this time (b) for me.
At $work (where the word "ternary" provoked empty glares¹) maybe rather:
my $mol = ""; $mol = "forty two" if $n==42;
HTH! :)
Cheers Rolf
¹) It hurts, I know!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Two simple code style advice questions
by BrowserUk (Patriarch) on Jan 16, 2013 at 18:34 UTC | |
by LanX (Saint) on Jan 16, 2013 at 21:36 UTC | |
by Anonymous Monk on Jan 17, 2013 at 10:47 UTC | |
by BrowserUk (Patriarch) on Jan 18, 2013 at 01:09 UTC | |
by Anonymous Monk on Jan 17, 2013 at 11:02 UTC | |
by LanX (Saint) on Jan 17, 2013 at 14:56 UTC | |
by Anonymous Monk on Jan 18, 2013 at 05:42 UTC | |
by Anonymous Monk on Jan 17, 2013 at 14:36 UTC | |
by Anonymous Monk on Jan 18, 2013 at 05:33 UTC |