3 ms·
There 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 t
by kalleboo 3y ago
There 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?