Skip

The Daily WTF
October 15, 2004 12:51 PM   Subscribe

The Daily WTF features braindead code samples. High-larious to a nerd like me.
posted by sonofsamiam (41 comments total)

 

Q: How do you generate an 8-digit random number in PL/SQL?

A: Keep generating random numbers in an infinite loop until you get one that's 8 digits in length:


l_int_seed_value:=((SYSDATE - TO_DATE('01011970','mmddyyyy'))*24*3600);
dbms_random.initialize(l_int_seed_value);
out_num_rand:=dbms_random.random;
WHILE out_num_rand<0 OR (LENGTH(TO_CHAR(out_num_rand)) !=8)
LOOP
  out_num_rand:=dbms_random.random;
END LOOP;


HAHAHAHA
*wipes tear from eye*
beautiful - really great link, thanks
posted by cmicali at 1:11 PM on October 15, 2004


In today's example, there are two errors: He's missing "Þ/þ", and he mistakenly reassigns "ð" as "o" (should be "d" or "th").
posted by lodurr at 1:12 PM on October 15, 2004


All I got upon clicking the link was "Service Unavailable". wacky hijinks ensued.
posted by infowar at 1:13 PM on October 15, 2004


Can someone explain how to code to me so I can laugh, too?
posted by Mayor Curley at 1:15 PM on October 15, 2004


Same here, infowar, are we detecting a case of Glass House here?
posted by tommasz at 1:17 PM on October 15, 2004


Yeah. Unavailable. This seems to work.


posted by Pretty_Generic at 1:17 PM on October 15, 2004


Thanks Pretty_Generic!
posted by dabitch at 1:19 PM on October 15, 2004


I see the first page, but most of the other pages (archives, etc.) are "Service Unavailable". I think it must be the wacky ASP.NET way of saying "argh too many visitors argh argh".
posted by hattifattener at 1:21 PM on October 15, 2004


I got in after a few tries, it's good stuff, if you're a coder like me. Non coders stay away, no laffs here for you! Sorry.
posted by chrid at 1:22 PM on October 15, 2004


"Service Unavailable"

Yeah, that's a hoot.
posted by bshort at 1:23 PM on October 15, 2004


Glass house? Eh... it's not his fault... it's just ASP... </snark>*

--
* I'm entitled. I used to make my living from ASP...

posted by lodurr at 1:25 PM on October 15, 2004


There's a subset of developers here who's day is not complete until this posts every day.
posted by yerfatma at 1:45 PM on October 15, 2004


Wow. End of week burnout: whose.
posted by yerfatma at 1:46 PM on October 15, 2004


Apparently the site's code itself is a big WTF with all the service unavailable errors.
posted by xmutex at 1:51 PM on October 15, 2004


100 100010010 001 1010!!!!11!!
posted by naxosaxur at 2:08 PM on October 15, 2004


This isn't the first time we've seen programmers having a difficult time gasping the intricacies of negative numbers. Heck, I'm sure we all had a little difficulty understanding at first, in the fifth grade. But you'd really think that someone able to program (am I giving too much credit here?), would have a little more sophistication than to distinguish positive and negative numbers with the “little line thing“ in prefixing the number.


//return whether a double is negative
bool IsNegative(double n)
{
string nStr = n.ToString();
if (nstr.IndexOf('-', 0, 1)) return true;
return false;
}

posted by jpoulos at 2:22 PM on October 15, 2004


jpoulos that was what i was going to post first, truely a thing of beauty
posted by cmicali at 2:25 PM on October 15, 2004


jpoulos, cmicali:

Ditto.
posted by linux at 2:38 PM on October 15, 2004


don't you think a lot of this site is the bad sneering at the worse? the example above is pretty shocking, but most of the other examples i looked at don't hit the same spot, and even for that example people worry more about technical details (-0.0; misguided comments about representation) than elegance (no-one mentions the redundancy "if (x) then true else false", for example).
posted by andrew cooke at 3:16 PM on October 15, 2004


