• TBon (unregistered)

    2^56 = 72.057.594.037.927.936, no wonder the value of 72.057.594.038.400.000 caused problems...

  • (cs)

    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

  • (cs)

    Just because you can doesn't mean you should. JUST BECAUSE YOU CAN DOESN'T MEAN YOU SHOULD.

    :(

  • TexDex (unregistered) in reply to TBon
    TBon:
    2^56 = 72.057.594.037.927.936, no wonder the value of 72.057.594.038.400.000 caused problems...

    I think that's not the only problems I see... that number could in theory be the result of a few very specific publications being selected. More likely it's the result of floating point precision where they should have used int (or rather, shouldn't have used this hare-brained scheme at all).

    CAPTCHA: burned

  • (cs) in reply to TBon
    TBon:
    2^56 = 72.057.594.037.927.936, no wonder the value of 72.057.594.038.400.000 caused problems...

    Indeed - PHP only stores integers natively for values which fit in a 32-bit signed value - once it goes higher, it starts using a high-precision floating point number instead. In most cases, the precision is high enough, but once it goes too high, well, this particular trick rather abruptly stops working; for example, if I run the code '$x = 72057594037927936; echo $x;' in Win32 PHP, the result is "7.20575940379E+16".

  • (cs)

    This is one of those WTF's where you almost have to be clever to come up with something this stupid.

  • Ash (unregistered)

    Very clever. It might be a good idea if integers didn't have storage limits.....

  • (cs)
    ...he left Computer Science for an English major.
    I hope he done learnt lotta English rightin' code!
  • (cs) in reply to akatherder
    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.
  • Expat (unregistered) in reply to ParkinT
    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.

  • (cs) in reply to TBon

    This would actually be a nice solution if the number of items stored was fixed and known to be a small number (e.g. less than 32 or so).

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

    If you didn't have subqueries available it would be even worse. You would think that typing out this kind of code would have caused somebody to think twice about what they were doing...then again you would probably know better than to trust the average developer's judgment.

  • rawr (unregistered) in reply to savar
    savar:
    This would actually be a nice solution if the number of items stored was fixed and known to be a small number (e.g. less than 32 or so).

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

    If you didn't have subqueries available it would be even worse. You would think that typing out this kind of code would have caused somebody to think twice about what they were doing...then again you would probably know better than to trust the average developer's judgment.

    I prefer to call them software grunts instead of software developers. ;) After all, they just mindlessly mill about int he code they were told to work on.

  • Jon B (unregistered)

    Simple solution:

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

    CAPTCHA: bathe. Ouch.

  • Pyro (unregistered)

    it's no problem you just need a bigger integer :)

  • (cs) in reply to Jon B
    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

  • Josh (unregistered) in reply to Pyro

    The real WTF is that they were using MySQL - they are lucky that the database stored that large value without silently modifying it!

  • Sandy (unregistered) in reply to Pyro
    Pyro:
    it's no problem you just need a bigger integer :)

    32 bits should be enough for anybody!

  • (cs)

    Yet another case of management unwilling to spend time on code reviews. Interns, Grunts, Jr. Developers, etc and the companies that employ them would all benefit greatly taking just an hour each week to review the work performed.

    Is it really a WTF if the problem is so common?

  • (cs) in reply to akatherder
    akatherder:
    This is one of those WTF's where you almost have to be clever to come up with something this stupid.
    Indeed. Which - if I'm not mistaken - was one of the original interpretations of the new Worse Than Failure site name...? (according to the article that accompanied the change)

    For the first time in aeons, and actual WTF!

  • (cs)

    We have a stupid like this in our codebase. It's actually slightly combinatorial, but in that 'not really' sort of way.

    Of the 64 possible values you will only ever have 2, 3 or 4. Not really viable.

    We're on our 6th revision and it's still not gone away, mainly because it's in really vital sections and deleting it would break a lot of stuff.

    Thankfully the original idiot who thought it was a good idea...moved on.

    SQL hates bitmasks.

  • (cs)

    The ERP system we use stores, for example, order line item sequence numbers, as increasing powers of 2. It's always kind of made me a little uneasy that some day I might discover why it does this, and be horrified.

  • (cs)

    TRWTF is PHP

  • SomeGuy (unregistered)

    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.

  • (cs)

    I see that both the Perl and the Postgres elitists have checked in. Too bad the story doesn't mention OS or we might have the "real WTF is using Windows" crowd.

  • (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

    Of course it was. I chose it.

  • Nutmeg Programmer (unregistered)

    Our coder paid too much attention in computer school. Like the sorcerer's apprentice, he learned how to invoke things he couldn't control.

    I often surprised when a test for equality works. Data gets changed all the time behind the scenes.

  • Paul (unregistered) in reply to Expat
    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?

  • An apprentice (unregistered) in reply to Quietust
    Quietust:
    Indeed - PHP only stores integers natively for values which fit in a 32-bit signed value - once it goes higher, it starts using a high-precision floating point number instead. In most cases, the precision is high enough, but once it goes too high, well, this particular trick rather abruptly stops working; for example, if I run the code '$x = 72057594037927936; echo $x;' in Win32 PHP, the result is "7.20575940379E+16".

    If the floating-point inaccuracies are at fault, I have a robust solution: change the column type to varchar(255)!

    (please tell me that's not what they did...)

  • (cs) in reply to Jon B
    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...

    Now THAT is funny!!
  • jread (unregistered)

    Newbie programmer here who doesn't really know what bitwise operations are. Could someone explain?

  • JB (unregistered) in reply to H|B

    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.

    Also, some people have the regex stigma (it looks more difficult, therefore it's a bad idea) on bitmasks, which I don’t agree with at all. They’re a tool, just like anything else. In an environment with a constrained number of flags and where storage and database IO is at a premium, bitmasks can be an extremely efficient way of storing boolean values.

    Just because some of the people on this thread don't understand the power of bitwise operations doesn't mean that they aren't the right choice when used correctly—it just means that you're all destined to make far worse WTFs because of your ignorance.

  • JB (unregistered) in reply to H|B

    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.

    Also, some people have the regex stigma (it looks more difficult, therefore it's a bad idea) on bitmasks, which I don’t agree with at all. They’re a tool, just like anything else. In an environment with a constrained number of flags and where storage and database IO is at a premium, bitmasks can be an extremely efficient way of storing boolean values.

    Just because some of the people on this thread don't understand the power of bitwise operations doesn't mean that they aren't the right choice when used correctly—it just means that you're all destined to make far worse WTFs because of your ignorance.

    CAPTCHA: muhahaha (I think this site is mocking me)

  • SNF (unregistered) in reply to jread

    http://en.wikipedia.org/wiki/Bitwise_operation

    That pretty well covers it. For the purposes of today's WTF, however, you need only understand that bitshifting left grows a number exponentially and will very quickly overflow whatever datatype it's being stored in.

  • b^2 (unregistered)

    Re: bitwise operations

    Integers are stored in binary. For instance, assuming 8-bit integers, 68 is 01000100 and 15 is 00001111. The & operator (bitwise AND) goes through two integers bit by bit and ANDs each but. Thus, in the example shown so far, 68 & 15 would be equal to 00000100 (4) since the 4 bit is the only bit enabled in both numbers.

    Thus, an array of boolean values can be stored in a bit vector where each bit corresponds to a certain flag and the value of that setting can be extracted with a bitwise operation. For instance:

    sampleInteger & 0x00000010 would return 2 (00000010) if the second bit of sampleInteger was enabled and 0 if it wasn't. Since in many modern programming languages 0 is false and anything else is true, you can simply use the syntax

    if (sampleInteger & mask) to see if a flag is enabled.

    CAPTCHA: sanitarium (I think an insanitarium would be more fun)

  • Bob (unregistered)

    Hmm...question for the purists: Does the use of the value field this count as a violation of 1NF, which requires that the domain of each attribute include only atomic values? There's a structure implicit in a bitfield, but is that still said to apply when the accepted values have only one on-bit each? It's isomorphic to consecutive integers.

  • Josh (unregistered) in reply to jread

    Bitwise operations compare numbers at the bit level. Think of each variable as an array of bits.

    Bitwise AND: Bit-X-Result is 1 if and only if Bit-X-Operand1 AND Bit-X-Operand2 are 1

    Bitwise OR: Bit-X-Result is 1 if and only if AT LEAST ONE OF Bit-X-Operand1 OR Bit-X-Operand2 is 1

    Bitwise XOR: Bit-X-Result is 1 if and only if ONLY ONE OF Bit-X-Operand1 OR Bit-X-Operand 2 is 1.

    He was using the sum of the values as an array of bits. That is, you could visualize the variable as a series of checkboxes for publications. So if the ordered, say, the WSJ and the Washington Post, youd get 10000010 (reading right-to-left, the "2" bit and the "128" bit are set).

    The problem with this is that variables aren't really designed to be used this way. It can work if you have a very small number of bit-flags to set (see hardware architectures and error flags), and that number is exceedingly unlikely to change. But if you have a long list of publications that may change over time, you're in deep crap. Worse yet is if you can't guarantee how many bits you'll have (if you were coding this in C, you could typedef your value to a uint32_t, then later to a uint64_t, and not have to worry too much at first).

  • Anonymous (unregistered) in reply to Bob
    Bob:
    Hmm...question for the purists: Does the use of the value field this count as a violation of 1NF, which requires that the domain of each attribute include only atomic values? There's a structure implicit in a bitfield, but is that still said to apply when the accepted values have only one on-bit each? It's isomorphic to consecutive integers.

    Well, in the current form the field is just a weird encoding for an enum, and therefore atomic. So no, I wouldn't count it as a 1NF violation.

  • JohnFx (unregistered) in reply to TBon

    I think this WTF defines quite nicely the term "Clever idiot."

    I get the feeling this programmer read an article about bit-masks and forced the issue to apply the newfound knowledge. Unfortunately this is all too common. This type of situation is probably responsible for 2/3 of the XML usage in existence today.

  • Eryn (unregistered) in reply to xtremezone
    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.

  • fanha (unregistered)

    Only two WTFs I see here.

    The first paragraph of the article; the rest is nothing but expected.

    And the comments here trying to justify how this might be a valid approach given the right assumptions. The idea is stupid down to the lowest level. This sort of trick is only "clever" in any way, shape, or form if you're still a student learning language basics, not if you're actually writing professional code that will be expandable, readable, and maintainable.

    It would be even worse if it did work, because it would embody the spirit of Worse Than Failure: shipping the code as a brilliant clever success not realizing you failed at good software development practices.

  • (cs) in reply to Paul
    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!

  • sgb (unregistered) in reply to savar

    This would actually be a nice solution if the number of items stored was fixed and known to be a small number (e.g. less than 32 or so).

    Indeed I've used this method many times - when needing to store the status of a small number of flags. We have web services on an intranet where there are 'roles' defined per service type; there are never more than 5 or 6 roles. A given users' access privilege is stored as a single integer which is interpreted as bit flags. This method does have valid uses - obviously the case in this WTF is not one of them. In olden days when resources were limited storing info as bit flags was common.

  • Matthew (unregistered) in reply to operagost
    operagost:
    I see that both the Perl and the Postgres elitists have checked in. Too bad the story doesn't mention OS or we might have the "real WTF is using Windows" crowd.

    Perl elitists?? Here? Yeah right. Mostly .NET and Java elitists around here as far as I can tell. Except for me, I'm a Ruby elitist. Didn't most of the Perl elitists drop out the web dev scene when CGI went out of fashion?

    BTW, PHP sucks.

  • (cs)

    I love having to maintain code from someone who completely dropped out of the industry.

    I've had to replace someone who decided he could make more money running a marijuana grow house and my boss had to drive to his house to pick up the dev server (the dev server being at his house is another WTF altogether) and the thing smelled like he had been smoking most of his crop.

    I've also had to take over for a programmer who fled the country to find his "Muslim roots" in the Middle East. At least he was too lazy to do any major damage, although most of his code didn't work at all.

  • Lee Burch (unregistered) in reply to JB

    I like bitmaps as much as the next guy but perhaps you missed the point yourself.

    This is one of the instances where a bitmask is a bad idea, that is why it is here on WTF.

    Quite simply you can't effectively query things such as "Who is subscribed to the New York Times". Not saying it is impossible just saying it does not well match the index that the DB would build over a bit mapped field such as this.

  • david (unregistered) in reply to Bob

    It's a violation of relational database system design, because it uses an external coding of the data, rather than using the relational database system.

    BTW, a good optimising RDBMS would store this index in a bitfield anyway, for small numbers of values, and would seamlessly handle the extension to many values when it was required.

  • Jeltz (unregistered) 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.

    I disagree in this case. The implicit casting from integer to float is evil. I much prefer the way of Python and Erlang where all integers have an arbitrary precision. The classic way of having a finite precision is fine too. But what PHP basically does is treating all numbers as floating point numbers and still have bitwise operations. Evil!

  • (cs) in reply to JB
    JB:
    Also, some people have the regex stigma (it looks more difficult, therefore it's a bad idea) on bitmasks, which I don’t agree with at all. They’re a tool, just like anything else. In an environment with a constrained number of flags and where storage and database IO is at a premium, bitmasks can be an extremely efficient way of storing boolean values.

    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.

  • dreadlocks (unregistered) in reply to Lee Burch
    Lee Burch:
    Quite simply you can't effectively query things such as "Who is subscribed to the New York Times".
    SELECT whatever FROM subscribers WHERE (value & 1);
  • dreadlocks (unregistered) in reply to dreadlocks

    ...of course if you were doing that manually, then you'd have to know the values (SELECT name, value FROM publications), but obviously there'd be a script written to retrieve this info for you, where you simply select publications and it gives you a subscriber list.

Leave a comment on “Absurdly High "Values"”

Log In or post as a guest

Replying to comment #:

« Return to Article