- 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
so...the solution to lim(x->inf) f(x)=2^x is...what exactly?
Admin
A web registration form I inherited had this gem in it for generating confirmation numbers:
That's it. No checks, and of course there was no Unique ID on the database side. I caught it before any duplicate numbers were generated (this time around), but it shed light on issues they had the previous year were conference attendees ended up with duplicate registration numbers for some unknown reason....
Admin
btw Anon, I hope your exponential functions are well at 11.
Admin
It's clearly a misinterpretation of the specs. The random generator was supposed to be used for the amount, not the invoice number.
Admin
No. g(x)=1/x does not 'attain' infinity at x=0. It is undefined at x=0. (To quickly see why, look at what happens when x approaches 0 from below and what happens when x approaches 0 from above, you get two different results and there is no canonical choice, so g(x)=1/x is undefined at x=0).
As g(x) is undefined at 0, then for all x>0 there is a real number k with g(x)<k. This is not a useful characterisation to make.
The correct way to understand the 'infinite' behaviour of g(x)=1/x is to say that it is unbounded in any neighbourhood of 0. Or in other words, for any number N there exists a (probably small) number e such that for all 0<x<e we have g(x)>N.
This statement is the mathematically rigorous way of saying g(x) tends to infinity as x tends to 0 (from above).
Exponential functions behave in a similar way: f(x)=2^x is not defined at x=infinity in the same way that g(x) is not defined at x=0. But again for any number N there exists a (probably large) number e such that for all e<x<infinity we have f(x)>N.
Admin
Adding a random number to the url is only going to slow me down when looking for data for a particular sequence (ie. John's url is bar, so the next thing for John must be foo), not stop me from seeing data (Ohh... foo is cool, what's at bar?). A login is the only way to ensure that one customers data isn't viewable by any other customer.
Admin
The Real WTF (among others) is the use of MySQL - naaay - MyISAM tables for invoice data.
You should always use a real database - Postgres, Oracle, SQL-Server - for financial data. With MyISAM, if you sneeze one day or you look at the server the wrong way, your tables are corrupted.
If you are forced at gunpoint to use MySQL for financial data, you should always use INNODB tables, never MyISAM. At least INNODB tables are transactional and have some resiliency against failure.
The programmer who would know better than to use MySQL for this purpose would also know better than to create this WTF.
Admin
the correct fix is to add more 9s!
Admin
I have no idea what you're getting at with this comment.. The person that you're responding to has the right idea.
Admin
He probably thought it was really clever, and therefore fun to write and debug.
Admin
Wait, I think I just got it. You're not thinking that the application would generate the IDs are you? Every relational database I've ever worked with has the option of automatically incrementing integers for primary keys. Most are also multi-threaded (support atomic actions from simultaneous clients).
If you really want to generate the IDs yourself, most modern DBs also support transactions.
Admin
You have to wait until the random number generator returns the one invoice number still available, 0-999999 is 1,000,000 possibles.
Admin
Admin
Oh please, people store this kind of stuff in ACCESS databases for crying out loud! What's wrong with MYSQL? =)
Seriously, I agree with you on the MyISAM part most definitely. INNODB is also kind of a pre-requisite not only for transactions as you say but also for foreign keys. The first thought that came to my mind when I saw MyISAM in that definition was NO FOREIGN KEYS! I mean, I'm sure there are other tables that reference that Invoice ID and doing so without foreign keys is another WTF.
But other than that, as long as stuff like that is stored properly using INNODB I don't see a problem with using MYSQL. Not everyone needs Oracle for crying out loud!
I've got MySQL running next to me on the server here and it's been doing its job faithfully for over a year now with no problems.
Admin
Of course you are right that 1/x does not "attain" infinity; Sorry, my maths vocabulary is slighty rusty. However, there is still an important distinction between the behaviour of 1/x and 2^x; unlike 1/x, 2^x is defined for any finite x. The question of it being defined or not at infinity is a moot point; to my knowledge, infinity is not generally considered part of the domain of any function. What's more, you cannot say that for any real number x there is a k such that k > 1/x, since this has no sense for x=0. However for k > 2^x it does have sense and is true. Consequently, this is a useful characterisation to make.
To get back on topic, my point was that the id generation will take inifinite time for a finite number of occupied IDs (1000000), so the execution time cannot depend exponentially on the number of occupied IDs (at least it cannot be dominated by an exponential term near where it matters).
Admin
In most cases there's a serious performance benefit for 'doing it in the database', especially when loading batches or doing something which can be done completely on the database.
Makes the application code cleaner too, just throw a call into sp_DoSomethingInteresting and you're away.
Admin
Admin
You know, back in the day I was evaluating help desk software for a network operations center, and my eventual pick was shot down by the chief propeller head because the ticket IDs started at 0.
"We can't use that. Everybody will know that it's a new trouble ticket system if the numbers start at zero."
"They're going to know it's a new system anyway, because only about fifty people even have our phone number, and prior to this they've never gotten any kind of incident number at all. What are you going to do, start the ticket numbers at ten thousand and hope nobody notices?"
We wound up not implementing anything.
Admin
A commonly held duck? I don't get it.
Admin
Yes. Yes there is.
Admin
Because that would eliminate the need for a random number generator.
Admin
What I find humorous about this is that, while this system of generating random numbers and checking their existence is profoundly stupid, he deliberately chose to use 'mt_rand()' instead of rand() to get a 'better' random number.
Admin
Shame about all the database and threading crap.
Admin
The green will have a pond in it, or by it.
The pond will most probably have ducks resident in it.
English village greens are held "in common," unless subject to some hideous parliamentary Act of Enclosure.
Thus, the ducks are held "in common."
Simple, really. And now back to the real universe, in which words can have more than one meaning and are interpreted according to context. A difficult thing to achieve in SQL or PHP, but one that's oddly satisfying in English.
Admin
Sheesh, we've been running ours for the better part of 7 or 8 years now without any significant problems. Just the occassional repair table when some idiot does something like unplugging the server thinking he was unplugging some other device.
Admin
I won't even comment on the code implications of random invoice numbers; that's been covered.
Some have pointed out that as a customer, it would look bad to place invoice number 800234 and later 800235, making one think they're the only customer. I've seen plenty of places that use a prefix for the client, so I would just assume in such a case that my client ID was the 800 prefix, and many others in business would assume this as well.
What would make me do a double-take as a customer, and possibly reconsider doing business with a company, would be getting an invoice numbered 800234 one day, followed by 312789 a while later. Once, I might think they re-did their invoice codes. More than once, and I'd have serious doubts about how they ran their company.
Admin
Admin
My personal favourite was in my first job - all primary keys where a 13 character string holding a time stamp in yyyymmddhhnnss format. When operations were 'too quick' (as they liked to call it) they simply waited one second and generated the next one. I skipped out of the building when I handed my notice in.
Admin
He started off with a decent thought - predictability of invoice numbers - but then turned into a WTF of it's own. I almost think it is a clever joke.
Admin
Admin
This discussion is getting less and less funny as it goes along. It is, however, still a little funny. It appears to be asymptotic humour.
Admin
http://mydata.wtf/000000001_CB34D6853C8C4BD3B37A30AD433349AC.html
and bar is at
http://mydata.wtf/000000002_96B8CF3D1E994E32BDF78E95F17B3BED.html
knowing foo doesn't get you to bar. I could have a billion URLs like this, and if they're cryptographically strong, guessing gets you nowhere (except for very large values of guessing).
You can't get bar without knowing the URL, just like you can't login without a password. It's a reasonable system for giving out fine-grained access that can be useful under specialized circumstances---e.g. customized download URL's when you buy software.
Admin
Admin
Admin
Hmm ... where it belonged ... PRODUCTION! ;)
Admin
Yes, but you're thinking like a rational person, try thinking like a manager instead.
Admin
I believe that you should use Scope_Identity() function in SQL Server. That way you won't get the value of a different table if a trigger does an INSERT into another table with an IDENTITY column.
Admin
URLs before: ...?ID=[sequential] URLs after: ...?ID=[sequential]&VC=[large number picked at random associated internally in DB with ID]
The original network had problems with secure session handling so entire site was stateless - no cookies, no sessions, all info passed via URL or form post.
The original code was really messed up so this was the quickest solution that required the fewest modifications. Still allowed for URLs to be shared within organizations, providing deep linking was enabled.
Also, was a junior at the time. When you have higher-ups yelling, you do what shuts them up the fastest.
Admin
Sometimes you want unpredictable ID:s to avoid users to circumvent the application by predicting the ID of the next/previous record.
But you still want an unique index on it to avoid trouble.
Admin
Admin
Maybe that number leaks to the outside, so your competitor can order twice, subtract, and know the rate you do business.
Admin
The random number thing made me seriously go "WTF" out loud. At work.
I would love to see an invoice where my invoice number came in the form of a GUID - that would be awesome.
Admin
Oracle, of the top of my head, declare the key as autoincrement, do something like insert into bar ( id ) values ( id_sequence.nextval ) returning id_sequence.currval into foo
or something like that. You should be able to look it up :-)
Admin
Wow. At least my predecessors had the, uh, decency, to do "SELECT MAX(id)+1 FROM some_table;" to get the next free identity.
Every day I go to work, I die a bit more.
Admin
Did they have the decency to wrap that in a transaction or something?
Admin
So how did it know when it was done? Did it just run forever and give you a higher and higher degree of confidence of sorting?
Perhaps it did a full scan of the array after every flip to see if it was now in order? That seems the most logical solution for such a sorting algorithm.
Also, bogosort.
Admin
Admin
Admin
PLEASE DEFINE NONTRIVIAL
Admin
Since I stopped wearing my roo-fur-lined KangaFoil cap around ten years ago, I've had this persistent feeling that there's somebody out there who's trying to tell me what to do. I can't help myself. I keep asking these imaginary people, "Why?" and "Don't you realise how stupid that is?" and "You do realise that this will kill people, don't you. And not just worthless poor immigrants, either" and "What do you want to be when you grow up?"
I mean, it's embarrassing. Obviously, I pay no attention to the imaginary answers (I might be credulous, but I'm not that credulous), but just the fact that I believe these phantoms are there is troubling.
Actually, I believe that "thinking like a manager" is an oxymoron. Not just because managers are an imaginary irritant, but because, by definition, they are incapable of thinking.