This site always makes me laugh. They posted one about version control which is pretty much the way my company's graphics/html section still does it.

But my favorite is this select statement:

CREATE PROCEDURE sp_get_order (
@OrderID int
) AS

select * into #temp_order from Orders
delete from #temp_order where OrderID<>@OrderID
select * from #temp_order
drop table #temp_order

Something apparently is wrong with

select * from Orders where OrderID = @OrderID

and why is this a stored procedure? Security, I bet. At least that's the way my boss thinks.
posted by bashos_frog at 3:51 PM on October 15, 2004


Wow, weird. I stumbled across this site about a week ago (I think via del.icio.us). I'm not enough of a programmer to "get" all these, but many of them are pretty entertaining.

(The entry about "the best-est version control" that bashos_frog references hits a little close to home, though!)
posted by neckro23 at 4:49 PM on October 15, 2004


I can't find my favorite: it was an enormous switch case and loop to determine if every character in a string were numeric instead of using a regex.
posted by yerfatma at 4:57 PM on October 15, 2004


Okay, I almost got one of the SQL examples. Hah.

But I am havening no luck understanding the rest.
posted by scarabic at 5:14 PM on October 15, 2004


while(1)
{
*read HowBigIsMyCallStackSort() *
*giggle*
}
posted by of strange foe at 5:29 PM on October 15, 2004


My favorite part of that site is how the comments are usually an actual attempt to answer "WTF?" Eventually someone comes up with some twisted hypothetical for why the code makes sense.
posted by smackfu at 5:42 PM on October 15, 2004


OMG, I recently came across something a lot like this one and was circulating it among friends. I can't believe I never saw this site before, although the dearth of PHP/MySQL stuff made me reflexively think, "OF COURSE they can't program, they're webtrash!"

The only thing worse than a dork is a snobbish one.
posted by Eamon at 6:38 PM on October 15, 2004


yerfatma: your favorite?

Don't sweat the Service Unavailable. That's just how IIS / ASP works under load. Hit "Reload" 8 or 10 times and it'll serve a page.

It's kind of sad that the site slams PHP and VB code so hard. Typically, Visual BASIC and PHP is written by non-programmers who have never made anything more complex than a BAT file. It's easy to make fun of people who barely understand what they're doing and couldn't possibly know better.

At work I printed out ObjectWrapper.java at poster size. It's as pointless as a lot of the code I have to put up with people trying to check in at work.
posted by majick at 6:51 PM on October 15, 2004


> Can someone explain how to code to me so I can laugh, too?

Self-taught coders find ways to make stuff work. They werent taught how to make algorithms, write decent code, how to do things in non-silly ways, and all the other stuff you pick up in a CS program. CS nerds find this funny. Its like having a pro wrestler laugh at a guy who works out once or twice a week. I fail to see the humor.
posted by skallas at 7:44 PM on October 15, 2004


Children often make really silly language mistakes when they are learning to talk. Sometimes they say things in strange and unusual ways, misusing words they have heard but don't really understand. Adults find this funny.
posted by Mars Saxman at 8:03 PM on October 15, 2004


skallas: I'm a completely self-taught coder with no CS education whatsoever, and I find my reaction to most of the examples on the site to be "you didn't think very hard about this, did you?" It's entertaining because in the real world I encounter similar badly written code from so-called professionals all the time, but rarely such spectacularly bad code. It's better to laugh at it than to become frustrated.
posted by majick at 8:04 PM on October 15, 2004


I'm not a coder at all and I find this funny.
posted by kenko at 8:15 PM on October 15, 2004


>"you didn't think very hard about this, did you?"

Not really. I mean the big jokes are people using case statements instead of regex? Shit, pick up a "how to web program" book and few to none mention regex. Or a web tutorial. Regex is a little counter-intuitive at first so I can see why authors would leave it out of the "dummys" books.

