I'm not an Arduino programmer, but I am a C programmer. And the problem of string types in C -- or, rather, the absence of a first-class string type in C -- is an old but important one.
The fundamental problem is this. In C, you can say things like
int a, b, c, d, f();
a = b + c;
d = f();
And you can say things like
float q, r, s, t();
q = r / s + t();
But you can not say
string x, y, z();
x = y + z();
C has no first-class string type. In pure C, if you want to manipulate strings, you have to use some combination of char []
arrays and char *
pointers. You have to remember to allocate enough memory to hold the strings you're working with today. This can be a real nuisance, and if you get the details wrong, you get strange bugs and crashes.
So, especially if you're a beginning or casual programmer, It Would Be Nice if C had a true, first-class string type. (And of course C++ does have such a type.)
But there's a very good reason true C doesn't have such a type. Manipulating strings is just plain harder than manipulating ints or floats. The reason it's harder is precisely because they're variable-length, and potentially rather large. Under C's philosophy, the best person to make good tradeoffs when it comes to deciding to handle a particular program's strings is that program's author, not the compiler or library writer.
You can write a decently good, decently efficient, high-level, first-class string type. But, it's never going to be as efficient, for every problem, as handcrafted char []
and char **
code would be. Or, if there are a bunch of rules for how to use a first-class string type efficiently, avoiding fragmentation and the like, those rules are probably going to end up being almost as complicated as the runes for using char []
and char *
correctly -- but the whole point of introducing the first-class string type was so that programmers wouldn't have to worry about those low-level details all the time! It's really rather a pretty pickle.