• (cs) in reply to Sad Bug Killer
    Sad Bug Killer:
    Since well-reasoned, humorous and insightful first comment wasn't a valid option in the survey...

    Just turn off JavaScript, silly :-P

  • Power (unregistered) in reply to savar
    savar:
    I shudder to think, though, what the INSERT statement would look like when you create a new publication record. If you had subqueries available it would be something like this:

    INSERT INTO PUBLICATIONS NAME, VALUE VALUES ("Newspaper",2*(SELECT MAX VALUE FROM PUBLICATIONS));

    it's more like value=2^(id-1) or in mysql: pow(2,id-1).

  • Brian (unregistered) in reply to Power

    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)

  • (cs)

    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.

  • anonymous workaholic (unregistered) in reply to SerajewelKS

    Ok, with some training the guy might turn out an above-average programmer, but I doubt any coaching would make him pretty.

  • kevin (unregistered)

    Why does it even need a value?

    CAPTCHA: gotcha

  • (cs) in reply to Brian
    Brian:
    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)

    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.

  • Aidan (unregistered)

    Why not just store each publication as a prime number and then simply take the product?

    CAPTCHA- so that's how you spell 'onomatopoeia'...

  • M L (unregistered)

    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.

  • TIMMEH (unregistered)
    Before that day, Brian had never realized PHP had bitwise operations.
    Are you fucking kidding me? Maybe Brian's the one who ought to be an English major.
  • Mr. Bean (unregistered) in reply to Opie
    Opie:
    Irrelevant, if one uses MSSQL, which stores groups of bit (single boolean) fields together, anyway, internally. ie if you have 8 bit fields spread throughout your table, MSSQL will store them as a single byte, internally, rather than as a ton of separate bytes (just try writing less than a byte to disk - I dare you), wasting space. It seems insignificant, but it really is significant, in aggregate. If a table has, say, 12 bit fields, it would take up 2 bytes in MSSQL. In other systems, like MySQL, it would take up 12 bytes. Now fill that table to just 1 million records. That's around 2MB in MSSQL and 12MB in MySQL. I'll scan the smaller table, thank you.

    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.

  • Richard (unregistered) in reply to SomeGuy
    SomeGuy:
    I was already cringing when I saw a column called "value" on a table called "publication". When you see a name as uninformative as that, you can just assume you're in trouble, before you even look at what it contains.

    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 :-)

  • (cs) in reply to Sad Bug Killer
    Sad Bug Killer:
    Since well-reasoned, humorous and insightful first comment wasn't a valid option in the survey, I'll stick to the classic - FRIST!

    Edit: well, almost

    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.

  • (cs) in reply to JB
    JB:
    Missed the quote . . .
    H|B:
    TRWTF is PHP

    Your comment about PHP only demonstrates your own ignorance to what the language has become. The fact that there are rookie programmers in PHP is not a problem with the language—I've worked with far worse code in the other 20-someodd languages that I work with on a regular basis.

    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.

  • bithead (unregistered) in reply to kevin

    "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)

  • James (unregistered) in reply to bithead
    bithead:
    "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).

    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.

    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)

    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.

  • James (unregistered) in reply to James
    James:
    Which is obviously slower and requires more disk space.

    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 :)

  • Synonymous Awkward (unregistered) in reply to caffeinatedbacon
    caffeinatedbacon:
    Paul:
    Expat:
    ParkinT:
    This is one of those WTF's where you almost have to be clever to come up with something this stupid.
    I agree. It appears he tried a bit too hard to be elegant, simple and/or concise. I have caught myself in that trap a few times.

    Ah, but you did catch yourself, and that's the difference.

    Yeah, but what about the times he didn't and some poor guy coming along later had to maintain his code?

    When I read Expat's positive, supportive and reinforcing comment, I almost thought I was on the wrong site. Thankfully, Paul's snarky, condescending, self-aggrandizing, worthless invective reassured me that yes, I am still reading WTF.

    Good work, Paul!

    I second that. I felt a cold chill for a moment back there, as if someone had walked over my grave.

  • blubb (unregistered)

    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

  • (cs) in reply to Eryn
    Eryn:
    xtremezone:
    Jon B:
    Simple solution:

    Charge the original programmer $0.01 for the first bug fix, $0.02 for the second, $0.04 for the third...

    ;D

    well... i started about 8 months ago at this software firm, and to date i have fixed 289 bugs. it got absurd after about the 30th bug, but i wouldn't mind being able to buy a couple galaxies.

    Those are Zimbabwe dollars. You can buy a coke or a half a loaf of bread.

Leave a comment on “Absurdly High "Values"”

Log In or post as a guest

Replying to comment #:

« Return to Article