That said, I see some kids who want to build a website and be part of the information age. I see kids who want to make a voting box or a message box. I see kids who want to USE their computers, not just download ads all day, etc.

Okay fine, I'm being a grumpy old man about this. I fully understand how this is funny, but if you scratch the surface you might find a kid would could use your expertise not your laughter. There aren't that many coders out there and this stinks of the elitism I find with linux users.

>imilar badly written code from so-called professionals all the time

I feel sorry for you if the people you work with turn out code like this. Stuff like this wouldnt fly at most programming 101 classes.

I guess I have too much sympathy for people who want to use their computer to do things and this reminds me of some of the mistakes I did at first.

I mean what ever happened to the promise of the future of making the computer do things for you? Here we are using all this MS software, sticking to big corporate sites, etc. And on top of it we have disdain for those trying to get out of that scene. We laugh at someone who only knows case, for, and if. Oh well, I guess the dream of the everyday programmer is up there with the flying car.
posted by skallas at 8:56 PM on October 15, 2004


I'm betting most of the authors featured on this site have some degree in CS. In my experience, self-taught coders are always at least competent, but there are a lot of spectacularly dumb people coming out of college.
posted by zixyer at 9:00 PM on October 15, 2004


They could use your expertise, not your laughter

skallas, they're getting our expertise THROUGH our laughter.

Come on, no one's being vilified by name, and the examples are pretty educational. If this is elitism, it's the genuine, meritocratic kind, where we distinguish the good from the bad.

In any case, I feel a certain "there but for the grace of God" sympathy. I've done stupid things through pressure or inattention, and no doubt will do more. And if the worst that happens is that someone gets a good laugh, I'll be grateful.
posted by i_am_joe's_spleen at 9:12 PM on October 15, 2004


I've spent some time reading through and thinking about each and every one of the entries in the WTF archive, and they seem to break down a little more than just "kids trying to do something with their computers." In fact some of them look like stubborn old timers with very low adaptability.

In the "so-called professional" category you have:
Some early examples of people who don't understand database normalization and try to get clever. This is possibly almost forgivable.
Dinosaur programmers, who are translating their PLI, COBOL or RPG techniques to VB.
A fair number of "if all you know how to use is a hammer, everything's a nail" types. These are coders who don't bother to learn the features of the language they're using.
Plain old sloppy thinking and shitty coding.
Some obvious padding by contractors or consultants who are trying to make simple problems look hard to solve.

In the "muddling through" category you have:
One guy just trying to do some Excel automation. Clearly not a pro, but probably The Computer Guy around the office by default.
A couple of student projects that clearly don't deserve more than the mildest ridicule.
A few DBAs obviously being pressed into service for development they don't actually know how to do. Some other folks clearly dragged, confused, out of their area of expertise by incompetent management.
Some "I know HTML, this web application thing can't be hard" types. The examples given don't look forgivable -- some look like parts of major undertakings, not a few pages on Geocities and a poll.

And a good handful of miscellany:
Stupid UIs, stupid requirements/specs, a couple of "stupid client" type anecdotes, that kind of stuff.

Of these, a great minority are of the sort that are just starting out. I can spot rookie mistakes, I regularly deal with programmers in several languages who are obviously wet behind the ears. A lot of these aren't rookie mistakes, they're incompetence bordering on maliciousness.

That said, there is more than one example in WTF that I myself made when learning. I know all too well what it's like to be plunked down in an unfamiliar development environment, on a strange platform, and to be asked to produce an application of a sort I'm not familiar with. I recognize the mistakes that can lead to.

Most of what's on WTF isn't that kind of learning curve stuff. A majority are examples of people confidently going to great lengths to avoid doing the right thing. Just thinking things through a little more would have avoided a large chunk of this bad code.
posted by majick at 11:04 PM on October 15, 2004




Can anybody spot the weakness in security?
posted by SpaceCadet at 11:40 PM on October 15, 2004


