4 ms·
Riddle me this: name one algorithm that requires #2 string length. I'll name a way that it doesn't matter. The reason this isn't an issue is because it's nearl
by sillysaurusx 5y ago
Riddle me this: name one algorithm that requires #2 string length. I'll name a way that it doesn't matter.
The reason this isn't an issue is because it's nearly impossible to think of a legit use case.
- kaetemi 5y agoNot length directly in itself, but the abstraction seems applicable to text editing controls.
- arcticbull 5y agoThat’s both #2 and #3, because Unicode characters can have various widths including zero. Gotta find out how far to move the cursor.
- ygra 5y agoThe Unicode character doesn't really have an intrinsic width; the font will define one (and I think a font could define a glyph even for things like zero-width spaces). But as soon as you want to display text you'll get into all sorts of fun problems and string length is most likely never applicable in any way. At that point the Unicode string becomes a sequence of glyphs from a font with their respective placements and there's no guaranteed relationship between the number of glyphs and the original number of code points, anyway.
- s_gourichon 5y agoSince you ask for an example: moving the cursor in a terminal-based text editor requires #2 string length. That said I understand your point about focusing on what is actually needed.
- yorwba 5y agoMoving the cursor doesn't require string length, it requires finding the new cursor position. You can compute #2 length by moving the cursor one grapheme cluster at a time until you hit the end, but if you only need to move the cursor once, the length is irrelevant. (Also, cursor positions in a terminal-based text editor don't necessarily correspond to graphemes.)
- tshaddox 5y agoIt’s pretty crucial to the game Hangman.
- 3np 5y ago“Full name” has a minimum length of 1.
- dodobirdlord 5y agoEven for this you probably wouldn't want to use #2, because some grapheme clusters are composed to create ligatures and wouldn't be used outside of composing to create a ligature, so they shouldn't ever form a valid string by themselves. But by the #2 analysis this would read as "length 1".
- 3np 5y agoCan you think of a way to do stricter while still not rejecting valid names? I don’t have one. (Except the airline model of “only A-Z” but it seems silly to stay there just because people could slip ligatures through the form)
- deleted 5y ago[deleted]