Archive for January 7th, 2011

A bold statement

Friday, January 7th, 2011

Let me make a bold statement:

All functions taking a “const String&” parameter as input are bad.

…where String is either your own custom string class, or std::string, whatever. This is bad, of course, because it forces your users to have a String around. If they get the string from an external source (typically as “const char*”) you just forced them to create a temporary String just to call the function (or worse, the temporary will get created without them even noticing). Since you pass it as a const, you will not modify the text and there is no reason to force people using a String. The proper API just takes a “const char*” parameter.

(Yeah, yeah, I know, it ignores Unicode stuff and loses some minor optimizations when the String class caches the length of the text, whatever, you get the idea of the bold statement. And also, any const function in the String class is stupid, as an old classic GOTW entry showed eons ago).

Finally the truth!

Friday, January 7th, 2011

Just noticed this from http://89.151.96.106/forums/viewtopic.php?f=1&t=54587&start=25

There’s two topics haunting me on this forum:
This one, and a topic where I managed to write that OPCODE was messy code! :)
Pierre Terdiman commented on that, of course. :wink:
That was years ago, but I clearly remember it.
Looking at OPCODE now, of course I realise that it’s actually remarkably clean code! :oops:

All you people who complained about the coding style in OPCODE - you know who you are -, take that! :)

shopfr.org cialis