- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
At least he didn't comment every line. I don't waste near as much time on that comment as I would on the following that appearently many stupid teachers require. (Smart teachers will kill you for commenting every line)
The stupid teacher would of course deduct points for mispelling hasSiblings in one of those comments.Admin
I don't think this is that funny, really. You can criticize code for using more lines that what it could but that is being extremely geeky and arrogant. As for the function’s name… well its kind of long right; too long probably. But if you find that to be really humorous and reply sarcastically you really need to find some next hobbies or ways of investing your time.
Admin
We don't actually know the function's name - so it's not that that is being made fun of.
What you seem to have failed to notice is that the sole comment is utterly pointless, since all it does is to restate the code itself. It's this pointlessness that should be, and is being, mocked.
The imagined function name was Alex taking the self-documenting code idea and guessing what this programmer's response would have been. Since for this programmer commenting means replaying the code, surely the function name should do too.
Admin
That´s true, but in fact I think it was a problem with my english, I was talking about programmers & programming languajes and I used "easy to read" as a "synonym" of "readable".
Replase "easy to read" with "easy to read by any programmer" or "readable by any programmer".
Admin
I think it's considered bad practice because so many code grinders don't understand it, which means they can't hire a local high school student part time to maintain your code after they lay you off. I've never been asked not to use it, but I have had a coworker ask me "WTF is that thing?"
Admin
"replase".replace("s","c"); :D
Admin
Why not just hand them a copy of "C for Dummies"? (Or whatever C-like language you are using.)
Admin
<FONT face="Courier New" size=2>why don't you punch them in the face and make them look pretty, tough guy?</FONT>
Admin
I use it as well, and here goes the board screwing up HTML again ...
Admin
And instead of
if (newCapacity > oldCapacity) {
buffer = realloc(buffer, newCapacity);
if (buffer == NULL)
{
fprintf(stderr, "Out of memory.\n");
exit(1);
}
}
write:
newCapacity > oldCapacity && ((buffer = realloc(buffer, newCapacity)) || (fprintf(stderr, "Out of memory.\n"), exit(1), 0));
Isn't that so much more readable?
Admin
Code isn't localized, it's internationalized.
</supersmartassmode>
Admin
If you switch on boolean values, then you've been reading TheDailyWTF for way too long.
Admin
How do you distinguish the Lisp part from the random crap?
Admin
Why don't you go and stick your head into a cow, as you promised, farmer boy?
Admin
In COBOL,
<font style="font-family: courier new;" size="2"> evaluate true</font>
will allow you to follow with cases on arbitrary expressions. See <http://www.fluffycat.com/cobol/cobol-eval.html> for an example.
Sincerely,
Gene Wirchenko
Admin
<FONT face="Courier New" size=2>listen up punk there's something to ponder / you talk smack but you're just a flounder / working tex-mex pecs on your bowflex? / baby please sit down and get back to your everquest</FONT>
<FONT face="Courier New" size=2>bustin' out chops like walker, texas ranger / ooh, look at you, you're mr. kung foo danger / like han solo look-alike at last year's dragon*con / plastic guns and a flash drive with lolikon</FONT>
<FONT face="Courier New" size=2>punch 'em in the face if they don't close their brace / crack 'em in the skull if they don't check for null / that's why the boys come running for some love / just another big bear looking for a little cub</FONT>
Admin
It's this sort of thinking that led people to believe the Obfuscated C Contest produced shining examples of good code. People who don't understand maintainability. People who arrogantly think they're better than someone else because they can write obfuscated code. If you use shorthand operators because you can't type the full form, then you should learn how to type.
The only reason to use the ternary is if you need to focus on the (conditional) assignment, and not on the conditional (possibly including an assignment operation). If you're using it to save space, that's bad practise.
Admin
"My brother is a carpenter. He always uses simple slotted screws because someday someone might want to unscrew it and they won't know about fancy Philips-head screws."
Anyone who is stumped by x = (foo > bar) ? this : that; has no business maintaining C code.
If they're too stupid to figure it out from context alone, how the hell are they going to understand something complex like a pointer to a function?
Where do you draw the line about how dumbed-down you force your code to be?
ok
dpm
Admin
Your point of view is exceedingly small. I use the conditional operator frequently. One reason is to avoid repetition of the LHS,
not only to save space but to save the person looking at the code from having to compare two variable names to make sure that the same target is specified both times.
Here is one piece of actual code. You tell me which is easier to read:
if (bExtended)
{
pvScsiInfo->sWork.sPassthru.get_extended = 1;
pvScsiInfo->sWork.sPassthru.code_page_num = nWhichPage;
}
else
{
pvScsiInfo->sWork.sPassthru.get_extended = 0;
pvScsiInfo->sWork.sPassthru.code_page_num = 0;
}
or
pvScsiInfo->sWork.sPassthru.get_extended = (bExtended) ? 1 : 0;
pvScsiInfo->sWork.sPassthru.code_page_num = (bExtended) ? nWhichPage : 0;
ok
dpm
Admin
And in both of your rebuttal postings, you used a conditional assignment to prove (???) that "the only reason to use the ternary is if you need to focus on the (conditional) assignment" is too narrow in focus. Huh?
Admin
If you think that a condition is a (two-valued) boolean, than you haven't been reading TheDailyWTF enough. :)
Admin
Instead of rebutting, you accidentally agreed, by posting two valid uses of the ternary.
Admin
I concur.
But a lot of people really hate being told that they're agreeing with something. Especially if their point was to be disagreeable.
And still people (apparently) think that all of the code linked from the following page demonstrates "C" code that any programmer worth a dime should be able to maintain:
http://remus.rutgers.edu/~rhoads/Obfuscated_C/obfuscate.html
(Hope I typed that all correctly.) After all, if "I" can read the ternary operator without blinking, then it must be great code!
I laugh. I cry. It becomes a part of me.
Admin
Which when does practically the same thing as GCC's ternary operator always did when the second operand was omitted, but surely soon everyone will think Microsoft invented this.
Admin
Remove the first "when" and recompile.
Admin
1. No one thinks obfuscated C produces shining examples of good code. You are fighting straw men.
2. If you cannot easily read horribly nested expressions, whether they involve ternary operators or not, you are excused.
3. If, on the other hand, you don't know what the ternary operator does at all, you are a dummy, and should either learn about it or switch programming languages. Or your profession.
Is that so hard to understand - even to a dummy?
Admin
I don't mind the ternary operator that much. OTOH, it's misused a lot and can make a simple assignment look a bit more complicated, if used incorrectly, so I can understand why some people discourage it.
Admin
For the first line how about:
pvScsiInfo->sWork.sPassthru.get_extended = !!(bExtended);
Depends if this is part of working set of C idioms though. Some people would be horrified. !! seems very natural to me though as a boolean cast.
Steve
Admin
I think this is typical of VB coders. They must teach them to write TODO comments first over at New Horizons, then never told them it was okay to take them out when you've done it.
I once worked with a guy famous for 20 line design-by-contract style header comments for one line private methods.
Coincidentally, when he did really wonky things (like iterate over massive arraylists looking for a specific string rather than use a goddamn hashmap in the first place or loading the same record three or four times in a row), he didn't document them all.
But the best of all is when he'd copy & paste 3/4 of an object's code, without changing a LETTER of his "documentation." Now, this is something I was guilty of too (we did a lot of attribute-based O/R mappings and it was just easier to C&P then remember the somewhat esoteric syntax), but I at least tried to encapsulate the similarities.
Admin
You could define a macro:
#define BOOLIFY(x) (!!(x))
It's an open question whether that would help some people, though. :)
Admin
I Funny you should mention the ternary operator. I posted an entire blog entry about it not too long ago: http://emooers.blogspot.com/2005/10/c-ternary-operator.html
Some people abuse and misuse it, but I've found a couple of very appropriate applications for it.
Admin
<FONT face="Courier New" size=2>hold on a minute. you just said you posted to your blog about the ternary operator. </FONT>
<FONT face="Courier New" size=2>i just want you to know that you just won the international mccorkle award that i just made up. it's awarded to those that demonstrated a superior ability to overcome the outer thresholds of geekdom and rise to take your place as not only a total loser, but a total loser of the world.</FONT>
Admin
The greatest thing here is that the behavior in this condition varies with compiler! Using GCC you get a different result than MS's VC6 compiler.
Very nice.