1
edit
Aarontrevena (talk | contribs) |
(A few more extra points about the original 'perl cons' being related to 5+ year out of date practice) |
||
| Line 26: | Line 26: | ||
**** See for example the 'autobox' module on CPAN (http://search.cpan.org/dist/autobox) that allows you to call $foo->isa('Class') on any scalar. -phaylon | **** See for example the 'autobox' module on CPAN (http://search.cpan.org/dist/autobox) that allows you to call $foo->isa('Class') on any scalar. -phaylon | ||
** Some parameter check is available. Or use Moose, it can check even better that many languages can. | ** Some parameter check is available. Or use Moose, it can check even better that many languages can. | ||
*** See for e.g. http://search.cpan.org/perldoc?MooseX::Params::Validate -mst | |||
* <tt>$$foo[1]</tt> and <tt>$foo->[1]</tt> mean the same thing. | * <tt>$$foo[1]</tt> and <tt>$foo->[1]</tt> mean the same thing. | ||
** This is analogous to a C/C++ construct where <tt>ix->member</tt> and <tt>(*ix).member</tt> mean the same thing. | ** This is analogous to a C/C++ construct where <tt>ix->member</tt> and <tt>(*ix).member</tt> mean the same thing. | ||
| Line 53: | Line 54: | ||
** qq[] is a string (as is qq{}, etc.), q[] is a string, though qw() is an array. | ** qq[] is a string (as is qq{}, etc.), q[] is a string, though qw() is an array. | ||
*** they each do different things, it's not rocket science - ajt | *** they each do different things, it's not rocket science - ajt | ||
*** if that confuses you, stick to 'str' and "str" -mst | |||
** &sub() is resolved at runtime but sub() is resolved at compile time, ''except'' for methods. | ** &sub() is resolved at runtime but sub() is resolved at compile time, ''except'' for methods. | ||
**** sorry, I don't see a problem here - Perl is dynamic - you can create methods and functions post compilation, how do you propose to resolve them at compile time without the Tardis? | *** &sub() is perl 4 syntax so it behaves weirdly, don't use it in perl 5! -mst | ||
*** sorry, I don't see a problem here - Perl is dynamic - you can create methods and functions post compilation, how do you propose to resolve them at compile time without the Tardis? | |||
** The conversions from one type to another can sometimes be horrendous to read. Eg: [keys %{ @{ $var } }]. | ** The conversions from one type to another can sometimes be horrendous to read. Eg: [keys %{ @{ $var } }]. | ||
*** ITYM [ keys %{@$var} ], compare that to dereferencing in C or C++. | *** ITYM [ keys %{@$var} ], compare that to dereferencing in C or C++. | ||
| Line 64: | Line 67: | ||
*** PHP doesn't have sepatates operators, and it creates problems for inexpirienced programmers (thay do not use ===, strval, intval). | *** PHP doesn't have sepatates operators, and it creates problems for inexpirienced programmers (thay do not use ===, strval, intval). | ||
** Figuring out what's $1, $2, $3, etc. from a regex result. And the fact that $1 and $2 don't get reset if there's no match. | ** Figuring out what's $1, $2, $3, etc. from a regex result. And the fact that $1 and $2 don't get reset if there's no match. | ||
*** my ($first, $second) = ($var =~ m/(foo)(bar)/); is preferred syntax unless you're emulating awk. Or stuck in perl 4. -mst | |||
*** Perl 5.10 will have named captures. | *** Perl 5.10 will have named captures. | ||
*** figuring out $1, etc is trivial | *** figuring out $1, etc is trivial | ||
| Line 76: | Line 80: | ||
*** Sorry, poor programming in your code not perl. | *** Sorry, poor programming in your code not perl. | ||
*** Any Perl framework will have other methods | *** Any Perl framework will have other methods | ||
*** and this is why nobody uses that interface anymore :) - mst | |||
** Multiple Inheritance can be problematic in extreme edge cases. | ** Multiple Inheritance can be problematic in extreme edge cases. | ||
*** Easy then: Don't use MI if you're not suited to it or it doesn't fit the project. Use single inheritance, or roles, or mixins, or traits. It's all available. | *** Easy then: Don't use MI if you're not suited to it or it doesn't fit the project. Use single inheritance, or roles, or mixins, or traits. It's all available. | ||
*** not if you're using Class::C3 (or the c3 mro in core 5.10), which most modern Catalyst code and all DBIx::Class code -does- use -mst | |||
** The fact that %var is a () (which is also the array notation) but {} is $var. | ** The fact that %var is a () (which is also the array notation) but {} is $var. | ||
*** () isn't the array notation. It's a list. my @array = (1, 2, 3); stores a list into an array. The only array notation is [], for array references. So my $foo = [1, 2, 3] is just a short version of my @foo = (1, 2, 3); my $foo = \@foo; perlfaq4 elaborates on this in "What is the difference between a list and an array." -phaylon | *** () isn't the array notation. It's a list. my @array = (1, 2, 3); stores a list into an array. The only array notation is [], for array references. So my $foo = [1, 2, 3] is just a short version of my @foo = (1, 2, 3); my $foo = \@foo; perlfaq4 elaborates on this in "What is the difference between a list and an array." -phaylon | ||
** That is, you can't really do %hash = (key1 => $cgi->param('unset_param'), key2 => 'something'), because then you'll actually just have an invalid hash. | ** That is, you can't really do %hash = (key1 => $cgi->param('unset_param'), key2 => 'something'), because then you'll actually just have an invalid hash. | ||
*** No problem there. You just need to know what contexts are and read the documentation for the module you're using. Or simply enforce scalar context. | *** No problem there. You just need to know what contexts are and read the documentation for the module you're using. Or simply enforce scalar context. | ||
*** But like we said, the $cgi->param interface is considered harmful. In catalyst you'd do $c->req->param->{unset_params} which would behave itself fine -mst | |||
== On Python cons == | == On Python cons == | ||
edit