(I know you know this, but others may not and so it should be emphasized.)
The emphasis in maintainable code (and all code spends 80% of its time in maintenance mode, so good code is maintainable code) should be on readability. An expression is readable relative to the rest of the code if the number of units I have to parse does not go up significantly from the surrounding code. I would posit that a difference of 3 or more renders an expression hard to read relative to the surrounding code. Given that most lines of Perl (in my experience) run between 3 and 5 units, anything that has more than 6-8 units is going to be very hard to read.
Your snippet contains, by my count, 9 units. I would argue that it should be written as so:
That could be improved quite a bit if what some_code() returns is clarified. If it returns @f == 0 or @f == 1, then other solutions can be provided. But, if it can legally return @f == 2, then the above is really the only good solution. Of course, some_code() and some_other_code() already sound like sucky functions and I have no idea what they do. I'm basing this solely on what you seem to have to do in order to work with them in a sane fashion.{ my @f = some_code(); @f = some_other_code() unless @f == 1; if ( @f == 1 ) { # .... } }
In reply to Re: creating a variable in an if statement
by dragonchild
in thread creating a variable in an if statement
by Tanktalus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |