|P is for Practical|
forcing contexts and micro-efficiencyby TomDLux (Vicar)
|on Nov 01, 2011 at 16:47 UTC||Need Help??|
TomDLux has asked for the
wisdom of the Perl Monks concerning the following question:
I'm reviewing the newest Modern Perl and it suggests adding to zero, concatenating to an empty string, and double negation as ways to force numeric, string and boolean context on a value.
Pretty standard stuff, but it made me wonder: Do these simply force a context, or do they carry out the superfluous operation. Would it make sense to detect the pointlessness of the operation beyond forcing context, or would that be more expensive than simply performing the operation?
Micro-optimizers around the world need to know!
As Occam said: Entia non sunt multiplicanda praeter necessitatem.