I think Mathias's point, that it is exactly as useful or useless as 
`codePointAt`, is a reasonable one. However,

> This method is just as useful as `String.prototype.codePointAt`. If that 
> method is included, so should `String.prototype.at`. If `String.prototype.at` 
> is found not to be useful, `String.prototype.codePointAt` should be removed 
> too.

This does not follow. The choice is not between adding two useless methods and 
adding zero. There is no reason to exclude the possibility of adding only one 
useless method.

But anyway, as some people seem to think that both methods are in fact 
useful---including Rick, who has agreed to champion---I agree with Scott that 
after having said our piece it's time to exit the thread.

-----Original Message-----
From: es-discuss [mailto:[email protected]] On Behalf Of C. Scott 
Ananian
Sent: Friday, February 14, 2014 12:12
To: Mathias Bynens
Cc: [email protected] list
Subject: Re: `String.prototype.symbolAt()` (improved 
`String.prototype.charAt()`)

Yes, I know what `String#at` is supposed to do.

I was pointing out that `String#at` makes it easy to do the wrong thing.  If 
you do `Array.from(str)` then you suddenly have a complete random-access data 
structure where you can find out the number of code points in the String, 
iterate it in reverse from the end to the start, slice it, find the midpoint, 
etc.  `Array.from` looks like an O(n) operation, and it is -- so it encourages 
developers to cache the value and reuse it.

That said, I can see where a lexer might want to use `String#at`, being careful 
to do the correct index bump based on `result.length`.
However, the fastest JS lexers don't create String objects, they operate 
directly on the code point (see http://marijnhaverbeke.nl/acorn/#section-58).  
So I'm -0, mostly because the name isn't great.  But I have exactly zero say in 
the matter anyway.  So I'll shut up now.
 --scott
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to