Re: (3) Ternary confusionby arturo (Vicar)
|on Feb 28, 2004 at 00:11 UTC||Need Help??|
I'm not going to quibble with the basic thrust of your advice, but the following quote struck my eye:
The above code is obfuscated seemingly for the sake of obfuscation.
What leads you to say that? Because it uses the ternary operator? The first thing I noticed about the code is that it put each significant chunk on its own line. That hardly seems like the practice of a determined obfuscator. Apart from the issue of whether or not a given developer is familiar with the ternary operator, it boils down to :
which is plain 'ol idiomatic Perl.
There are a number of reasons one might write code like that, having nothing to do with obfuscation. Perhaps the original author liked the terse idiom and compensated for it by formatting the code the way s/he did. Maybe s/he had five minutes and somebody asked her/him to make the script use a different connection if it was running on a specific server.
Of course, if you're going to rewrite it for later expansion, you might as well move the connection selecting code off into its own subroutine or, if it's complex enough, module. But I think we should all be aware that developers don't always have the time to develop code like that right from the very start -- especially when you don't know whether your code is going to be in use two weeks after you write it, which is a distinct possibility.
If not P, what? Q maybe?