It's not elitism to laugh at 9 identical case statements in a row to test whether a character in a string is numeric. I can think of a dozen other ways to do that, most of which should be more obvious than what was coded.

Ditto for the SQL example I posted - I really tried to figure out how someone could come up with that, and there is no good reason. The first page of any decent SQL tutorial would show the right way to do it. Therefore the person who did it is lazy or stupid or both.

I've made my share of mistakes, and I don't have a CS degree, but if anyone on my team showed me either that SQL, or the case statement mess, I'd have them out on their ass by the end of the day.

You want someone like that programming your bank's internet software? Medical software? The firmware controlling your ABS brakes? Air traffic control system? What is sad, and scary is that some of them will eventually wind up on such projects.
posted by bashos_frog at 1:49 AM on October 16, 2004


>You want someone like that programming your bank's internet software?

Err, how does WTF stop this exactly? Lets not get too full of ourselves here. The end result is a cheap laugh, not saving the world.

I also don't think you guys have to defend this, humor is subjective. Some things I think are not funny, actually are to others. You dont have to rationalize it away, if you want to laugh at bad coders, then do so, but don't feed me this ridiculous line that the daily WTF is some humantarian service to save me from faulty ABS firmware or 'everyone had it coming.'

Its like High School kids who make fun of fat kids. Hey, they find it funny. Fine. But lets not pretend their ridicule is going to change anyones eating habits for the better.
posted by skallas at 2:06 AM on October 16, 2004


Just last week I took on a web app project as a freelancer. I met a "programmer" (I was taking over from him) who'd sketched out the database schema of the web app and showed it to me. First off, he'd never even heard of relating two tables with a shared key, so his design was rather imaginative to solve the problems this lack of knowledge gave him. Secondly, the actual front-end design of the web app was done entirely using layers, not tables. Not that it's necessarily WRONG to use layers, but in this particular design, it was way wrong. Frankly, the whole thing was a mess, and I started from scratch.

However, at the meeting, I could see he was struggling and he did look nervous while he explained to me the project in front of the boss and his supervisor. I could have criticised obvious mistakes, but I didn't. I took in the info I needed and discarded the mistakes he had made; the guy was leaving anyway, and I sensed a lot of internal politics even just in that one meeting....there is sometimes a time and a place.

As it's already been stated in this thread, I'm sure all programmers here have been in situations where they've blagged their way through a project - not really understanding the full picture, and taking on a steep learning curve.

I think we all need some humilty here, because complacency is a very bad thing - bad programming habits are a blind spot we all have unless we are willing to accept criticism from others or even be self-critical. If you accept your weaknesses, lessons get learned.
posted by SpaceCadet at 3:59 AM on October 16, 2004


Can anybody spot the weakness in security?

There is a company that manages hundreds of sites for universities around the country (and gets paid enormously for it.) I found that, after a certain number of steps, the URL bar would have the admin variable sitting there exactly like that. I was able to edit any other of these universities' pages, since there was not even any filesystem-level security, everything was world-writable.

I pointed this out and they supposedly fixed it, but they just changed all the methods to POST.
posted by sonofsamiam at 5:01 AM on October 16, 2004


majick, that's the one. Thanks. skallas, I have to join the dissenters, though I appreciate what you're saying. I would say that most all the examples I've been forwarded look like people ratting on their co-workers, so I don't know how many amateurs are getting tooled on. And my enjoyment is directly proportinal to how "professional" the coder thinks they are; if something is clearly a newbie struggling through, it's not that funny anyway. The real schadenfreude comes from people who've clearly survived a career without knowing what they're doing. Except when my company buys a third-party component from them (*cough*ProductCart*cough*).
posted by yerfatma at 5:44 AM on October 16, 2004


« Older "Neil Young is coming by tomorrow for dinner. Time...   |   Typo with Lego Newer »


This thread has been archived and is closed to new comments



Post