5 ms·
In that case, it sounds like `length` on Unicode strings simply shouldn't exist, since there is no obvious right answer for it. Instead there should be `codepo
by haberman 3y ago
In that case, it sounds like `length` on Unicode strings simply shouldn't exist, since there is no obvious right answer for it. Instead there should be `codepointCount`, `graphemeCount`, etc.
- Etherlord87 3y agoYou're absolutely correct! `length` is ambiguous - you shouldn't have a `time` argument in a `sleep` function; you should have `milliseconds` and/or `seconds` etc.
- extraduder_ire 3y agoYou could have a Duration argument though. The parallels of string length with the phrase "How long is a piece of string?"[0] make this apparent/amusing. I'm sure I'm not the first person to think that. [0]: https://en.wiktionary.org/wiki/how_long_is_a_piece_of_string https://en.wiktionary.org/wiki/how_long_is_a_piece_of_string
- Etherlord87 3y agoThe `Duration` being a type that implements an interface removing the ambiguity? Like a `DateTime` object does? I think it might be useful to have a function returning a collection of information about text, how many unicode points, how many grapheme clusters, how many syllables, vowels, consonants, special characters… But for performance reasons you probably want separate functions that give you just one of these.
- extraduder_ire 3y agoDateTime, Instant, and Duration are totally different things. I believe I was thinking of a class I remember seeing added to java at one point. Time is probably one of the few things in programming that's even more cursed than strings.
- kalleboo 3y agoThere are basically 2 places where programmers mostly want the "length" of a string: 1. To save storage space or avoid pathological input, they want to limit the "length" of text input fields. E.g., not allow a name to be 4 KB long 2. To fit something on screen Developers mostly used to western languages can approximate both with "number of letters", but the correct answers are For 1. Limit to bytes to avoid people building infinite zalgo characters, but be intelligent about it - don't just crop the byte array not taking into account graphemes. For 2. This sucks, especially for the web, but the only really correct answer here is to render it and check. Did I miss any other common cases?
- mike_hearn 3y agoPresizing buffers, initializing for loop counts ...
- kalleboo 3y agoBuffers should just be working on raw byte arrays without even considering the content (if it's a string or data or whatever). "for loop counts" depends on what you're doing in the loop...
- davidmurdoch 3y agoUnrelated to this post, but you suggested (https://news.ycombinator.com/item?id=37381390 https://news.ycombinator.com/item?id=37381390) I use your company hydraulic.dev for my electron build. I ultimately gave up on it, then someone from node-gyp comment on an issue I opened about it, and provided the solution: https://github.com/electron-userland/electron-builder/issues/7755#issuecomment-1744147677 https://github.com/electron-userland/electron-builder/issues... Just wanted to let you know in case it's a gotcha you might not be aware of that might help you out if you run into similar problems with some of your customer builds.
- mike_hearn 3y agoThanks for the tip! Sorry to hear you gave up on it, it'd be really appreciated if you could email me with some info as to what problems you hit. We're improving our Electron support at the moment (adding ASAR support and so on), so if there's low hanging fruit it'd be good to know where to look. The bug you linked to is a bit confusing, it seems to be a bug in electron-builder (or node-gyp), not Conveyor?