| « Prev | Page 1 | Page 2 | Page 3 | Next » |
|
I'm always amazed at the number of people who don't understand bitwise operators in C. Any type of embedded GPIO practically requires them.
|
|
Wow...just wow...
|
|
I bet he had nightmares about having to add another 'bit'.
|
|
If the code REALLY looks like that, there's another WTF hidden: It literally is 1111111 (decimal), not binary 1111111 aka 127.
|
Your powers of observation are incredible. |
|
That first one is actually octal, right? It is in C/C++, anyway.
|
That is actually a feature. It allows you to REALLY make sure you are searching for an lastnameby passing in a 9000000 |
If only it were that simple. All the numbers with a leading one are actually in decimal--but leading zeros? That's octal, baby! |
|
This is the first code in a month or two that's made me actually want to gouge my eyes out in disbelief.
The fact that he attempted to use a bitmask but had to make a constant variable for each possible combination of bits that he would use, OUGHT to tell him something.... |
|
He he, Speak of the devil! I'm making use of a bit array myself for something im working on right now.
Though i'm opting to use the bitwise operators for accessing it, and i think i'm going to the skip storing every possible combination as a constant (who's decimal represetation resembles the binary representation of arra). Great that he actually has booleans for everything allready ... but insists on setting the contants anyway. |
|
There's nothing essentially wrong with doing it like this, in fact in some situations it is to be prefered.
You get finer grained control over the business logic if you can handle specific combinations seperately. You can, for example, scroll down to the elseif block that handles the DOB-email-name combination and make it a Special Case with special behavior. It makes it a lot easier to refactor. That's not so easy if you just obfuscate it all as a load of bits and masks which by definition have no meta-data attached. |
|
Because of the mix between octal and decimal, I'm guessing that's why he did this. Something wasn't working by using bitwise operators correctly (because his numbers were wrong), so he came up with this cockamamy scheme to get it to work.
|
|
Wait a second -- why is the result variable of all those if's called matchPattern? It couldn't be that they perform a regexp comparison somewhere down the road, could it? If this is so, the WTF should be titled "Boolean Integer Strings".
|
Re: Boolean Integers
2008-03-07 08:39
•
by
this webcomic is a wtf
(unregistered)
|
This is actually very nice, we can then change the value to a string, then test for the condition with a simple mid(str(integerflagholder),positiontotest,1). You can't do neat stuff like that with some crazy ass binary bit flipper. |
|
After defining 20 of these "bit patterns" he probably thought "Screw this", and left out the other 107.
|
Re: Boolean Integers
2008-03-07 08:42
•
by
earl
(unregistered)
|
|
Well, at least that explains why the programmer could not use bitwise operators:
MATCH_LNAME_DOB | MATCH_EMAIL_ONLY != MATCH_LNAME_DOB_EMAIL 0x10C8E0|0x3E8 != 0x10CCC8 0x10CBE8 != 0x10CCC8 1100000|0001000 = 1100776 So it makes perfect sense why the binary operators where not used: they just would not work. (and by the looks of it, that is Java) |
|
TORWTF is that crazy code indentation....
|
|
There are exactly 10 types of people in the world: those who understand binary and those who don't :)
|
Re: Boolean Integers
2008-03-07 08:47
•
by
BrianJ
(unregistered)
|
This looks like C#. C# does not have octal literals. So all these numbers are decimals. |
Re: Boolean Integers
2008-03-07 08:49
•
by
Harry
(unregistered)
|
There are exactly three types of people in the world. Those that understand true and false and those that don't. |
Re: Boolean Integers
2008-03-07 08:49
•
by
sweavo
(unregistered)
|
And those who know about ternary |
Re: Boolean Integers
2008-03-07 08:50
•
by
yer mom
(unregistered)
|
|
There's no final in C Pou... Sharp
|
|
In this case using XML would really be a better solution... (No matter what way!)
|
|
Let me count the ways that code is bad. Oh wait, I only have an integer to store the total and I see eight things. Shit.
|
Re: Boolean Integers
2008-03-07 08:57
•
by
tgies
(unregistered)
|
look how dumb you are |
|
Actually, this implementation looks "Pretty Simple".
|
|
Looks like Java to me.
Which is your favorite Bit? |
Re: Boolean Integers
2008-03-07 09:04
•
by
keanpedersen
(unregistered)
|
|
The code is in Java, which does have octal literals.
|
Re: Boolean Integers
2008-03-07 09:05
•
by
Anon E. Muss
(unregistered)
|
|
I've always preferred to call it D Flat.
|
|
This is clearly a case of Cargo Cult design. He saw the bitfield method used somewhere, heard it was the right thing to do, and tried to implement it. Without the appropriate background in boolean mathematics or software theory. And then made a complete botch of it.
Since C doesn't usually (outside of certain embedded compilers) support raw binary numbers, most people use octal or hex for constants. Then you get a nice string of 0x0001, 0x0002, 0x0004, 0x0008, 0x0010 etc. |
|
TRWTF is that the equals signs are not lined up in the constant definitions.
|
|
Sweet Lord.
It doesn't matter what language it is. Given that you need to track that much information, the combinations give 2^7=128 possible combinations. Setting a constant for each possible combination is just silly. Structure the code s.t. you deal with the fields as little as possible.
Setting a bunch of constants that you have to remember later is a foolish waste of resources. (The programmmer's time, mostly) Later on, you'll have to have something like
How is that better than the setting of flags in the first place? Finally, what if I have email & address, but not the last name? Shiat. |
Re: Boolean Integers
2008-03-07 09:21
•
by
Anonymous Coward
(unregistered)
|
It's Java. C# has no final keyword. |
you should all video in your bitwise operations |
There are 2 types of commenters, those that are able to create original humor and those that can only parrot things that were funny five years ago. |
Re: Boolean Integers
2008-03-07 09:41
•
by
Alan
(unregistered)
|
There is so much wrong with that, i don't know where to start. There is absolutely no reason to define all those extra matches, only 7 are required. What should be used here is a bitfield, no question about it, but not in the way he implemented it. Let me psuedo code a much better one in C#: public enum MatchPattern { None = 0; FirstName = 1 << 0; LastName = 1 << 1 Email = 1 << 2; ... ... } public MatchPattern Match () { MatchPattern p = MatchPattern.None; if (hasLastName) p = p | MatchPattern.LastName; if (hasFirstName) p = p | MatchPattern.FirstName; if (hasEmail) p = p | MatchPattern.Email; return p; } |
Re: Boolean Integers
2008-03-07 09:49
•
by
Schnolle
(unregistered)
|
|
Oh, sure. All you have to do is to find the special case among the 128 different cases in this motherhuge if statement reaching over about three dozen pages, which is MUCH easier than just have a separate statement covering all the actual special cases after the assignment or whatever...
|
|
Aside from the fact that he's using decimal numbers instead of bitstrings, isn't THIS TRWTF:
" You have only a single integer to represent them. " Is he writing for the VIC-20 or something? |
Re: Boolean Integers
2008-03-07 09:59
•
by
mack
(unregistered)
|
|
anyone who doesn't think that this code is a piece of crap should be slapped across the face with a keyboard. I suppose the author of this code, as well as this comment, have never heard of something called an enumeration.
If you are setting your program up to have multiple special cases then you are setting your program up wrong. |
And those who have social anxiety disorder. So really there are 4 (decimal) or 100 (binary) kinds of people in the world. |
|
In 30 years of programming, I can honestly say I've never seen anyone use mixed decimal bitflags (octal yes, hex yes but never decimal).
Maybe this guy just didn't understand the difference? |
|
This is the worst kind of code. Using a bitmask isn't super-advanced, but it does take a certain degree of cleverness to apply it appropriately. So when I see code like that, I usually think that the programmer knew what he/she was doing and I spend time reverse engineering and trying to rationalize it when I should just throw it out the window.
Horrible code masquerading as clever code is your enemy. |
|
the real wtf is that the featured comments are even bigger wtfs than the article.
|
Re: Boolean Integers
2008-03-07 10:27
•
by
Kyle
(unregistered)
|
No you can't, because (((1 << positiontotest) & integerflagholder) != 0) is too long. |
Re: Boolean Integers
2008-03-07 10:27
•
by
diebitfieldsdie
(unregistered)
|
I question that. Unless you are working with limited hardware or bandwidth, there is *no* reason to try to cram 8 boolean conditions into a single byte. It will only lead to obfuscation and wtfery. There are several alternative solutions involving data structures all the way from enums to classes, all of which involve no more overhead than the original wtf here, and all of which are far more maintainable and less bug-prone. I would likely just set independent bools and check them in the if statements directly, which has the benefits of adding metadata (variable names) to the conditions, requires coding only the number of cases you actually need, and the logic being immediately readable by the poor sod who has to debug it later. |
Re: Boolean Integers
2008-03-07 10:29
•
by
Kyle
(unregistered)
|
Why yes in fact, it is. if (specialcase) { } else { //use bitmaps here. } |
Fail. |
|
Well if they are going to be highlighting the troll posts, I think its time to quit reading this site.
|
| « Prev | Page 1 | Page 2 | Page 3 | Next » |