Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Advice on style

by chrestomanci (Priest)
on Nov 25, 2010 at 16:01 UTC ( #873670=note: print w/ replies, xml ) Need Help??

in reply to Advice on style

Firstly, do you need to export anything? If your module has an OO interface, then users will typically do:

use Your::Clever:Module; my $instance = Your::Clever:Module::new() $instance->some_function();

Secondly, if you read the POD for Exporter, then near the bottom they list a number of alternatives, many of them look much nicer. Exporter is an old module, and a lot of other stuff has come since, some of it will be better.

Having said that, I don't think it makes any difference. My gut feeling is that none of it matters until perl gets to the end of your source file (or package), and then considers everything at once. In other words it is just a style thing like tabs vs spaces for indent, and you should do what ever you or your local coding conventions prefer.

For myself, I am thinking that you have to use or require the exporter module, so it makes sense to put that use along with all the others, and then set-up the exports afterwards, Then again, I have just taken a look at some old perl I wrote about 8 years ago, and it is the other way around. I guess it makes no difference.

Comment on Re: Advice on style
Download Code
Replies are listed 'Best First'.
Re^2: Advice on style
by GrandFather (Sage) on Nov 26, 2010 at 00:01 UTC

    Actually users should never:

    my $instance = Your::Clever:Module::new();

    Instead they should:

    my $instance = Your::Clever:Module->new();

    which works better with inheritance and is more robust against changes to the OO hierarchy.

    True laziness is hard work

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://873670]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2015-10-04 08:39 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (100 votes), past polls