Earlier quoted context omitted.
It is wrong that "{emoji}".length == 7 -- but it's wrong because there's no such thing as the 'length' of a string out of context. A string should be viewed as an opaque data type with views into it depending on what you're trying to do. You can have its length in the context of storage/retrieval/transmission (UTF-8 byte count), its length in the context of parsing (code points), its length in the context of editing…
What do you mean there is no such thing as a character when grapheme cluster is exactly that? This is also the out-of-context , and people get confused because instead of this human context attribute they've been forced to use all the other alternatives that require more knowledge
It’s not wrong that "🤦🏼♂️".length == 7 (2019)
61–70 of 315 posts
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#62 iex(3)> String.length(" ")
1
Edit: looks like HN doesn't support that emoji in code blocks, at least.Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#63> Python 3’s approach is unambiguously the worst one, though. Did I miss the part where he explains this take? It's made up of 5 valid unicode code units. For a language where you're not supposed to need to know the byte size semantics, the correct length should be 5. What am I missing? The close second being 17, because length in bytes. Is another fine way to represent this data, e.g. what a successful write of some…
Well, why not? There are a lot of things that people would want to call string.length for — drawing little equals signs under text in a terminal, for a frivolous example — where that’s the whole reason they’re making the call. Off the top of my head I’m not really sure how you solve that with variable-width characters if there’s no way to separate out or count them.
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#64Earlier quoted context omitted.
It is wrong that "{emoji}".length == 7 -- but it's wrong because there's no such thing as the 'length' of a string out of context. A string should be viewed as an opaque data type with views into it depending on what you're trying to do. You can have its length in the context of storage/retrieval/transmission (UTF-8 byte count), its length in the context of parsing (code points), its length in the context of editing…
What do you mean there is no such thing as a character when grapheme cluster is exactly that? This is also the out-of-context , and people get confused because instead of this human context attribute they've been forced to use all the other alternatives that require more knowledge
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#65this one one of those things that people point to when comparing languages, but in reality rarely matters. with Go, you just get the number of bytes, which the the correct default thing to do: https://godocs.io/builtin#len if the language default was anything other than this, THAT WOULD BE WRONG and unexpected. I would prefer the default to be the dumb, fast thing. then if I want the slow, fancy thing, I can import s…
(and it's not expected that a character's length is>1 unless you've been conditioned to excpect it)
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#66 perl -e 'use utf8; print length(""). "\n";'
1Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#67Earlier quoted context omitted.
That makes more sense. I'm sure there could be some language out there where a empty strings length could be 7.
Not sure if HN will handle it, but this empty string's length is 7: ' ' ( '\u200b'.repeat(7) ) Edit: HN does not, in fact, handle it.
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#68perl -e 'use utf8; print length(""). "\n";' 1
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#69> Python 3’s approach is unambiguously the worst one, though. Did I miss the part where he explains this take? It's made up of 5 valid unicode code units. For a language where you're not supposed to need to know the byte size semantics, the correct length should be 5. What am I missing? The close second being 17, because length in bytes. Is another fine way to represent this data, e.g. what a successful write of some…
It is wrong that "{emoji}".length == 7 -- but it's wrong because there's no such thing as the 'length' of a string out of context. A string should be viewed as an opaque data type with views into it depending on what you're trying to do. You can have its length in the context of storage/retrieval/transmission (UTF-8 byte count), its length in the context of parsing (code points), its length in the context of editing…
If the user can freely change a font it is impossible to send a string of 3 graphene clusters because you won't know if it actually will show up as 3 to client or a different number.
Re: It’s not wrong that "🤦🏼♂️".length == 7 (2019)
#70Is there a situation where I am going to try to get the length of an emoji and I care about the outcome?