News for hackers. Stuff that matters.
Re:Differences Between Perl 5 and Perl 6 by kbenson on Wednesday October 07, 2015 @01:01PM (#10347222)
There's a specific reason why length was deprecated, and the error, which gives alternatives, may give some insight:

    # perl6 -e 'my $string = "foo"; say length $string;'
    ===SORRY!=== Error while compiling -e
    Undeclared routine:
        length used at line 1. Did you mean 'elems', 'chars', 'graphs', 'codes'?
Perl 6 tries to get unicode right. In doing so, it makes a distinction between characters, elements, codepoints and graphemes. At certain points, you may want one or the other of these.

When asking for the length of a string, what are you really asking for? The number of characters? Visible characters, or unicode combining characters? What if it's really the number of bytes in the string you need? Perl 6 makes it easy to determine all of these things in a clear manner. In doing so, it becomes obvious that "length" is ambiguous due to both its common specific role in other languages, and it's meaning when viewed in the context of these different needs.

If you want individual characters, you split the string, if you want access to the underlying data, you call .encode to get the encoding you expect, or you stick it into a Buf or Blob type if you don't actually need string semantics.

(Corrections welcome, I could be wrong at any number of points above).

Re:Differences Between Perl 5 and Perl 6 by spathi_fwiffo on Wednesday October 07, 2015 @01:19PM (#10347373)
That does shed some insight into why a generic Length is missing, but I agree with the sentiment that it is counter intuitive. It does not read right on a quick scan, and I think this is especially important in softly typed languages.

If I see string.chars I expect to see a bucket of char, and not the count of chars. That name needs to be more explicit.

Re:Differences Between Perl 5 and Perl 6 by kbenson on Wednesday October 07, 2015 @01:34PM (#10347508)
I think you are speaking from unfamiliarity with the language and possibly bringing baggage from other languages. In Perl 6, chars is the number of characters in a string, and elems, which is inherited from the Any role, exists on many objects and means the number of elements, as that makes sense for that object.

Perl 6 is not softly typed, it's gradually typed. It's as hard as you want to make it.

> If I see string.chars I expect to see a bucket of char

Why? Is that an expectation that comes from some other language? There's only so much you can expect a language to follow the semantics of other languages. Perl 6 will have it's own quirks, expecting it to conform to some malleable standard based on what some percentage of other languages do is not something I think is entirely fair to expect.

Re:Differences Between Perl 5 and Perl 6 by dragonwriter on Wednesday October 07, 2015 @01:50PM (#10347627)
> Why? Is that an expectation that comes from some other language?

No, the convention that (thing that can be viewed as a collection of subelements in several different ways).(plural name for one kind of subelement) is a property/method providing a collection of the subelements of the named type is not only common in other languages, it is also quite common in Perl 6 -- and even followed (aside from chars) in the Str class specifically; examples include (from Str): univals, lines, words, ords

chars is the odd man out here: charcount or something similar would have been a lot cleaner. (Yes, its consistent with elems, but that seems to be poorly chosen for the same reason; its a plural name, but it provides a single numeric value.)

Re:Differences Between Perl 5 and Perl 6 by acqq on Wednesday October 07, 2015 @04:15PM (#10348741)
In the code I'd make I'd always call these nchars and nelems and it would be intuitively clear (to me too one year after I wrote the code), but Perl 6 seems to like to mess with the accustomed minds. Renaming "for ( ; ; )" which was structurally identical to the C one to the "loop" is easy. Somebody also mentioned renamed ARGV to *ARGS. Examples aplenty.

It seems this and a lot of other details were intentionally made to clash with our habits, as I write in my other comment.

Re:Differences Between Perl 5 and Perl 6 by kbenson on Wednesday October 07, 2015 @02:02PM (#10347728)
I don't necessarily disagree with your reasoning, but I vaguely recall there was quite a bit of debate about the naming of these methods when they changed, and I don't recall the arguments. I have a feeling it's too late to change them now, so it may just have to live on as a quirk of the language.
Re:Differences Between Perl 5 and Perl 6 by dragonwriter on Wednesday October 07, 2015 @02:39PM (#10348009)
> I have a feeling it's too late to change them now, so it may just have to live on as a quirk of the language.

I can see that, and I don't think its all that bad, just suboptimal, and confusing based on more than just expectations shaped by other languages.

Re:Differences Between Perl 5 and Perl 6 by vvanders on Wednesday October 07, 2015 @01:43PM (#10347566)
I think it's a poor selection.

<noun>s always has denoted some sort of collection to me and I'm sure you'll see many people have the same confusion.

Re:Differences Between Perl 5 and Perl 6 by wvenable on Wednesday October 07, 2015 @01:29PM (#10347459)
It's terse which is another curse or benefit of Perl. The less terse method name would be string.numchars or string.charcount.
Re:Differences Between Perl 5 and Perl 6 by a3n on Wednesday October 07, 2015 @02:14PM (#10347812)
If I had been part of the effort, I would have suggested nchars, nelems, etc. chars and elems sounds to me also like I'm going to get a collection of some kind.