Comment On Absurdly High "Values"

Brian works for a web development shop with an all-too-common formula: lots of intern labor and a very high turnover. As a recent hire, a large part of Brian's job is maintaining old sites developed by various former employees. [expand full text]
« PrevPage 1 | Page 2Next »

Re: Absurdly High "Values"

2007-11-30 09:08 • by TBon (unregistered)
2^56 = 72.057.594.037.927.936, no wonder the value of 72.057.594.038.400.000 caused problems...

Re: Absurdly High "Values"

2007-11-30 09:09 • by 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

Re: Absurdly High "Values"

2007-11-30 09:14 • by Squiggle
Just because you can doesn't mean you should.
JUST BECAUSE YOU CAN DOESN'T MEAN YOU SHOULD.

:(

Re: Absurdly High "Values"

2007-11-30 09:14 • by TexDex (unregistered)
163612 in reply to 163609
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

Re: Absurdly High "Values"

2007-11-30 09:18 • by Quietust
163613 in reply to 163609
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".

Re: Absurdly High "Values"

2007-11-30 09:21 • by akatherder
This is one of those WTF's where you almost have to be clever to come up with something this stupid.

Clever

2007-11-30 09:23 • by Ash (unregistered)
Very clever. It *might* be a good idea if integers didn't have storage limits.....

Re: Absurdly High "Values"

2007-11-30 09:25 • by ParkinT
...he left Computer Science for an English major.

I hope he done learnt lotta English rightin' code!

Re: Absurdly High "Values"

2007-11-30 09:26 • by ParkinT
163618 in reply to 163615
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.

Re: Absurdly High "Values"

2007-11-30 09:38 • by Expat (unregistered)
163622 in reply to 163618
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.

Re: Absurdly High "Values"

2007-11-30 09:42 • by savar
163623 in reply to 163609
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.

Re: Absurdly High "Values"

2007-11-30 09:45 • by rawr (unregistered)
163624 in reply to 163623
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.

Re: Absurdly High "Values"

2007-11-30 09:46 • by 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.

Re: Absurdly High "Values"

2007-11-30 10:02 • by Pyro (unregistered)
it's no problem you just need a bigger integer :)

Re: Absurdly High "Values"

2007-11-30 10:03 • by xtremezone
163627 in reply to 163625
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

Re: Absurdly High "Values"

2007-11-30 10:24 • by Josh (unregistered)
163631 in reply to 163626
The real WTF is that they were using MySQL - they are lucky that the database stored that large value without silently modifying it!

Re: Absurdly High "Values"

2007-11-30 10:31 • by Sandy (unregistered)
163632 in reply to 163626
Pyro:
it's no problem you just need a bigger integer :)


32 bits should be enough for anybody!

As usual

2007-11-30 10:31 • by clively
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?

Re: Absurdly High "Values"

2007-11-30 10:47 • by PyroTyger
163634 in reply to 163615
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!

We has this stupid too.

2007-11-30 10:52 • by Benanov
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.

Re: Absurdly High "Values"

2007-11-30 10:58 • by db2
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.

Re: Absurdly High "Values"

2007-11-30 11:09 • by H|B
TRWTF is PHP

Re: Absurdly High "Values"

2007-11-30 11:24 • by 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.

Re: Absurdly High "Values"

2007-11-30 11:25 • by 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.

Re: Absurdly High "Values"

2007-11-30 11:25 • by T_PAAMAYIM_NEKUDOTAYIM
163648 in reply to 163610
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.

Re: Absurdly High "Values"

2007-11-30 11:27 • by 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.

Re: Absurdly High "Values"

2007-11-30 11:40 • by Paul (unregistered)
163654 in reply to 163622
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?

Re: Absurdly High "Values"

2007-11-30 11:45 • by An apprentice (unregistered)
163657 in reply to 163613
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...)

Re: Absurdly High "Values"

2007-11-30 12:04 • by ParkinT
163665 in reply to 163625
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!!

Re: Absurdly High "Values"

2007-11-30 12:32 • by jread (unregistered)
Newbie programmer here who doesn't really know what bitwise operations are. Could someone explain?

Re: Absurdly High "Values"

2007-11-30 12:56 • by JB (unregistered)
163686 in reply to 163640
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.

Re: Absurdly High "Values"

2007-11-30 12:58 • by JB (unregistered)
163689 in reply to 163640
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)

Re: Absurdly High "Values"

2007-11-30 13:00 • by SNF (unregistered)
163690 in reply to 163677
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.

Re: Absurdly High "Values"

2007-11-30 13:01 • by 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)

Re: Absurdly High "Values"

2007-11-30 13:18 • by 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.

Re: Absurdly High "Values"

2007-11-30 13:21 • by Josh (unregistered)
163693 in reply to 163677
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).

Re: Absurdly High "Values"

2007-11-30 13:59 • by Anonymous (unregistered)
163700 in reply to 163692
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.

Re: Absurdly High "Values"

2007-11-30 14:00 • by JohnFx (unregistered)
163701 in reply to 163609
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.

Re: Absurdly High "Values"

2007-11-30 15:15 • by Eryn (unregistered)
163709 in reply to 163627
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.

Re: Absurdly High "Values"

2007-11-30 15:21 • by 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.

Re: Absurdly High "Values"

2007-11-30 15:24 • by caffeinatedbacon
163713 in reply to 163654
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!

Re: Absurdly High "Values"

2007-11-30 15:57 • by sgb (unregistered)
163717 in reply to 163623
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.

Re: Absurdly High "Values"

2007-11-30 16:05 • by Matthew (unregistered)
163718 in reply to 163647
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.


Re: Absurdly High "Values"

2007-11-30 16:25 • by shakin
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.

Re: Absurdly High "Values"

2007-11-30 17:16 • by Lee Burch (unregistered)
163724 in reply to 163686
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.

Re: Absurdly High "Values"

2007-11-30 18:18 • by david (unregistered)
163726 in reply to 163692
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.

Re: Absurdly High "Values"

2007-11-30 20:11 • by Jeltz (unregistered)
163728 in reply to 163689
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!

Re: Absurdly High "Values"

2007-11-30 20:26 • by Opie
163729 in reply to 163689
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.

Re: Absurdly High "Values"

2007-12-01 02:38 • by dreadlocks (unregistered)
163737 in reply to 163724
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);

Re: Absurdly High "Values"

2007-12-01 02:40 • by dreadlocks (unregistered)
163738 in reply to 163737
...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.
« PrevPage 1 | Page 2Next »

Add Comment