SFML community forums

General => General discussions => Topic started by: FRex on May 12, 2013, 04:34:20 am

Title: Missing const char * overloads
Post by: FRex on May 12, 2013, 04:34:20 am
My question is, why some functions do not have overload for const char * but only const std::string& while const char * would make perfect sense.
Examples are basically all over the SFML with sf::String's constructor being proud example that you can actually pass c-string somewhere without the std::string terrorizing you with memory allocations.
Now: loadFromFile is not such a big deal, few dozen characters at most, unless you're loading things from insane filepaths, but loadFromMemory on sf::Shader is just evil. Shader source is expected to be quite long(at least around few dozens, going up to few hundred at most, but still much more than a path would have).
Also: other loadFromMemory take void * so why does loadFromMemory for Shader break out so much and instead of taking const char * take const std::string& which will probably copy quite a lot characters for no reason, and then call c_str() on that anyway while it could work perfectly good on my const char * that isn't in std::string?
Honestly if there was choice between the two, victory should go to const char *(but I'm not saying to remove std::strings from apis completely, just don't force it, especially with sf::Shader), you can go from std::string or any other reasonable string to const char * easily with c_str() or equivalent but to go from const char * or other string class class to std::string requires a copy.
Title: Re: Missing const char * overloads
Post by: Cornstalks on May 12, 2013, 08:46:07 am
"[...] premature optimization is the root of all evil." - Donald Knuth

While I can't speak for Laurent, I would argue that:
Title: Re: Missing const char * overloads
Post by: Laurent on May 12, 2013, 10:32:22 am
Don't fix what's not broken ;)