Postfix conditionals and language design
So I'm reading some Perl code. I usually stay away from Perl as much as I can, but I'm trying to figure out some undocumented behavior of the MusicBrainz RDF server so I have to UTSL. Anyway, I get to this line:
return ("No artist name or artist id given.", $data, 0, undef)and I get confused, because I saw the artist ID check but not the artist name check. So I start reading backwards to see if I missed something; maybe the artist name check happened in some non-obvious function call? I go skimming through various other files to see if some other code is filling in the artist ID or something. Eventually, I give up and come back to that line, and I notice that the next line is:
if ($data->{artist} eq '');and I smack my head. I'm willing to chalk this up to bad style (and I hope people would agree this is bad style), but now I'm wondering: when is it ever good style to put the conditional guard after the code it's guarding? Or, more generally, when is it ever good style for the order of code (in the same basic block) to be the opposite of the order of execution?
no subject
As for the perl fragment in question, the camel book actually talks about when it's good style or not. However, it's at work and I'm at home. I think it's something like "put the important clause first"
As for my weapon of choice, when I'm not being paid, it's almost surely Ocaml. It's mostly functional, has a powerful, terse syntax and has a really good native code compiler.