From: daniel@... (Daniel Chetlin) Date: 2000-12-10T03:10:02+09:00 Subject: [ruby-talk:6977] Re: Why isn't Perl highly orthogonal? On Sat, 09 Dec 2000 08:54:13 GMT, Terrence Brannon wrote: >One day my boss asked me: "how do you get the length of an array in >Perl?" So I told him: > >scalar @array; > >But of course what irked me is how unintuitive and irregular Perl is >and how this forced my boss to ask me something like that. > >LENGTH $string => length $string >LENGTH @array => scalar @array > >PORTION $string => substring $string, $offset, $length >PORTION @array => @array[$offset..$offset+$length] > >In other words, conceptually similar operations do not map to the same >name in Perl. Why does this make Perl a better and not worse language, >than the intended replacement to Perl, Ruby, which is in fact highly >regular in all places where Perl isn't, with the above being just a >few examples? Perhaps you and your boss see things differently from other programmers regarding both of these examples. I don't think the majority of Perlers identify the length of a string as similar to the size of an array. Why not interpret `length @array' to mean the length of all array elements combined? In fact, the Perlish way to determine the size of an array is extremely natural to me, because the value of an array in scalar context presents the ability to say `if (@array > 4)'. Wonderfully expressive, and much more natural than `if (length @array > 4)', IMO. In your eyes, which one seems better? Similar logic can be applied to your PORTIONs -- no Perl programmer equates substrings with slices. Why do you? Generally, there is quite a major difference between strings and arrays or even lists in Perl. And I don't think you'll find that Ruby is different from Perl in this way. A current thread on ruby-talk is the question of why String#sort and Array#sort do what was perceived to be different things. I suspect you would expect String#sort to sort by character, rather than by line. -dlc fbeel sbe gur gbegherq ynathntr; guvf vf uneq