It's certainly possible to write functions (subs) with comments about what they do, and use meaningful variable names. The built-in syntax/operators do require some study, though.
For the "Enterprise!" developer pool, there's Java. The 500 line methods are still hard to slog through, though. Too many never got the note about a "business logic layer" and abstraction, and just shove all the details in-line. In which case, the language of mandate doesn't matter much.
Great straw-man there. I didn't realise that javac required 500 line methods before compilation.
> In which case, the language of mandate doesn't matter much.
It's a lot easier to pass two collections to a method in Java than to a sub in Perl.
List <Integer> aList = Arrays.asList( new int [] { 1, 3, 5 }); // probably missing some more type stuff in <>
Map <String, String> aMap = new HashMap <String, String> ();
aMap.put( "name", "Joe");
aMap.put( "ID", "42"); // I need to check if Java 8 has map literals a la Groovy...
doSomething( aList, aMap);
...
void doSomething( List <Integer> aList, Map <String, String> aMap) {
System.out.println( "First: " + aList.get( 0) + ", Name: " + aMap.get( "name") );
}
--- Perl ---
&do_something( [ 1, 3, 5 ], { 'name' => 'Joe', 'ID' => '42 });
...
sub do_something {
my( $list_ref, $hash_ref) = @_;
printf "First: %d, Name: %s\n", ${ $list_ref }[ 0 ], ${ $hash_ref }{ 'name' };
}
------
I'm not seeing that much of a difference in parameter passing, other than the explicit reference/dereference syntax.
Of course Java doesn't require 500 line methods. But the bondage and discipline imposed is independent of whether or not readable code will be produced.
I actually like strongly typed languages for larger programs, but prefer something more fast and loose for smaller ones. TMTOWTDI!
You can drop the inner array, asList takes variable number of arguments.
> // I need to check if Java 8 has map literals a la Groovy...
Sadly not, IIRC they've backed off from literals towards a Guava style static factory methods, which I'm not thrilled about.
> I'm not seeing that much of a difference in parameter passing, other than the explicit reference/dereference syntax.
So let's say I'm a newbie Perl developer just exploring subs.
sub stuff {
my ($a, $b) = @_;
print "$a and $b\n";
}
my $a = 1;
my $b = 2;
stuff($a, $b);
It works! Hurrah. Feeling clever, I move onto collections. sub stuff {
my (@a, %b) = @_;
print "$a[0] and $b{A}\n";
}
my @a = (1);
my %b = (A => 2);
stuff(@a, %b);
And it doesn't work at all. @a has some additional values, and %b is undef.So yes, let's use references.
sub stuff {
my ($a, $b) = @_;
print "${$a}[0] and ${$b}{A}\n";
}
my @a = (1);
my %b = (A => 2);
stuff(\@a, \%b);
Except now, I have two ways of working with Perl's collections, two separate sets of sigils, and all because I wanted to pass two collections into a function and Perl treats function arguments as a collection, and Perl implicitly flattens collections.The difference I see, as a Perl newbie only working with it out of necessity, is that having (because you need it because of earlier design choices) more than one way of operating on data structures, violates the principle of least surprise.
printf "First: %d, Name: %s\n", $list_ref->[ 0 ], $hash_ref->{ 'name' };No final "right" or "wrong" choice for all use cases.
YALT -- yet another languagewar troll.
Something like religion then, were people hearing voices long ago got followers -- but today generally are locked up? :-)
I programmed in Perl for CGI in the mid 90s and didn't see anything wrong with it. It was weird, but I had programmed with much worse before then (Lotus Notes Script...whew), so I wasn't really bothered by it. That being said, I see no reason ever to write another line of Perl again.