in reply to Re^7: Some thoughts around the "is Perl code maintainable" discussion
in thread Some thoughts around the "is Perl code maintainable" discussion
Update: I couldn't find this last night, but as far as
the concise representation of a high level algorithm in an unnecessary number of sets of a few short statements.
goes, this beats any Perl example I've seen into a cocked hat.
By "method of passing of arguments into subroutines.", I assume you mean 'by reference', making that essentially the same 'problem' as "The explicit use of references". Reading between the lines of your mentioning those, and "composability", I assume that you favour pure FP languages.
So when you rail against Perl for these features, you are essentially railing against side-effectful languages. Ie. Every imperative language in existance along with a good number of FP languages, that allow call-by-reference and mutable variables. And yet, the vast majority of software in existance, and most new software being written, is being written in languages that allow both. This is an old argument and one that scopes well beyond Perl.
As for DWIM -v- DWIS. Here is an example of Perl DWIMming:
sub perms { return !@_ ? [] : map{ my $next = $_; map{ [ $_[ $next ], @$_ ] } perms( @_[ 0 .. $_-1, $_+1 .. $#_ ] ); } 0 .. $#_; } print @$_ for perms qw[ a b c ];; a b c a c b b a c b c a c a b c b a
Take a careful look at that array slice: @_[ 0 .. $_-1, $_+1 .. $#_ ], and note that $_ takes the values 0 .. $#_. That means that in the first iteration of the slice, the indexes are 0 .. -1, +1 .. $#_. And at the other extreme it will be 0 .. $#_ -1, @_ .. $#_.
When I first encountered Perl and started using the range operator (..), I was disappointed that it didn't work for descending ranges. Do you see how Perl is DWIMming there, and how, if it always DWIS, then I would have to explcitly code conditional checks to ensure that the slice didn't address out-of-bounds indices. Whilst not hugely difficult to do, adding those checks and tests to the routine above would destroy its simplicity and clarity, and obscure the algorithm. And this is just one example of DWIM, that greatly simplifies the concise and expressive coding of algorithms in Perl.
Try a brute force conversion of the above to C and you'll understand how much complexity this well chosen 'irregularity' in Perl avoids. And Perl is full of these. Not that I agree with all the DWIMs, but then maybe I just haven't yet encountered the situations where they make sense.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Some thoughts around the "is Perl code maintainable" discussion
by paddy3118 (Acolyte) on Aug 15, 2007 at 08:13 UTC | |
by BrowserUk (Patriarch) on Aug 15, 2007 at 09:21 UTC |