- 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
WOW. That's not "reinventing the wheel". That is Reinventing Fire!!!
Admin
TRWTF is the endianess... LSB should be on [0] in my opinion...
Admin
yeah - every coder should know that there is an OR statement for things like this...:
</sarcasm>Admin
really people... make it a function and stop copying code everywhere!
Admin
Cue large number of horrendously bad attempts at writing this in [one line/a language of choice/a highly obfuscated manner] that should make any competent programmer weep for the future of humanity...
Admin
What... uh... oh god... strange noise
I don't see the WTF here.
I only see a vast green pasture with some happy animals on it. It seems very peaceful and looking at it comforts me and restores my inner balance.
Admin
He used integers. I suppose it could be worse; he might have used booleans, and we all know how much trouble people like this have with the complexity of booleans!
Admin
Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.
Admin
Make sure to subtly change the function in places and have code dependencies on it working slightly differently.
Admin
for $R (0 .. 7) { $Rules[$R] = ( inputInt == int(inputInt/2)*2 ? 0 : ( inputInt == int(inputInt/4)*4 ? 0 : (
Oh, hell. I give up. If it works, don't fix it.
Admin
You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
Admin
Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea
Admin
Here's an implementation in Javascript:
Admin
I would have said ArrayIndexOutOfBoundsException, but the "var rules = [];" suggests that this is Javascript.
Admin
Like this?
rules = [int(x) for x in "{:08b}".format(inputInt)]
Admin
Nice.. but extending builtin "Types" brings more problems than it solves.
Admin
Don't mind if I use this extensively with other quotes.
Admin
What they forgot to do was put in a charge of $50 for every new bug introduced!
Admin
So how did they deal with porting this code to a 16-bit machine?
The pending 64-bit upgrade must be truly impressive ...
Admin
Admin
In fact you'll have 99 problems, but the bits aint one
Admin
Ouch. Why does this suddenly give me a headache? I mean, it's just regular WTF quality code, nothing to see here really... Strange.
As a mental exercise, think, when did things go wrong in the creation of this code? What was the exact event, where reality and sanity parted ways in this case?
Admin
...when the author of this WTF was hired?
Admin
This is crying out for an enterprise-y database solution. That way it can be easily extended to 64 bits!
Admin
Now back that function up with 256 individual JSunit test cases and you're golden. Oh, but wait, it isn't a function. Guess you'll have copy-paste the tests too for each place in which this code is used. On the plus side, your code coverage will look amazing.
Each if-block is about 294 bytes. 256 blocks makes 75KB uncompressed. I'm sure the users of that website will appreciate how fast it loads!
Admin
I'm a C# guy...why couldn't they do something along the lines of...
It's not that tough of a concept, though I haven't used flags in months and have probably botched the above code big time. :(
Admin
What's beautiful about this code is how well it scales. Imagine how easy it would be to extend it to 16 or 32 bits!
Admin
Ain't nobody got time for that.
Where's the easy reader version? :P
Admin
Those jobs are hard to come by and their availability is a closely guarded secret by those who are making a fortune from them
Admin
A major factor in the rift between IBM and Microsoft over OS/2 was that IBM was pressuring Microsoft to write more lines of code. Bill Gates likened it to paying for a new aircraft design by the pound. Of course, that's still not any individual being paid by the line, but I assume that IBM's coders on OS/2 were being incentivized in some way to write more lines.
Admin
This should be a featured comment!
Admin
as far as code goes, I like the simple but readable version. var rules[]; for( int i = 0; i<8; i++){ rules[i]=inputInt%(2^i); }
Admin
Actually...
You could extend to 64 bits by pushing 8 rules[] into a rulesSixtyFour[]. Not sure how to populate it, though. Maybe do modulo 2^32, 2^31, 2^30, ..., 2^25 on the input to figure which of the eight rules[] arrays to operate on. Within each array you might do modulo eight more times to figure which bit to set.
It's still horrible but at least it's actually fewer operations than the original code. For nostalgia and backwards compatibility I guess you could leave the original for setting the last 8 bits.
Don't get uppity if I'm totally wrong, this morning's cappuccino is only half gone...
Admin
And now our faculty rules:
---snip--- Rule six: There is NO rule six. rule seven: No Poeftas
Admin
Admin
Assuming that the endianess is required, I would do something like this:
Admin
In a recent project I worked on, we weren't being paid for lines of code but management was very, very interested in keeping metrics on them. We would frequently have to submit statistics (or they would be calculated from tools we used). How many lines of code did you produce this week? How long did it take your peers to code review? Therefore, how many LOC/minute do they review? How many bugs came out of this section of code? How many LOC/bug? How many LOC in your module? Compared to every other module? etc, etc, etc. It was kind of nuts, but at least it didn't really get in the way of the job itself.
They were trying to quantify things like, given an average of X lines impacted per bug, and it takes Y hours to fix, therefore how many bugs can a developer fix per day, therefore we can schedule in Z bug fixes per week...
Admin
Well, that's impressive 2304 lines of code. One cent per line makes it $23.04. If he takes longer than half an hour he wasted his and his employers money.
Admin
Admin
Hmm
Nah it should XML encoded strings of floats to be really sure he captured EVERY possibility including sign, infinity and of course NaN
Admin
But just wait until you see the code to translate the rules back into a value, I have. Its munitions grade bad code and hence health & safety forbids posting it.
Admin
...straight out of school.
Perhaps next time they should wait until after graduation.
Admin
Admin
hum higher order bit is with index 7! Wait other way! it's zero.
Admin
Duh, he should have used a switch statement.
Admin
rules←inputInt⊤⍨8/2 rules←2|⌽⌊{⍵÷2}\8/inputInt
The later one is my favourite so far.
Admin
The interesting thing about the code sample is that any reasonably competent compiler will take at least the assignment code and optimize it. An even better compiler will recognize the whole thing is -static code- and produce a very tight representation.
Those of you who propose generating this with some functions should recognize that, depending on the expression, the programming language and the quality of the compiler, you'll end up running that code when you didn't have to.
Admin
Admin
I don't get that... Shouldn't it be
"You have two problems. You think "I know, I'll use bits." Now you have 10 problems."
Admin
That... or just: