On Thu, Dec 9, 2010 at 2:41 PM, Shawn H Corey <shawnhco...@gmail.com> wrote: > FYI: I don't mean to burst your bubble but new() is the convention for > creating an object, not create().
Yes, but... According to `perldoc perlobj`: > That word "new" isn’t special. You could have written a > construct this way, too: > > package Critter; > sub spawn { bless {} } > > This might even be preferable, because the C++ programmers > won’t be tricked into thinking that "new" works in Perl as it does > in C++. It doesn’t. We recommend that you name your > constructors whatever makes sense in the context of the > problem you’re solving. For example, constructors in the Tk > extension to Perl are named after the widgets they create. Personally, I remember people using the C++-like syntax... my $obj = new Foo::Bar; ...on this list and being told to use the alternative syntax... my $obj = Foo::Bar->new; ...instead. It seems better to just avoid the name "new" entirely so it isn't confused with other languages. I think it will be less confusing for people that way. I know that I found it confusing to see the C++-like syntax, only to have people on this list discourage it and say that it doesn't do what we think it does. I'm not fixed on 'create', but generally I name my "constructor" functions in C "${struct_name}_create" (where $struct_name is the name of the struct), so it just seems logical that I would name my constructors in Perl 'create' as well (after all, that's essentially what they're doing). -- Brandon McCaig <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/