|XP is just a number|
Re^4: Module Announcement: Perl-Critic-1.01 (scalar)by tye (Cardinal)
|on Jan 26, 2007 at 22:45 UTC||Need Help??|
Do you write the following?
If not, then it is probably because you know that 'lc' just returns a scalar. If you do, then there are probably a lot of people who find you silly. 'lc' isn't the only function I use that just returns scalars. Sprinkling 'scalar' all over hellenbach doesn't improve code much in my experience.
I actually consider the => to be broken for not enforcing scalar context on both sides. But that still just shifts the problem to things like function arguments.
Why haven't you written a 'string' function that forces all arguments to be treated as strings and asserts if given a reference? And an 'integer' and 'float' function that asserts when given things not appropriate for those context? Then you can fix all of your broken assumption-filled code:
Yes, that code looks much easier to maintain. [Oops, I left off one boolean().]
And what about all of those places where my list context is implicit? Surely those need to be made explicit too? I'll write partOfList() that asserts if not called in a list context.
Now, there are places where using scalar() is more appropriate. But, no, I don't consider using it on a function that just returns a scalar to be such a place. And I don't think transforming every function that might want to return an undefined scalar into "a function that returns a scalar except when it wants to return a undefined scalar in which case it returns an empty list instead and if you really wanted the undefined scalar then you should wrap the call in scalar() for that purpose" to be even close to an improvement strategy.