- 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
took me some minutes, not the worst code I've seen. And the default age of 25 is reasonable assumption ;)
Admin
If (gender == female) return 25;
Admin
so glad to see he used string parsing on nBirth instead of nasty arithmetic operators / and %
Admin
Those of us old enough know that a better default is 29, and that furthermore anybody older than 29 should be shown as being 29.
Admin
Obligatory xkcd ref : https://xkcd.com/221/
Admin
String structs are the way forward. Just serialise everything each function call to one param. It's awesomeness. Never had to write a function with more than one param since makes things so much simpler and is uniform with return. One in one out, one in one out, one in none out. Could not be simpler.
Admin
So I think this actually works correctly, it's just insane. My guess is at some point the birth date got "optimized" into an int and he didn't bother to rewrite all the old code for it. Or maybe I'm going too far down the rabbit hole here...
Admin
Frankly, I think you're so far down the rabbit hole, you're fifty miles up in the air on the other side of the planet.
Admin
Works correctly? Maybe - as long as the person isn't more than 99 years old. It's plainly broken in that case. But then again, that may be a limitation in the data source since the incoming integer looks to be representing MMDDYY digits.
Addendum 2016-08-31 09:17: Edit: DDMMYY digits.
Admin
i write such code every time
Admin
MMDDYY or DDMMYY, it's the wrong way to position-encode dates in integers. Where I've seen position-encoded integer dates, it has always been YYYYMMDD, or converted in to a proper serial number. YYYYMMDD and serial numbers both allow you to sort unambiguously by date using the integer representation directly.
But a proper date type is better, obviously.
Admin
So that's how they got to Australia.
[joke intended for a European audience. Other locales' results may vary]
Admin
Why 25 ? Always return 42 !
Admin
Second obligatory XKCD: https://xkcd.com/1179/
Admin
struct-based currying! I like the way you think!
Admin
I love this routine. According to it, I'm 25!
Admin
"Those of us old enough know that a better default is 29, and that furthermore anybody older than 29 should be shown as being 29."
An off-by-10 error!
Here's the correct answer: https://www.youtube.com/watch?v=3wNK1Jt4JLg
Admin
Interesting. Regarding the default age, according to this, https://en.wikipedia.org/wiki/List_of_countries_by_median_age , he was either expecting the users to be from Guyana, or Nauru / United Arab Emirates women. Otherwise he would surely introduce floating point age.
Admin
Darn it. I only learned today, when I fed Google Translator with this article and read its [s]shit[/s]output, that "environment-aware" refers to ecology, and not some shell environment variable set.
Admin
Not Surprised.
I know you're poking fun, but of course it shows the folly of context-free statistical machine translation.
Admin
True "environment aware" programmers use and reuse only global variables.
Admin
I once found
if ( x --> y) { ...
in C++ code. Took me a minute to figure out what that was doing...
Admin
I really like your user name :)
Admin
And how long did it take you do find out why x was 1 less in the following code?
Admin
No arguments from me. Yet, if that's what the data source is feeding you, and you don't control the source, then I guess you're kind of stuck.
Admin
Another classic would be
x+++y
- without looking up the rules, how does the C/C++ parser read that? (Yes, I know the answer...)And I've seen
x == y ? a = 7 : 0;
(paraphrased, but it was "condition question-mark assignment colon zero") in the "if" branch of an if-else. Lazy fucker.Admin
YOU GUYS, the return 25 is not a default age, but rather an error code that is returned if the passed birthday is incorrect. The function assumes (correctly, no doubt) that the birthday is being read from a floppy disk, and therefore if the birthday is not able to be parsed then it's because the floppy disk is corrupted. So the function returns ERROR_SEEK.
Admin
It doesn't. That would be like Toyota naming their premium brand Parsus instead of Lexus. Who would want to drive a Parsus, always following behind a Lexus and forced to eat entrails handed down from those who went before?
Reminds me of dmr's inane Usenet posting where he asserted that whitespace is your friend. I retorted that if C programmers liked whitespace, he wouldn't have had to change the =- operator to -=
Anyway, the lexer is frist.
Admin
The real WTF here is that syntax highlighting used on DailyWTF apparently treats everything after a semicolon as a comment, even with C(++).
(Yes, one shouldn't include multiple statements in a single line. But isn't this the site for "just because you can, doesn't mean you shou... no wait, do just that!" type of code.)