I would prefer the code which states, most simply and obviously, what the intent of the designer is ... and, also, which builds the maximum flexibility for the future.

In case #1, if there was a legitimate other use for @tests as an array (versus using keys(%ntests)), and if the value-initialization of %ntests should always be zero .. likely .. then I would use a simple foreach my $key (@tests) { %ntests{$key} = 0; }, written on three source-lines. Is it “shorter?” Clearly not. Is it “faster?” (Rhett Butler, Gone With The Wind) But it is clear, to almost anyone who’s written a program in any language out there. And it’s easily maintainable going forward: you can put anything you need to inside that block, at any time in the future.

In case #2, the first alternative is instantly “outed.” (Say what you mean.) And once again I would perhaps write something like: my $mol = ""; if ($n == 42) { $mol = "forty-two"; } Once again, I am looking towards the future, after two years of programmers meddled with this same bit of code and it grew over all those years into something totally different.

Basically, when someone writes the first bit of code, whatever it is, they have a very clear notion in their heads at that time of what they’re trying to write at that time, and they get the idea stuck in their heads that there are brownie-points for being “clever.” We’ve even got a “golf” section here, and it’s fun, but it’s just for fun and we all know it ... or, we should. But, what happens over the next several years? Well, one day, a change surely comes to pass which negates the assumptions that allowed the O.C. to have been “clever” in the first place, and that means that his entire block of code must be replaced. First, it must be correctly understood. Then, it must be correctly replaced with code that correctly does, not only what the new-change needs to do (which is why the current coder is dealing with this code now at all), but also everything that it did in the past. Depending on the code, that entirely-unwanted voyage of discovery can become huge, and profoundly de-stabilizing. A great big cost and delay, maybe, and all for nothing. “Thanks for nothing, clever-one wherever you are now ...”

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other