I tried both for a while when I was getting into programming, and one huge thing that has always bothered me about Perl is the strange behavior with changing sigils. Here's what I mean: $foo is a scalar @foo is an array $foo[0] is the first element of @foo, instead of @foo[0] As far as I know, Larry Wall's rationale as a linguist was that in English, one would say "this apple" and "these apples", but "this third appl…
Why is this difficult to understand? my @foo = qw(1 2 3); $foo[0] = 1; you are referencing an array and returning a scalar. the sigil represents a scalar which is what is returned. A list isn't being returned, so why should the sigil represent that?
Ask HN: Why do people consider Ruby better than Perl or vice versa?
21–30 of 32 posts
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#22I believe the Ruby community is very pro-Perl. I enjoyed Perl myself and Ruby seems to have a lot of the same soul to it. I usually say Ruby is everything I loved about Perl with none of what I disliked/hated.
I'm an old Perl hacker but do most of my work in Ruby these days -- and love it. I'll always have a soft spot for Perl, and will never forget how it helped build the Internet. But to me, Ruby makes Perl look like Java.
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#23Earlier quoted context omitted.
Why is this difficult to understand? my @foo = qw(1 2 3); $foo[0] = 1; you are referencing an array and returning a scalar. the sigil represents a scalar which is what is returned. A list isn't being returned, so why should the sigil represent that?
Why require context-dependent sigils when you don't need to? Eliminate the unnecessary.
That's a circular argument. So is "Why not require them when you need them?"
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#24Earlier quoted context omitted.
I'm an old Perl hacker but do most of my work in Ruby these days -- and love it. I'll always have a soft spot for Perl, and will never forget how it helped build the Internet. But to me, Ruby makes Perl look like Java.
Can you explain the "makes perl look like java" comment? how does perl look like java?
Perl:
my $x = 'Apple Carrot Banana';
# sort them into an array
my @y = sort split(' ', $x);
# do we have more than 2 elements? (just a random test)
if (scalar(@y) > 2) {
print "we've got ", scalar(@y), " elements!\n";
} else { print "insufficient elements. fail.\n";
}Ruby:
x = 'Apple Carrot Banana'
y = x.split(' ').sort
if (y.size > 2)
puts "we've got #{y.size} elements!"
else puts 'insufficient elements. fail.'
endRuby just seems more elegant to me, more programmer-friendly. YMMV.
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#25Earlier quoted context omitted.
Can you explain the "makes perl look like java" comment? how does perl look like java?
I'm kind of kidding, but Ruby lets you do things more elegantly than you can in Perl, and with less verbosity (hence the Java comment). It's really a syntax issue that I'm talking about, but it matters a lot for readability and language usability. Perl: my $x = 'Apple Carrot Banana'; # sort them into an array my @y = sort split(' ', $x); # do we have more than 2 elements? (just a random test) if (scalar(@y) > 2) { pr…
my $x = 'Apple Carrot Banana';
my @y = $x->split(' ')->sort;
if (@y > 2) {
say "we've got ${\@y->size} elements!";
} else {
say "insufficient elements. fail.";
}Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#26Earlier quoted context omitted.
I'm kind of kidding, but Ruby lets you do things more elegantly than you can in Perl, and with less verbosity (hence the Java comment). It's really a syntax issue that I'm talking about, but it matters a lot for readability and language usability. Perl: my $x = 'Apple Carrot Banana'; # sort them into an array my @y = sort split(' ', $x); # do we have more than 2 elements? (just a random test) if (scalar(@y) > 2) { pr…
A modern Perl programmer might write something much more elegant: my $x = 'Apple Carrot Banana'; my @y = $x->split(' ')->sort; if (@y > 2) { say "we've got ${\@y->size} elements!"; } else { say "insufficient elements. fail."; }
use 5.12.2; # enables modern features
my $x = 'Apple Carrot Banana';
my @y = sort split ' ', $x;
say @y > 2 ? "we've got ${\scalar @y} elements!"
: 'insufficient elements. fail.';
Not everything needs to be an Object. Not every call needs to be a method call. Some people think better with procedures, some people think better with objects.One of the reasons I personally like Perl is I can use which ever one is appropriate to the problem domain.
Edit: forgot the `sort` call.
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#27"Perl is often a stereotyped as unreadable, but it's largely up to the writers of the code itself to make it _that_ illegible; it's not a consequence of the language." Well, one argument is that the language (and community) should encourage good/readable/maintainable code.
By and large Modern Perl code is strongly encouraged to be readable, maintainable with a sound well engineered basis. If someone is telling you it isn't, they haven't paid attention for half a decade.
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#28Switched from Perl to Ruby in 2006. Things I like off the top of my head: One variable type. This makes references unnecessary. Also, everything that can be stored in a variable is an object. I can remember the Ruby syntax for defining a class. In Perl I had to look it up every time. Also Perl has two competing class systems. Methods by default take a fixed number of arguments and there are no implicit conversions be…
However either you've totally missed the last four years in Perl. Perl has been challenged by Ruby, Python and Perl6. Because of this we've had a lot of developments that you gloss over or ignore.
> I can remember the Ruby syntax for defining a class. In Perl I had to look it up every time. Also Perl has two competing class systems.
The Perl Syntax for defining a class is pretty straight forward. I'm awfully sure I haven't had to look it up in a decade:
package Foo;
sub new { my $class = shift; bless {}, $class }
1;
I'm not sure what the "competing class" system you're referring to is though. Perhaps you mean Moose (first released in 2006 when you left). The assumption that it is "different" is incorrect because Moose does roughly the above, except the `new` method is inherited from a base class. The Moose syntax here is: package Foo;
use Moose;
1;
Given the Moose syntax, I'm not sure what is harder to remember than Ruby's syntax: class Foo
end
Additionally there is MooseX::Declare which hacks the Perl parser/tokenizer to allow new keyword syntax (a feature added to core 5.12) allowing you to say: class Foo { }
> Good Perl practice involves boilerplate such as 'use strict'. I hear about lint tools and such and it makes me think the situation has gotten worse since 2006.Yes it is unfortunate that Larry didn't predict what the good defaults would be in 1987 (Perl1) or 1994 (Perl5). With Perl 5.12 good Perl practice involves:
package Foo;
use 5.12;
I'm not sure that this is necessarily "worse" than 2006's: package Foo;
use strict;
use warnings;
It is 2/3rds of the line count, but really we're talking about one line. Additionally I'm a very active member of the Perl community and I haven't heard about "lint tools". Perhaps you mean `perltidy`? This isn't a lint tool, it's a source code beautifier ... like html-tidy.> Ruby IO operations throw exceptions when they fail. Hence you don't need the '|| or die "could not open!"' idiom.
You can use the (now in core) `autodie` pragma to eliminate this idiom from Perl too. Yes it's unfortunate that the idiom could spread for the first 20 something years of Perl making the nearly-anal-backwards-compatible defaults not enable it.
> The Ruby Array class and the Enumerable module are good. I've become dependent on methods that aren't as readily available in Perl: include? each_with_index all? any? permutation. Also the intersection and union operators: & and |
These exist on CPAN in various modules. List::Util, List::More::Util etc. Yes it is unfortunate that they're not more easily available. This is part of the price paid to backwards compatibility demons and keeping the Perl standard library (relatively) small.
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#29Earlier quoted context omitted.
But to the question of whether a language can be intrinsically "illegible", I'd say that it is easier to write "hard-to-read" code in some languages than others. The conventions that a language community shares often lead to easier or harder to read code. In the Perl community, clever code which solves a problem is highly valued. In the Python community (as the Python Cookbook famously says) "To describe something as…
> I don't know enough about Ruby's community to say whether they have their own view about the relative merits of the clever/clean approaches or if they value something else entirely. Although I think some groups are starting to pick up an anti-clever view of these (the Merb movement probably helped), but you can almost pick any random ruby github project and there will be some custom magic under the hood. Not saying…
Re: Ask HN: Why do people consider Ruby better than Perl or vice versa?
#30Earlier quoted context omitted.
I'm kind of kidding, but Ruby lets you do things more elegantly than you can in Perl, and with less verbosity (hence the Java comment). It's really a syntax issue that I'm talking about, but it matters a lot for readability and language usability. Perl: my $x = 'Apple Carrot Banana'; # sort them into an array my @y = sort split(' ', $x); # do we have more than 2 elements? (just a random test) if (scalar(@y) > 2) { pr…
A modern Perl programmer might write something much more elegant: my $x = 'Apple Carrot Banana'; my @y = $x->split(' ')->sort; if (@y > 2) { say "we've got ${\@y->size} elements!"; } else { say "insufficient elements. fail."; }
my $x = 'Apple Carrot Banana';
my @y = $x.words.sort;
if @y > 2 {
say "we've got {@y.elems} elements!";
} else {
say "insufficient elements. fail.";
}