[LA.pm] coding guidlines, inline functions
Ofer Nave
ofer at netapt.com
Tue Dec 7 13:35:56 CST 2004
On Tue, 7 Dec 2004, Kevin Scaldeferri wrote:
> On Dec 7, 2004, at 11:08 AM, Ofer Nave wrote:
>
> > 2) inline functions
> >
> > Is there any analog in perl to C inline functions (i.e., macros)? In
> > other words, is there an elegant way in perl to make things modular for
> > code maintenance purposes, but empower the perl parser/compiler to
> > optimize away unnecessary function call overhead?
>
> So-called "constant functions" are optimized away. These look like:
>
> sub pi () {
> return 3.14;
> }
>
> The empty prototype is required and the return value must be
> recognizable as constant at compile time.
>
> This is basically what the 'use constant' pragma does.
>
> Other than that, I think you have to wait for Perl 6. Or get really
> brave with source filters.
Yup, knew about use constant. Though lately I've been using the Readonly
module from CPAN, cause I like consistent sigil usage ($PI).
I've never used source filters. Familiar with the concept, but not any
particular implementation. Is there a conventional way to do it? Seems
there's a lot of optimization you could do by automunging the source
before compilation. Maybe all programs should be wrapped in an eval. :)
-ofer
More information about the Losangeles-pm
mailing list