- 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
Just turn off JavaScript, silly :-P
Admin
it's more like value=2^(id-1) or in mysql: pow(2,id-1).
Admin
Unfortunately, the actual code was similar to savar's suggestion. Actually, though, it ran two separate queries - one to get MAX(publications) (which was then doubled in PHP) and one to insert the record into the table.
CAPTCHA: darwin - Only the strongest Comp. Sci majors survive (if only that were true)
Admin
To be honest, I think this guy only needs to brush up on some basic DB skills. The example certainly is a WTF, but I think TRWTF is that he left to study English. You'd be surprised how many graduate Computer Science students I know that don't even know what a bitwise operation is. All you need to do is say "binary" and their eyes glaze over.
Give the guy a decent internship where he has to check his designs with his supervisor first, (and hope his supervisor is competent) and you'll have a pretty above-average programmer.
Admin
Ok, with some training the guy might turn out an above-average programmer, but I doubt any coaching would make him pretty.
Admin
Why does it even need a value?
CAPTCHA: gotcha
Admin
Great, that's a race condition waiting to happen. Perhaps not so likely where your dealing with data that changes rarely, but this kind of approach is all too pervasive in web applications. It's also not helped by the MySQL guys insistence that proper referential integrity and transactions weren't necessary - well, not until they learnt how to implement them.
Admin
Why not just store each publication as a prime number and then simply take the product?
CAPTCHA- so that's how you spell 'onomatopoeia'...
Admin
I once did something very similar to this. The business application had to associate about 100 million items with about 8000 entities. An item could be associated with any combination of the 8000 entities and the entities could be associated with any combination of the 25 million items. A query on this association had to be extremely fast.
An association table was quickly ruled out. There was no way we could reasonably handle a table with billions upon billions of rows in it. The table and the index on it for a fast search would blow out the tablespace available for it.
My solution: Each "item" would have a VARCHAR FOR BIT DATA about 250 characters in length. This stood for a very, very large number (about 8000-bits in length). Each "entity" would have a number representing the bit-position in that varchar, read from the 'left'. It should be noted that the "entities" were relatively static.
So, once you have the string, finding a hit was simply a bitwise operation on the (entitynumber % 32)th bit of the ((entitynumber / 32) + 1)th character of the VARCHAR.
Admin
Admin
If you're using MySQL, you'd probably use a SET field to store multiple flags in a single field. This is probably what the coder of the original WTF should have done in the first place.
Admin
Before I saw the contents of the field I guessed it may have meant price.
CAPTCHA was onomatopoeia. Long one to type. I'm learning how to spell it and what it means - something good coming of posting here after all :-)
Admin
Too bad Alex didn't provide a better description of your post. You know, something like "Stupid idiotic FRIST post that shows everyone what a moronic ass I am". Would have fit better.
Admin
Too late for a reply? Well, agreed, rookies are evil regardless of the language. But this fact doesn't save PHP. For me, it is a messy tool because it offers a poor (and, in this case, dangerous) syntax and inconsistent libraries. Given that there are better (also free) choices for web development, PHP makes no sense.
Of course, there are legacy applications written in PHP which must be supported yadda yadda... but this fact doesn't diminish its wtf-ness. It just puts PHP in the "legacy" drawer.
Admin
"Why does it even need a value? "
TRWTF, please take a bow. The VALUE was useless to start with as it could be derived trivially from the id, and can't be effectively used as a key (any more than the id).
While use of the bitfield as an accumulator of discrete choices is clever-ish (but a poor choice for n>32 in php) storing the bitmask for each (numbered) choice is silly, and as we see, error-prone.
Captcha: craaazy (strangely apropos)
Admin
I assume you mean 2^(id-1) to "trivially" find the value from the id? I doubt that very much. It may be a coincidence that it works here but to rely on that would be a mistake.
I’d assume the region has the bitmask (we don’t know if he stores that. To do so would be indeed be silly). The “publication” which you may reasonable assume could cover more than one region would have a “value” representing the as an accumulator of discrete choices to describe the regions.
The alternative way of doing this many-to-many relation ship is to have a 3rd table describing the mapping between the publication and region tables. Which is obviously slower and requires more disk space. If you could have guaranteed there were less than 32 regions this would have been far from silly and a good solution.
Admin
Erm forget that it wouldn't be slower. It'd quicker and scalable but require more (cheap) disk space. Still I think it's not really that bad just trying to be a little too clever for no reason ... ok it's bad :)
Admin
Admin
I don't really understand this WTF. Is the coder trying to increment an id by shifting it to the left?
($story->regions & $region->value) == $region->value so this line checks if $story->regions == $region->value ??? or dose the code change Value more than shifting it to the left?
$temp_string .= $story->toString(); what has this line to do with anything?
i'm kinda confused :P
Admin
Those are Zimbabwe dollars. You can buy a coke or a half a loaf of bread.