Comment On Many Shades of Cout

For the most part, the Message Queue Processor at Andy's company is not a terrible application to work with. Most changes – such as setting up a new queue, changing trigger times, and so forth – can be done by changing configuration files. At least, that was Andy's opinion before having to make a change to its code… [expand full text]
« PrevPage 1 | Page 2Next »

Re: Many Shades of Cout

2007-07-09 09:03 • by Xepol
That's one way to deal with C's case sensitivity I suppose. Or is it its user insensitivity?

Re: Many Shades of Cout

2007-07-09 09:03 • by burntfuse
"Find and replace" is sooo useful...

Re: Many Shades of Cout

2007-07-09 09:05 • by Lastchance
But they got it up and running faster, so it was the right decision from a business standpoint.

Yeah. Right.

Re: Many Shades of Cout

2007-07-09 09:11 • by Lloyd (unregistered)
Ho, that was a funy one!!

Re: Many Shades of Cout

2007-07-09 09:17 • by pitchingchris
Putting those declares as a lazy workaround so they don't have to spell it right is just stupid. Might as well shoot yourself in the foot, cause its going to hurt later anyway.

Re: Many Shades of Cout

2007-07-09 09:25 • by Ackshooerry (unregistered)
Isn't the real WTF here that Andy would want to use cOut as a variable name? I mean, if I wanted to make string consisting of a bunch of Fs, I wouldn't call it printF and if I wanted to determine if some value was in a set called T, I wouldn't delcare a boolean called inT. Do I have a point, or do I have no idea what I'm talking about (it's been about 10 years where I did any programming of consequence)?

Re: Many Shades of Cout

2007-07-09 09:27 • by SilverViper2k
At least he sorted the lines somewhat binary:
0000 COUT
0001 COUt
0010 COuT
0011 COut
etc.

Re: Many Shades of Cout

2007-07-09 09:28 • by espinafre (unregistered)
This is a What The Fuck (capitalized) like i've not seen in a loong time

Re: Many Shades of Cout

2007-07-09 09:29 • by lbp (unregistered)
144509 in reply to 144505
Ackshooerry:
Isn't the real WTF here that Andy would want to use cOut as a variable name? I mean, if I wanted to make string consisting of a bunch of Fs, I wouldn't call it printF and if I wanted to determine if some value was in a set called T, I wouldn't delcare a boolean called inT. Do I have a point, or do I have no idea what I'm talking about (it's been about 10 years where I did any programming of consequence)?


I was thinking the same. It's kinda two wtfs in one. Andy does one by choosing a potentially ambiguous name, the previous program did one by being incapable of keeping their fingers on (or off) the shift key.

Re: Many Shades of Cout

2007-07-09 09:46 • by death
Ahem. And running replace on code to fix the typos was too onerous? I mean WTF? This was apparently the only clash with a variable so running a replace was safe.

BTW: to whiners about ambiguity of c0ut, look carefully. Its not O. its a zero. NOT ambiguous even least bit without the block from nutty spelling-indifferent coder.

EDIT: My bad. It is an O. The font fools ya.

Re: Many Shades of Cout

2007-07-09 09:49 • by zip
144513 in reply to 144505
Ackshooerry:
Isn't the real WTF here that Andy would want to use cOut as a variable name? I mean, if I wanted to make string consisting of a bunch of Fs, I wouldn't call it printF and if I wanted to determine if some value was in a set called T, I wouldn't delcare a boolean called inT. Do I have a point, or do I have no idea what I'm talking about (it's been about 10 years where I did any programming of consequence)?


Um, there's no way a poor variable name (cOut) is as bad as def'ing every possible capitalization of a keyword because you can't friggin type.

Re: Many Shades of Cout

2007-07-09 10:03 • by webrunner
I like ucout and ucot. I wonder if there's an epcot.

Re: Many Shades of Cout

2007-07-09 10:06 • by Wizou (unregistered)
I'm wondering why the code wouldn't compile ?
It is legal to declare
void Serialize(ostream& cout, vector<CRcpt>& rRcpt) {  ...  }

and use of "cout" inside the function would correctly refers to the parameter.

The only problem I see is if he wants to access the global "cout" from inside the function (for debugging purpose??)

Re: Many Shades of Cout

2007-07-09 10:09 • by anonymous (unregistered)
144516 in reply to 144514
webrunner:
I like ucout and ucot. I wonder if there's an epcot.


Let's hope there's no UCUNT.

Re: Many Shades of Cout

2007-07-09 10:11 • by Ian McCall (unregistered)
144517 in reply to 144509
I suspect the reverse - I suspect all the capitalisations were defined precisely to stop people declaring variables called some variant of cout. It's a bad name to be using.


Cheers,
Ian

Re: Many Shades of Cout

2007-07-09 10:13 • by Licky Lindsay
Every now and then we get one that is just too hard to believe. Why would anybody *do* such a thing? How could anybody have ever gotten away with such a thing, if they tried it?

Was this project coded by chimpanzees or something, with one (human) coder in charge of setting up enough DEFINEs so that the random keybashing of the chimps might have a chance of compiling?

Re: Many Shades of Cout

2007-07-09 10:15 • by S (unregistered)
144519 in reply to 144500
Xepol:
That's one way to deal with C's case sensitivity I suppose. Or is it its user insensitivity?


Ahem... cout? In C?

More likely C++

Re: Many Shades of Cout

2007-07-09 10:16 • by Licky Lindsay
144521 in reply to 144517
Ian McCall:
I suspect the reverse - I suspect all the capitalisations were defined precisely to stop people declaring variables called some variant of cout. It's a bad name to be using.


Did they similarly protect all the other keywords in the language and all other functions, types, and variables of the standard library? Why stop with cout?

Also, "ucot" is not close enough to cout to be deserve being caught by such a trap. Unless someone was just being an asshole.

Re: Many Shades of Cout

2007-07-09 10:26 • by jethrotull (unregistered)
144522 in reply to 144512
death:

BTW: to whiners about ambiguity of c0ut, look carefully. Its not O. its a zero. NOT ambiguous even least bit without the block from nutty spelling-indifferent coder.

EDIT: My bad. It is an O. The font fools ya.

You look :)
It would be ambiguos even if it was zero.
Any guidebook of good programing practices tells you not to use O or l where it could be mistaken for zero and one respectively.

Re: Many Shades of Cout

2007-07-09 10:46 • by EvanED
This is worse than making a CPP macro named current.

Yes, I got bit by that. Caused me twenty minutes of confusion, frustration, and swearing at GCC for not making sense.

Re: Many Shades of Cout

2007-07-09 10:51 • by jack (unregistered)
144524 in reply to 144521
Licky Lindsay:
Ian McCall:
I suspect the reverse - I suspect all the capitalisations were defined precisely to stop people declaring variables called some variant of cout. It's a bad name to be using.


Did they similarly protect all the other keywords in the language and all other functions, types, and variables of the standard library? Why stop with cout?

Also, "ucot" is not close enough to cout to be deserve being caught by such a trap. Unless someone was just being an asshole.

The hiccough would come in like so:
void sayFoo( std::ostream &Cout ) {
cout << "Foo!" << std::endl; // Whoops!
}

As an aside, the problem here -- if this were a spell-check for the incredibly lazy -- is the use of #defines. If you declare:
std::ostream &Cout = cout;
std::ostream &cOut = cout;
...

You get the spell-check effect without removing the ability of others to use the name in other contexts.

Re: Many Shades of Cout

2007-07-09 11:09 • by k (unregistered)
144529 in reply to 144516
I am a pretty dyslexic typist, often getting the right letters in the wrong order. Sometimes my commonest mis-typing of 'Count' seems strangely appropriate to my mood.

Re: Many Shades of Cout

2007-07-09 11:13 • by Number6 (unregistered)

"Avoid macros. Do not ever ever ever even consider starting to think about writing a macro that is a common word or abbreviation." -- Herb Sutter

Re: Many Shades of Cout

2007-07-09 11:13 • by kupal (unregistered)
I bet the guy who wrote that was a vb programmer...
"nah, if we used vb we wouldn't have this problem, stupid c++ compiler!"

Choose VB!!!
Choose VB!!!
Choose VB!!!
Choose VB!!!
Choose VB!!!
Choose VB!!!
Choose VB!!!

captcha : kungfu

Re: Many Shades of Cout

2007-07-09 11:20 • by Mark H (unregistered)
one developer at my first job added macros like these to every project he worked on:
#define FLASE FALSE
#define retrun return

very confusing when you spot a typo and yet the code compiles anyway.

Re: Many Shades of Cout

2007-07-09 11:26 • by j (unregistered)
144541 in reply to 144529
k:
I am a pretty dyslexic typist, often getting the right letters in the wrong order. Sometimes my commonest mis-typing of 'Count' seems strangely appropriate to my mood.


Maybe you should go into management.

Re: Many Shades of Cout

2007-07-09 11:27 • by Licky Lindsay
144542 in reply to 144524
jack:

The hiccough would come in like so:
void sayFoo( std::ostream &Cout ) {
cout << "Foo!" << std::endl; // Whoops!
}


I still go with my "monkeys with typewriters" theory.

It was the best of times, it was the blerst of times.

Re: Many Shades of Cout

2007-07-09 11:38 • by dhromed
144550 in reply to 144542
I would like to slap the original developer around a bit with a large cout.

Re: Many Shades of Cout

2007-07-09 12:04 • by Anonymous (unregistered)
Now, if only there was an easy way to allow the "public" keyword in Java to be redefined as "pubic", because I find myself making that typo quite a bit. Not sure why.... :-/

Re: Many Shades of Cout

2007-07-09 12:19 • by Zygo (unregistered)
144567 in reply to 144505
Ackshooerry:
Isn't the real WTF here that Andy would want to use cOut as a variable name? I mean, if I wanted to make string consisting of a bunch of Fs, I wouldn't call it printF and if I wanted to determine if some value was in a set called T, I wouldn't delcare a boolean called inT. Do I have a point, or do I have no idea what I'm talking about (it's been about 10 years where I did any programming of consequence)?


To me, CamelCase has a direct mapping to "camel_case" (and in languages where '-' is valid in identifiers, 'camel-case'), so I read

printF

as equivalent to

print_f

although I wouldn't use

inT

because that's obviously an object of type 'in', as in:

typedef struct in in_t;

Besides, everyone<tm> knows boolean function names are of the form "predicateP", as in

inTP

Re: Many Shades of Cout

2007-07-09 12:33 • by Zygo (unregistered)
144574 in reply to 144539
Mark H:
one developer at my first job added macros like these to every project he worked on:
#define FLASE FALSE
#define retrun return

very confusing when you spot a typo and yet the code compiles anyway.


Feh. If you can't spell, you can't program computers.

It's especially bad when you have big C++ class hierarchies full of virtual methods--the code compiles happily, but the behavior at runtime is as random as the spelling.

It almost makes you want to have some way to declare in C++ "this method overrides an existing virtual method of the base class, and if there isn't one then stop compiling RIGHT NOW." Actually there's nothing almost about it, I really want that feature.

In the past I found a way to deal with this: if I find a single spelling mistake in the code, I reject the entire code submission at review time, and I don't say where the error was. (Just to prevent all coding from coming to a dead halt, I publish a list of misspelled/correctly spelled word pairs to the group as needed). The worst offender got some kind of spell-checking code editor plugin instead of learning to spell on his own, but at least it fixed his code for him.

Re: Many Shades of Cout

2007-07-09 12:43 • by joe.edwards
144577 in reply to 144574
Zygo:

It almost makes you want to have some way to declare in C++ "this method overrides an existing virtual method of the base class, and if there isn't one then stop compiling RIGHT NOW." Actually there's nothing almost about it, I really want that feature.


C# has the override keyword, that will stop compilation if the parent class doesn't have any such method. It also has the new keyword that specifies that your method just happens to mask another with the same signature, but the parent shouldn't use it.

Addendum (2007-07-09 12:56):
You could also use pure virtual methods, since you're using C++. It will stop compilation when it doesn't see a matching override.

Personally, I never want to go back to C++ since using C#.

Re: Many Shades of Cout

2007-07-09 13:20 • by Worf (unregistered)
144586 in reply to 144513
zip:
Um, there's no way a poor variable name (cOut) is as bad as def'ing every possible capitalization of a keyword because you can't friggin type.


And cOut may be a very natural variable name at that. After all, it may be a character you want to output somewhere. Or it could be the output character mode, or plenty other meanings that are perfectly logical...

Re: Many Shades of Cout

2007-07-09 13:47 • by James (unregistered)
Not included, but immediately below those lines:


// Just in case...
#define String string
#define strnig string
#define strng string
#define stringg string
...
...


You can't be too careful, right?

Re: Many Shades of Cout

2007-07-09 13:51 • by Namespace (unregistered)
144592 in reply to 144515
That's how namespaces are your friends.

void Serialize(ostream& cout, vector<CRcpt>& rRcpt)
{
cout << "Hi, this is the argument cout";
std::cout << "Hello, this is the global cout";
::cout << "Howdy, this is the ultimate global cout."
<< "Note that I don't belong to any namespace";
}

Re: Many Shades of Cout

2007-07-09 13:58 • by Namespace (unregistered)
144594 in reply to 144515
Sorry for the duplicate post, I didn't understand the difference between the reply and quote button. I thought replying to that comment would have some link to that comment. Anyways, here is the original post I replied to so you have some context.

Wizou:
I'm wondering why the code wouldn't compile ?
It is legal to declare
void Serialize(ostream& cout, vector<CRcpt>& rRcpt) {  ...  }

and use of "cout" inside the function would correctly refers to the parameter.

The only problem I see is if he wants to access the global "cout" from inside the function (for debugging purpose??)


That's how namespaces are your friends.

void Serialize(ostream& cout, vector<CRcpt>& rRcpt)
{
cout << "Hi, this is the argument cout";
std::cout << "Hello, this is the global cout";
::cout << "Howdy, this is the ultimate global cout."
<< "Note that I don't belong to any namespace";
}

Re: Many Shades of Cout

2007-07-09 14:05 • by Namespace (unregistered)
Oh, I see.

"144592 in reply to 144515"

So there was a link to the comment I replied to. Oops.

Re: Many Shades of Cout

2007-07-09 14:24 • by SuperousOxide
144597 in reply to 144504
I've considered doing this sort of thing, but in the shell rather than the code. When I make stupid typos typing in the shell they don't get preserved for posterity.

Re: Many Shades of Cout

2007-07-09 14:28 • by bobday
144600 in reply to 144595
Namespace:
Oh, I see.

"144592 in reply to 144515"

So there was a link to the comment I replied to. Oops.

No one's holding it against you, baby. The forum's interface is terrible.

Re: Many Shades of Cout

2007-07-09 14:44 • by Ackshooerry (unregistered)
144601 in reply to 144586
Worf:
zip:
Um, there's no way a poor variable name (cOut) is as bad as def'ing every possible capitalization of a keyword because you can't friggin type.


And cOut may be a very natural variable name at that. After all, it may be a character you want to output somewhere. Or it could be the output character mode, or plenty other meanings that are perfectly logical...

Like I wrote above, there are perfectly logical reasons for why one might want to name a variable printF or inT as well, but that doesn't make it okay. I find it ironic that Andy would submit this code as a WTF, when tomorrow I could probably submit Andy's code with a comment like, "This guy at my work uses variables with names like cOut. I mean, WTF?!?" and he would ragged on in the comments. Those who don't live in WTF-proof houses, and all that...

Re: Many Shades of Cout

2007-07-09 15:16 • by AdT (unregistered)
You forgot to mention

<code>
#define coitus cout // What The Fuck?
</code>

Re: Many Shades of Cout

2007-07-09 16:39 • by Pilothaz
it is scary that someone would do that, too much effort. Just Find/Replace the vble one Case sensitive.

Re: Many Shades of Cout

2007-07-09 18:18 • by jaymz (unregistered)
144669 in reply to 144513
with regard to def'ing the combos of capitalization versus using a VERY bad variable name (in C anyways), im not so sure the former is worse. at least the multiple definitions are to a keyword and not a variable type itself,

Re: Many Shades of Cout

2007-07-09 18:22 • by jaymz (unregistered)
144671 in reply to 144669
by the above i mean to say the def's are of a keyword rather than using a bastardization of a keyword as a variable (oooh, long nite). i dont know why you would want to use a keyword as a variable

Re: Many Shades of Cout

2007-07-09 19:07 • by foxyshadis
144677 in reply to 144567
Zygo:
To me, CamelCase has a direct mapping to "camel_case" (and in languages where '-' is valid in identifiers, 'camel-case'), so I read

printF

as equivalent to

print_f

although I wouldn't use

inT

because that's obviously an object of type 'in', as in:

typedef struct in in_t;

Besides, everyone<tm> knows boolean function names are of the form "predicateP", as in

inTP
That should probably be inTPS.

bobday:
Namespace:
Oh, I see.

"144592 in reply to 144515"

So there was a link to the comment I replied to. Oops.

No one's holding it against you, baby. The forum's interface is terrible.
What's sad is how much better it is than the old (still-breathing in the sidebar) one. Except avatars. I really miss avatars, have no idea who anyone is anymore. ;_;

Re: Many Shades of Cout

2007-07-09 19:42 • by gwenhwyfaer
144678 in reply to 144539
Mark H:
one developer at my first job added macros like these to every project he worked on:
#define FLASE FALSE
#define retrun return

very confusing when you spot a typo and yet the code compiles anyway.

You know, all the need for this would go away if only symbol tables used fuzzy matching. In fact, that's such an obvious(ly good) idea that I'm surprised no compiler has adopted it already - not even Intercal, which is usually such a pioneer of language features whose usefulness has yet to garner the widespread appreciation they deserve.

Thank goodness for the C preprocessor. How else could one so gracefully make up for such a linguistic omission?

Re: Many Shades of Cout

2007-07-09 19:49 • by Kain0_0
144681 in reply to 144515
Wizou:
I'm wondering why the code wouldn't compile ?
It is legal to declare
void Serialize(ostream& cout, vector<CRcpt>& rRcpt) {  ...  }

and use of "cout" inside the function would correctly refers to the parameter.

The only problem I see is if he wants to access the global "cout" from inside the function (for debugging purpose??)


If he did a "using namespace std;" or a "using std::cout" you in the namespace of this function you could go "::cout" to get the global.

otherwise "std::cout", or if you really want to be pedantic "::std::cout"

(For those of hard of thought - or just woke up - quotes ("") are to be omitted in the rendering of the code)

Re: Many Shades of Cout

2007-07-09 21:22 • by gwenhwyfaer
144686 in reply to 144567
Zygo:
Besides, everyone<tm> knows boolean function names are of the form "predicateP", as in

inTP

...is the given parameter a Thinker...?

Re: Many Shades of Cout

2007-07-10 02:54 • by Bob Loblaw (unregistered)
144704 in reply to 144574
Zygo:
I find a single spelling mistake in the code, I reject the entire code submission at review time, and I don't say where the error was.
Glad I don't work with you, and I'm a meticulously accurate speller.

Re: Many Shades of Cout

2007-07-10 04:59 • by Spud (unregistered)
#define begin {
#define end }
« PrevPage 1 | Page 2Next »

Add Comment