in reply to Style: buried variables or double referencing?
Oruse Readonly; Readonly my $LOW => 9; Readonly my $HIGH => 14; ... my $count = $some_variable eq 'x' ? $HIGH : $LOW; for $i (0 .. $count) { ... }
a bit depending on whether you need $count elsewhere, and what 9, 14, $some_variable, 'x', 'y' actually stand for.use Readonly; Readonly my %VALUES => (x => 14, y => 9); ... for $i (0 .. $VALUE{$some_variable}) { ... }
The main drive of programming it this way is that I strongly dislike 'magical' literals (specially numbers) in the middle of the code. Unless I know the bigger picture, I can't see what the 9 and 14 stand for. Nor do I know whether their values can be changed without having to change the value elsewhere in the program as well. Defining them as constants helps solving this problem.
|
|---|