Hacker News new | ask | show | jobs
by VorpalWay 16 days ago
C and C++ are amongst the worst for working with strings, substrings, etc. It has gotten a bit better in newer versions of C++ (and I don't keep track of changes in C, so not sure what is going on there these days), but it is still far behind most more modern languages.

Python has good string support, as does Rust. I think (though I don't know it myself) Perl is famous for good string handling? Even bash has ok support for working with strings.

So I don't really agree on "aren't many languages", but then again there are a ton of languages I don't know, so maybe those I mentioned are the exception.

2 comments

It’s unclear whether you are talking about the ergonomics of dealing with strings, the flexibility of using encodings other than UTF-8, or whether you mean human-oriented or computer-protocol-oriented string handling. It’s also unclear whether you are talking about using the standard library only or if you include other ubiquitous libraries like ICU.
I was considering standard library here. That said, of the languages I worked in, C/C++ is the most annoying to add additional dependencies in.

I will concede that most languages lack support for anything except ASCII and Unicode these days (usually just UTF8 and UTF16), but legacy encodings are mostly pointless these days. I would argue you should if possible reject them, or if you have to handle them: convert on ingress/egress and use UTF8 internally.

As for your first question I was considering general string handling, how painful is it to do the sort of things I typically end up doing with strings: concatenating, stripping leading / trailing whitespace, finding substrings, splitting on lines or other delimiters, splitting after a specific substring, checking if a string is a prefix/suffix of another, search and replace, etc. What exactly people do will differ from person to person, but I would think these are not uncommon operations. And here traditional C and C++ are really unpleasant (again things have improved a bit in modern C++ but still not great).

I said "strings and encodings". Almost all modern languages break the moment you realise there's more to text than ASCII