On 11/3/14 8:09 PM, Walter Bright wrote:
On 11/3/2014 2:28 PM, Steven Schveighoffer wrote:
I had a very nasty experience with using a template-based API. I vowed
to avoid
it wherever possible.
The culprit was std::string -- it changed something internally from
one version
of libc++ to the next on Linux. So I had to recompile everything, but
the whole
system I was using was with .so objects.
templates do NOT make good API types IMO.
It seems this is blaming templates for a different problem.
If I have:
struct S { int x; };
in my C .h file, and I change it to:
struct S { int x,y; };
Then all my API functions that take S as a value argument will require
recompilation of any code that uses it.
Would you conclude that C sux for making APIs? Of course not. You'd say
that a stable API should use reference types, not value types.
a string is a reference type, the data is on the heap.
But that is not the issue. The issue is that it's IMPOSSIBLE for me to
ensure std::string remains stable, because it's necessarily completely
exposed. There is no encapsulation.
Even if I used a pointer to a std::string, the implementation change is
going to cause issues.
On the contrary, having C-strings as a parameter type has never broken
for me. In later projects, I have added simple "immutable string" type
modeled after D, which works so much better :)
-Steve