On 2014-05-29 06:49, comex wrote:
> On Thu, May 29, 2014 at 12:16 AM, Bardur Arantsson <s...@scientician.net> 
> wrote:
>> No matter how defective the notion of "length" may be, personally I
>> think that people will expect the former, but will be very surprised by
>> the latter. There are certainly cases where the JavaScript version is
>> wrong, but I conjecture that it "works" for the vast majority of cases
>> that people and programs are likely to encounter.
> 
> Why would they expect the former?
[--snip--]

It's behavior that people are used to. My point isn't really whether
it's correct or not -- my point is more about adherence to the Principle
of Least Astonishment. Which being *explicit* here would do by naming it
"byte_len" or "code_point_count" or some such.

> 
> Of course, this could be seen as an argument in favor of naming clarity.

Exactly, and that's really my point.

> 
> Also, I hope nobody uses JavaScript .length for any purpose other than
> what in Rust would be a byte length, since it doesn't actually count
> codepoints...
> 
> '😃'.length
> 2

They do. For e.g. client-side form validation and such. Or course when
you do that you usually also restrict the string content to letters, so
YMMV.

Regards,

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to