4 ms·
I think this bears trumpeting: strings are hard! It's easy to gloss over their issues via garbage collection and pervasive heap allocation, but once you're in a
by kibwen 12y ago
I think this bears trumpeting: strings are hard! It's easy to gloss over their issues via garbage collection and pervasive heap allocation, but once you're in a domain where you care about stack allocation and avoiding copies you start running into difficult tradeoffs (above and beyond even the question of string encoding, which is a different beast altogether).
Speaking as a dynamic language programmer who's trying to break into systems programming, it took a long time for me to fully appreciate the difficulties around strings. And now that I do, I'm perpetually paranoid about how many allocations my Python programs are doing behind the scenes...
- rwmj 12y agoChrome is a web browser, not a real time operating system.
- ajuc 12y agoIf you care about performance use std::performant_but_tricky_string. 99% of code doesn't care about string-related performance, but needs string anyway.
- crpatino 12y agoIf you care about performance at all, strings are going to slow you down in unexpected and counter-intuitive ways. Far better if you pass around text data as binary buffers (with metadata describing encoding, please), and only convert those to strings once they are ready to be consumed by the user (which is typically not where performance bottlenecks show up anyways)
- ajuc 12y agoIf you care about performance a lot, it may well be that most of your critical paths are in numeric code, and strings are only used to read input and write output. So you should just use strings unless profiling shows problems there.
- Dewie 12y agoI wonder how cavalier people treat strings when they feel like "primitive values" in the language - like Java having the (+) operator for concatenation. I don't agree with the view that "costly" (it's all relative, but anyway) operations should look "costly" (i.e., be a relative eyesore). But I don't doubt that it can affect one's mindset.