- 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
An Hour. An Heir. ... but not an hexadecimal.
Admin
Oh come on, you are making this up, right?
Admin
I strongly suspect someone just wrote up a perl script to spit out that code. I refuse to believe that, while typing, he couldn't think of a better way to just write out all the damn code. This thesis is not mutually exclusive with paid by the line-ism...
Admin
Yeah, most of the stuff I was basing it on was older english works, but not too terribly old. And I would definitely call Agatha Christie a literate Brit. [;)]
Admin
Congratulations - that's the first time I've ever laughed while reading the Daily WTF
Admin
C'mon you guys. I got one word for you: Thorough. That or "Autism".
You'd have to be one determined mutha *shut-yo-mouth* to program this.
Admin
I hate when people can't remember this rule from 2nd grade English class. The word "historical" is the one I most often hear abused like this- a lot of times on TV you'll hear people say "it was an historical event." And it'd be less annoying if they mispronounced "historical" such that the "h" was silent. But they'll pronounce the "h".
People do this with words starting with "u" too. It's <i>an</i> umbrella, but <i>a</i> unicorn. A long "u" starts with the "y" sound.
But I digress, this isn't a grammar website.
Admin
Don't forget the C++ / STL version:
template< typename T >
std::string ToString( const T& value, std::ios_base& (*base)(std::ios_base&) = std::hex )
{
std::ostringstream outs;
outs << base << value;
return outs.str();
}
Works on any type that has the ostream << operator defined and any radix you want!
Admin
Couldn't be. You wouldn't write comments into the script, would you?
Admin
Wow, It'd be bad if he just didn't realize the language provided functionality for the conversion, but it just shows plain stupidity that once he decided to write a conversion function himself he ended up with that.
I'd assume pretty much every programmer knows the following table by heart:
Us developers use hexadecimal becuase its so damn easy to convert to and from binary. Every one of the 16 characters matches one of the 16 possible combinations of 4 bytes.
So worst case scenario, he needed a for loop with a 16 entry select statement...........
Of course it would have shown some real insight to check the documentation and find the dozen (atleast) various formatting and conversion functions that would do this in a single line.........
Admin
There are <FONT size=6>10</FONT> types of people:
Those who understand binary
Those who don't
Admin
Simpler than a lookup table:
if( digit <= 10)
c = '0' + digit;
else
c = 'A' + digit;
That's how I do it.
/Well, when I need to do it by hand for reasons that I can't seem to remember
//Didn't have to do it for a long time though
Admin
By 'A' + digit, I of course meant 'A' - 10 + digit.
/The forum ate the - 10
//No, really
Admin
i've done this sorta thing for the sake of "it could be fun".... to be deleted almost immediatly...
now to use this, that's a whole different story
Admin
Oh, good. For a second there, I thought I was going to be the only person who noticed someone declaring Pi as an integer.
Newsflash! Value of Pi found to be exactly 3! "We're Baffled," say scientists.
Admin
That is, by far, the strangest definition of 'fun' I have ever heard. (Well, except this one time when I saw a show on the Discovery Channel about people that would put hooks in their body and hang from the ceiling. That was a little stranger.)
Admin
That's what it is in Indiana, right?
Admin
So you're saying this is dysfunctional programming.
Hmm..., I have to remember to use that sometime.
--RA
Admin
Dork. The comment should be:
/**
* The number of hexadecimal characters per byte equals 2;
*/
--Rank
Admin
Yeeeeeeeeeeey! You made my day!
How do you do that, store 3.14 in an integer? Redefined what an int is, and used some weird constructors???
Admin
All right, my first guess (to be charitable) is that you're simply ignorant. My second guess is that you're both being ignorant while picking on a subset of the population you believe won't/can't fight back.
1. Autism!=stupidity
2. More than likely, the attention to detail would express itself in coming up with the most efficient method of solving a problem, though it might possibly blow deadlines out of the water (not that there's anything remotely exclusive when it comes to blowing deadlines out of the water)
3. Because of that attention to detail, you'd most likely have software that's in perpetual development that the developer in question never feels is release quality, even if the quality is such that the current quality is better than everything else currently available.
Admin
We're also getting close to Alex's 400th (and, before that, 1000th, if you prefer that) posting. Hope he's got something wonderful in mind 8-|
Admin
This code is just painful to read. I mean, you couldn't even copy and paste something this bad...
Imagine this guy writing an octal converter
Imagine this guy writing a base64 encoder [+o(]
Admin
The character values don't matter... just do:
const char hexchars[] = "012345678ABCDEF";
Admin
OMFG! This is a classic example of a stupid and stubborn person programming the same way he would break a wall with bare hands - brute force and persistence... I admit that I may be somewhat lazy but that's why I (and actually most of the people I know) after working for a while actually stop and think whether this isn't too hard and if there's another easier way or even something already done by someone else and published on the forums or some site... oh boy, that's what google is for!
Admin
Er, "0123456789ABCDEF".
Admin
Admin
<font size="5">W</font>ow! I'm sure that David H's former colleague missed the class teaching arrays and never bothered to pick it up before he graduated.
Admin
I'm just assuming you mean "Every one of the 16 characters matches one of the 16 possible combinations of 4 bits."
Admin
And neither is that grammar nor correct. It's phonemics, not grammar. An historical is correct English--British or American.
The rule is say 'an' rather than 'a' if the consonat is not aspirated. Therefore "an historical" but "a historian."
Admin
Is that like, "truthiness" ?
Admin
Clearly, he didn't spell out the rest of the code, because that's the obvious bit...
Admin
Looking at this travesty I'm starting to womder if people aren't doing stuff like this just to get posted on this site. A sort of "Badge of Infamy"? Hey look, I got my code shown on the Daily WTF !!!! HOORAY !!!! :|
All I can say is that if this is real it's a shining example of why code reviews are required.
unlisted_error
Admin
Well, that depends... am I getting paid by the line?
Admin
Years ago when I was starting out with PHP my manager needed an online survey app. Nothing too complicated. The managers build the surveys with a number of optional controls. I needed to do some math at runtime that will differ for each survey.
So I wrote a class that evaluated simple mathamatical formulas following the order of operations.
I was pretty proud of myself, actually. It wasn't incredibly easy for a new developer. I posted it to a discussion forum.
Someone said "why didn't you just use eval()?"
so i renamed it stupid_waste_of_time.class.php
Admin
I have taken to asking prospective coders (for a design verification job, so its fairly low level hardware stuff) to convert hex 19 to decimal for me. Its amazing how many people can't, or take an inordinate amount of time to do so. It tends to be very predictive on how well they will do overall.
Admin
And the forums also added the '=' in "if(digit <= 10)", right? :p
Admin
...he didn't write a unit test.
Admin
Why not?
The script would generate comments if that was part of its requirements.
Admin
Admin
char inttohex(int i) {
return '0' + i + ('A' - '9') * (i > 9);
}
int hextoint(char c) {
return c - '0' - ('A' - '9') * (c > '9');
}
Good thing I don't work with numbers higher than 15.
Admin
I'm not buying that, whoever wrote that code was joking.
Admin
char toHex(int val) { return (val&0xF)["0123456789ABCDEF"]; }
;-)
Admin
Uhm..
LOC..
Ponder
LOCo? ;)
Admin
Actually they did on this machine, since I was, ahem, well, I just let this one speak for itself:
char *screen = (char *) 0x0401;
(*(screen+4)) = hex_hi (ch[0].click);
(*(screen+5)) = hex_low(ch[0].click);
... and in this architecture's case, you don't put character values to screen memory, you have to use character screen codes, which the compiler doesn't produce (or maybe it does, I didn't read all docs at that time).
Can we guess the architecture already? Hint, few people coded in C for it =)
Admin
I love the constant "number of hexadecimal characters per byte".
I heard that the folks at the ISO are planning to redefine the byte to use 16 bits instead of 8. Man, is it ever going to be hell for the programmers - but not for this guy! He's prepared - he just needs to change the constant and it will be all right!
Admin
It was correct before a stressed H until around the start of the 17th century. It was revived as an affectation only at the end of the 19th century. It is certainly neither correct nor in common usage today.
Admin
PI is equal to 3, or so does the Holy Bible quote.
The Bible being the word of god and the symbol of everything that's Holy and True, PI is therefore definitely equal to 3
Admin
Pirate jokes arrh always funny.
Admin
This one is clearly made up. Total fake. Complete and total BS.