Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re^2: Climbing Mt. Perlcritic -- Switch statementsby puudeli (Pilgrim) |
on Mar 26, 2009 at 07:03 UTC ( [id://753356]=note: print w/replies, xml ) | Need Help?? |
I would go exactly towards subroutines. Switch-statements are cluttered and at worst difficult to read and maintain. Given-when is similar although it does make the code a bit more readable. IMO the problem with switch/given structures is that too easily you insert multiple things into a clause making your logic/function "too long". It is also too easy to use overly complex conditions with given/when. In order to get cleaner and more testable code I would go for longer code. It eases the maintenance in the long run. Without knowing the full code it is difficult to properly refactor it as there are too many variables whose context and details are unknown (eg. @PLACE, @batch, %files, is the code inside a function or not). But here is my humble try. I did make some assumptions about the code though. Correct me if I'm wrong.
update: one function was missing, copy/paste error.. update2: I know I generated lots of code, the purpose is that most of the code is easily unit tested. Subs that are strongly decoupled from the data makes it easy to write unit tests. I'd like to know the context and the purpose of @batch and @PLACE so that I could see the associations between them and code and refactor even more.
-- seek $her, $from, $everywhere if exists $true{love};
In Section
Seekers of Perl Wisdom
|
|