| « Prev | Page 1 | Page 2 | Page 3 | Next » |
Re: The Bit Setter
2012-05-07 12:54
•
by
Overthinker
(unregistered)
|
There. Fixed. :) Captcha: secundum - frist, secundum, ... |
Re: The Bit Setter
2012-05-07 12:54
•
by
gnomie
(unregistered)
|
No... not really... never was... |
Re: The Bit Setter
2012-05-07 12:56
•
by
Fonseca
(unregistered)
|
(I'm referring to Dargor17's post, of course) |
|
TRWTF is that months ago I wrote a C# class to manipulate a bitmask's state as booleans indexed by Enum. :-o
enum Foo { None = 0x0, Bar = 0x1, Baz = 0x2, BarBaz = 0x3, Bak = 0x4 }
I don't remember which project it was for, or if any version ever went into production though... I just now went searching for the code, barely found it hidden away in an archive, and fixed a silly bug in it that I think had me stumped when I first wrote it. xD grep doesn't find it anywhere in my ~/src tree so I guess that's a good sign.
Though the code could arguably be useful (particularly for colleagues that have trouble with bitwise logic), I'm not sure that the overhead of a heap-allocated object to manage a bitmask doesn't outweigh the advantages of using a bitmask... I don't remember why I originally wrote this either, but I suspect that it's because C# doesn't allow bitwise operations on enum types directly, and all of the conversions to an integer type and back to an Enum made the code ugly and error prone... |
|
This function does work exactly as advertised. Maybe if the author had called the second argument $mask instead of $bit, you would not be so confused.
I'm not saying it's not a silly function, I'm just saying there are no bugs. |
I've seen exactly this. Its terrible. Checkboxes on a web form that get "converted" to individual bits packed into an integer and sent to the database. As soon as you added a new checkbox into the form you had problems in the backend... |
A TRUE catch-all is great because it will catch "possibly", "you betcha" and "as foretold by the prophecy"; however what about "unlikely" or "you wish"? Also what about the situations where the context (or non-verbal) is needed to make a good call on the meaning, like "maybe" or "sure"? |
bit-wise operation is mostly requested in all program languages. once requested, you must code for it. |
with more business like leaning in IT department, less it and more process take place. so bit manipulate is only something that was in 1st year of comp sci. now we pass taht paper, who care about little bits? |
|
"I'm puzzled at how he explains that if $val is 12(10010) and $bit is 5(101) he would get 13(10011): I would have expected 17(10111), assuming that $bit is a mask as is implied by the other comment..." Um... because 12 is 1100 and 5 is 101, so the result is 1101? 10010 is 16+2, or 18 (decimal). Now, given that you did the final OR computation and got 10111 (wrong, but work with it), 10111 is 16+4+2+1 or 23 (not 17). But we did need a Real WTF out of this story (the function is horribly misguided, but not really WTF worthy). |
Tried the "SET" datatype someday ... I cried. How do you handle 20 boolean flags in a table ? (I was using libmysql & c++) |
As far as you know? I can't really say I find that reassuring. What I *do* find reassuring is a compiler or interpreter which sees my attempt to treat a string value as boolean true/false for the glaring cock-up that it is, and isn't afraid to tell me so. |
|
lol, true that... :)
|
I'm trying to work out what is so utterly heinous about something like "function setBit(int $val, int $bit, bool $switch = true)" that it's worth all that kitten-slaying boilerplate code to catch the possibility that someone will pass a string where a boolean is called for? Also, what about 'False', 'FALSE', 'fAlSe'...? |
|
"smarter-than-built-in-language-features collegue" ...
i am quite sure that php built-ins looked that way, actually. looks like a promising php6 feature. but by then they probably improved the function. real_setBit($needle, $haystack) ... |
|
Oh. My AND was wrong. Sorry about that. :|
I am TRWTF. :( Captcha: Ullamcorper Don't even ask me what that's supposed to be... |
Take the code from a chatbot (cleverbot, ELIZA, whatever) and use it to parse all arguments to functions from now on. I'm sure you could create an interesting programming language based on that. |
I think I have to use "as foretold by the prophecy" instead of True in Python now. |
Re: The Bit Setter
2012-05-07 17:28
•
by
Your Name
(unregistered)
|
Yep, I used to work on a system which actually does that with security permissions from checkboxes, just like you said. Eventually some of the numbers got into the millions. Amazing how when they spent several years rewriting it from scratch, that's one area they swore they'd do away with, but nope it's still there. Captcha "vereor" - when regular "or" isn't powerful enough for your bit manipulation |
Re: The Bit Setter
2012-05-07 17:41
•
by
Rabble
(unregistered)
|
|
0x12 is hex, not dec 12. The example refers to decimal 12.
(HEX) 0x12 -> 0b00010010 (DEC) 12 -> 0b00001100 The bitmath does, indeed, work out the examples given. TRWTF is the number of folks here that don't understand bit twiddling.. |
"It is known." |
Re: The Bit Setter
2012-05-07 18:20
•
by
Davey Jones
(unregistered)
|
|
I actually consider that a very non-php idiom. It seems very C/C++ish to me. Php seems like it attempts to be a 'higher level' language, and shouldn't need to be as concerned with bitwise manipulation.
|
"Make it so." |
|
The code isn't a WTF. It works as advertised by the clumsily written comment.
If there's a WTF, then it's the apparent lack of familiarity with basic bit arithmetic on the coder's side, though he did manage to produce correctly working code in the end. |
Well, t's over-engineered, the description is confusing, and so is the name. I guess that rates a WTF. But for the rest, you're right: Functionally, it does exactly what it promises to do, if one carefully reads the description--and doesn't jump to conclusions about what "turn on the 4 bit" means. After all, 8 | 4 is 12. |
|
The real WTF is the amount of incorrect examples of binary operators in the comments.
|
Re: The Bit Setter
2012-05-07 19:34
•
by
AN AWESOME CODER
(unregistered)
|
Depends. In this case, it's one in the same. If this is some library code that I need to use for some presently-unknown reason and I expect it to work as documented, the code is buggy. |
Re: The Bit Setter
2012-05-07 19:40
•
by
AN AWESOME CODER
(unregistered)
|
This is the dumbest assumption of purpose I've ever heard in my life. We're not talking about memory management, we're talking about math. |
setBit($val, $bit, '0') will switch bits off, but setBit($val, $bit, 0) will switch them on. Nasty bug. |
No, I take that back. What the hell kind of WTF has working code?! |
|
Lesee... comment is wrong... string conversion doesn't account for "nope", "nuh-uh", "no way josé", "hell no", "FileNotFound"...
|
In my previous job I had to maintain code written by someone who did things like that. He also deliberately threw exceptions to break out of loops. |
Re: The Bit Setter
2012-05-08 01:28
•
by
Gibbon1
(unregistered)
|
I have a macro in C, BF(X,Y), returns an int with bits X through Y set. Course that's C. So a two letter macro is culturally appropriate. This is PHP, so a function that does something only somewhat related to what one would assume based on the name is also culturally appropriate. First we have setBit() which sets a bit field. Eventually we'll have Setsbit() which sets one bit, starting with bit 'zero' I think the WTF here is assuming anything about anything in PHP. PHP is a language for a certain type of customer, one that is allergic to committing to spending enough money up front, yet can be persuaded to spend double that in drips and drabs over time. |
|
I think it would be less WTF to split the functionality into two functions - setBit and clearBit to do away with the boolean parameter cruft.
|
|
"set some strings that humans would consider false...."
Sounds like it has been programmed by a robot.... |
uhm.... 12 (1100) & 5 (0101) = 13 (1101) oh, I see, you're a troll! |
Re: The Bit Setter
2012-05-08 03:04
•
by
Captcha:genitus
(unregistered)
|
TRWTF is all these funky conversions. This function accepts a boolean, accept PHP's type casting or give it a boolean |
I'm not sure if I understood correctly, but I agree with how I undertand it. Too much learning in higher level language will always ee people unknowing of the truth fundamental. |
Re: The Bit Setter
2012-05-08 03:27
•
by
werner
(unregistered)
|
Seconded. I just added
to my WTFutils.h What bothers me about this post is that bit twiddling is supposed to be a fairly low level construct, mostly used for premature optimization in C/C++ code, while Php is a high level language. The fact that someone needed such a function in Php in the first place is TRWTF. |
and a troll with 16 fingers too. |
Now there's a WTF if I've ever seen one. |
Bitmasks have been used to store a bunch of booleans in the past, it's not all that bad, even if your example shows some people can do it the fail way. |
MySQL is TRWTF |
WTF. and how, dear sir, do you plan on handling ip addresses without binary ??? CAPTCHA conventio : welcome to conventio, the convention hall planet. |
Re: The Bit Setter
2012-05-08 06:01
•
by
bitbitbit
(unregistered)
|
More likely 10 fingers and only 6 toes. |
Your database has problems with integers that don't fit in 32 bits? Your forms have more than 32 checkboxes?? |
But it would be so hard to store each checkbox separately! I actually got a similar whine from my devs recently: But that's another 20 database columns! I wanted to ask: So the vendor now charges another $10,000 license for each new column? Or what? Surely you don't have to write a gob of new code for each column, do you? Ever hear of reusable stuff? One validation module for ALL dates, maybe? |
The real wtf is you want to store a bunch of boolean values. At least the bitmask is a sensible technical solution that partially hides the spupidity that 20 boolean columns would instantly give away. While I wouldn't go as far as to defend your code monkeys, I'm pretty sure you're full of wtf and don't even realize how incredibly nice a bitmask can be. |
What about "Amen", "Insh'allah", "So mote it be" and "Das ist gut, ja?"? |
Re: The Bit Setter
2012-05-08 09:42
•
by
¯\(°_o)/¯ I DUNNO LOL
(unregistered)
|
Just a very inept yakuza. They had to cut off both his pinky fingers AND his pinky toes. |
| « Prev | Page 1 | Page 2 | Page 3 | Next » |