Re:Ask HN: Why do people consider Ruby better than Perl or v...
by matt_p on Sunday January 09, 2011 @08:43PM
(#2087090)
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?
Re:Ask HN: Why do people consider Ruby better than Perl or v...
by jordandanford on Sunday January 09, 2011 @10:37PM
(#2087350)
I understand the idea behind it, but I don't feel like it's any clearer than "foo = [1, 2, 3]; foo[0] = 1" (in Ruby, Python, or something similar). This was even changed in Perl 6 because the different sigils just increased obfuscation: http://en.wikipedia.org/wiki/Perl_6#Sigil_invariance
Re:Ask HN: Why do people consider Ruby better than Perl or v...
by aaronblohowiak on Sunday January 09, 2011 @08:52PM
(#2087115)
Why require context-dependent sigils when you don't need to?
Eliminate the unnecessary.
Re:Ask HN: Why do people consider Ruby better than Perl or v...
by phamilton on Sunday January 09, 2011 @09:19PM
(#2087181)
for the same reason strcmp() returns not just a -1,0, or 1, but a "distance" between the two strings being compared. A function or syntax has multiple uses if additional information is available to the programmer.
Example:
@array = qw(1 2 3); $length = @array;
print $length;
By allowing a non scalar to take an implicit scalar form, we have an extremely useful and quick way to get the length of an array. Nothing that difficult to replace with a len() call, but it's language features like these that make perl ($length = @_ may be the most useful of all) so handy for quick hacks.
Re:Ask HN: Why do people consider Ruby better than Perl or v...
by jordandanford on Sunday January 09, 2011 @10:32PM
(#2087331)
I guess my problem with something like that is that conceptually it doesn't make much sense. There's no obvious reason why assigning an array to a scalar variable would give its length – it doesn't really feel clear or elegant, just unexpected.
$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 apple" instead of "these third apple". The problem is that code isn't a human language, and obeying these rules doesn't make sense and puts additional cognitive strain on the programmer. Basically, having different syntax quirks for scalars, arrays, hashes, and file handles makes code unnecessarily weird, especially when combining them for things like multi-dimensional arrays.