|
|
|
| Non-WTF Job: C++ Developer at Good Grievance (Ronkonkoma, NY) |
| « Developing in Access | 1.1: A New, High-Falutin' Web-Comic » |
"You'd think that the C++ Boolean would be a welcome addition to the language," writes Jake E. "Not so much for our outsourcing company. This is what's now in our constants.h file."
#define TRUE 1 #define FALSE 0 ...snip... #define SUCCESS 0 #define FAILURE 1 ...snip... #define SUCCESSFUL 0 #define FAILURE 1 ...snip... #define OPER_SUCCESSFUL "SUCSESS"
"So," Jake continues, "FAILURE and TRUE are the same value, FAILURE gets defined twice, and SUCCESS is misspelled. And what's the use for all these DEFINEs? Why, function return codes of course!"
string Admin::Update()
{
...snip...
if(!UpdateState())
{
RollBackUpd();
RemoveWorkDir();
return ERR_UPD_STATE;
}
if(CheckInternal())
{
return OPER_SUCCESSFUL;
}
...snip...
return "SUCCESS";
}
"And then there's this usage..."
string returnStr=a.Update();
if(strstr(returnStr.c_str(),"ERROR"))
{
cout << "\tUpdate: "
<< returnStr.substr(6, returnStr.length()).c_str()
<< endl;
return;
}
"Yes," Jake adds, "it returns a literal char*, which is then cast to an STL string on the function return, which is then cast to a c_str in the comparison, which is finally compared with strstr(). All this for a Boolean! "
"Good thing they only check whether the return string contains 'ERROR' and not any of the various misspellings of SUCCESS. Oh, and as for my attempts at showing the boss how bad our outsourced code is? !SUCSESS. After all, the application did work."
|
The "bool" type in C++ is not that hot, especially as it comes to STL. To paraphrase (badly) Scott Meyers, from one of the Effective books: There's nothing wrong with an STL collection of bool, so long as you understand it's not really a collection, and it doesn't really have bools in it.
C++ is a beautiful language; if you have a brilliant mind, it allows you to express things that most other languages can't hope to touch. It's also the idiots' power tool for creating WTFs. My favorite C++ WTF of all time: #define private public #define protected public That, is pain. |
|
Looks to me like the mis-spelling "SUCSESS" might actually be deliberate, so that when you call Admin:Update() you can distinguish between OPER_SUCCESSFUL and actual success!
|
|
Maybi hiz boss wantid to ahdopt a nu, mor lojicul speling ov wurds like sucsess?
Ouch! That was painful to type. |
| « Developing in Access | 1.1: A New, High-Falutin' Web-Comic » |