Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Why Moose uses this syntax??!!

by Anonymous Monk
on Dec 29, 2014 at 05:16 UTC ( [id://1111603]=note: print w/replies, xml ) Need Help??


in reply to Why Moose uses this syntax??!!

has 'x' => (is => 'rw', isa => 'Int'); has 'x' => {is => 'rw', isa => 'Int'};

The second syntax is more righteous
Some times some people say TIMTOWTDI. But in this case there is just one way better than another
I'm gonna tell ya the reasons
First, the second syntax is faster than first one because you pass one string and just one hash reference while first syntax passes one string and list of law key value pairs. In the first case, the subroutine probably does something like:

 my ($propname,%options)=@_

This is just wasteful isn't it? You make list of key value pairs and copy to @_, and copy again to %options.
But in the second case, you only make list once and what you copy is just a reference.
When you make a big program which uses a lot of classes, the second syntax would be more efficient
Second, inconsistencies.
There are so many module which uses first syntax and there also second syntax.
That leads users into confusion because of inconsistencies of syntaxes. for example the module 'Template' uses second syntax in 'process' subroutine

use Template; # some useful options (see below for full list) my $config = { INCLUDE_PATH => '/search/path', # or list ref INTERPOLATE => 1, # expand "$var" in plain text POST_CHOMP => 1, # cleanup whitespace PRE_PROCESS => 'header', # prefix each template EVAL_PERL => 1, # evaluate Perl code blocks }; # create Template object my $template = Template->new($config); # define template variables for replacement my $vars = { var1 => $value, var2 => \%hash, var3 => \@list, var4 => \&code, var5 => $object, }; # specify input filename, or file handle, text reference, etc. my $input = 'myfile.html'; # process input template, substituting variables $template->process($input, $vars) || die $template->error();

The laziness of not typing two characters '{' and '}' make bigger problem called 'inconsistency'
So what I want to say is: Moose must support at least both syntaxes
PS: It seems that here are so many emotional people. And you even don't give me logical answers.And taste is not a matter of programming. It is matter of food or something. Please find taste in other places

Replies are listed 'Best First'.
Re^2: Why Moose uses this syntax??!!
by Your Mother (Archbishop) on Dec 29, 2014 at 07:08 UTC

    Disagree; there is no performance or handling difference with subroutine argument lists that small, the inconsistency, you assert, is a matter of preference not fact, and this is how many of us write those attributes–

    has x => is => "rw", isa => "Int";

    Plenty of modules also handle args this way and your suggestion would lead to monstrosities like my ( $self, $args, $something, $else, $i, $can, $now_hash, $manage_list, $todo ) = @_; because if it’s possible, someone will do it.

Re^2: Why Moose uses this syntax??!!
by Anonymous Monk on Dec 29, 2014 at 08:00 UTC

    That leads users into confusion because of inconsistencies of syntaxes

    What users? Those who don't read the docs?

Re^2: Why Moose uses this syntax??!!
by Anonymous Monk on Dec 29, 2014 at 11:20 UTC
    And taste is not a matter of programming.

    Yes, it is - you're proving this point by continuing this discussion. Unless of course you can prove that your imagined performance difference actually exists by showing a benchmark that shows a significant difference.

    So what I want to say is: Moose must support at least both syntaxes

    Great, then file a feature request with Moose, or even better, write a patch.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (3)
As of 2024-04-20 01:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found