Open Side Menu Go to the Top
Register
Our Personal WTFs Our Personal WTFs

03-27-2011 , 08:41 PM
Every programmer has come across a piece of code so bizarre, so awful, that you wonder, not what the guy who wrote it was thinking, but how he managed to get himself to work that drunk.

There's a website dedicated to these stories, that every self-respecting programmer should read, for your daily dose of "at least it's not that bad" - until, of course, it really is that bad. And then you come here, and tell us, so we can all laugh about it.

Sharing your own code, but pretending you didn't write it, is not only acceptable, it's expected. My first story in the next post.
Our Personal WTFs Quote
03-27-2011 , 08:44 PM
A real-life example from my job. We have a reports system (obviously). It also pages, 100 lines per page (less obvious, but it's an Ajax app, so it needs to be somewhat responsive). When we filtered the reports, we loaded the 100 items from the database, and THEN applied the filter, leaving a random number of items per page.

No, I did not code that. Yes, I fixed it.

I posted the above in another thread, but thought it would fit better here. This is also where I provide the mitigating factor for the programmer that did it this way, but also subtly mock him for another mistake he made.

He coded it this way, basically, because we needed filtering on reports super urgent omg do it today a major client wants it now, and it worked. The reason he couldn't easily do it with database queries is, essentially, his previous decision to JSON encode all values going in to a certain table, which stored the bulk of reported data. We're now working on ways to work around this decision for reporting purposes, but we had a period of a month or so where clients were seeing some ridiculous reports.

Last edited by Zurvan; 03-27-2011 at 09:00 PM. Reason: I don't normally write in function names
Our Personal WTFs Quote
03-27-2011 , 08:54 PM
We have rest calls to retrieve all users from a server, we don't have rest calls to get all registered users. We have rest calls to update pricing programs, we don't have rest calls to return all available pricing programs... Your basic "this is designed by people who don't have to use it" situation.
Our Personal WTFs Quote
03-27-2011 , 10:59 PM
Up until a few weeks ago when I started working on organizing things, the Java program I'm doing at work had 3 packages (data, gui, util). Data and gui had at least 75 files each. A number of those files were 1k+ lines and had lots of nested classes.
Our Personal WTFs Quote
03-28-2011 , 01:15 AM
A couple of years back our company purchased a COTS finance system. During the install process I had to run 1500+ sqltalk schema updates. As far as I can tell, I was installing the very first schema they released, followed by every patch the company had ever released.

Took me all of 5 minutes to cat the files together and create a behemoth sqltalk script but the... i'm not sure what to call it... of that install method astounded me.
Our Personal WTFs Quote
03-29-2011 , 05:52 PM
I wrote an asp.net app which included a dynamic table with all the cool stuff you would expect. Dynamically add/remove rows, sort columns, etc, etc. All that cool stuff you would expect in an ajax app... thing is I didn't know any ajax toolkits or apis or even what ajax was, so I wrote it from scratch.

It was a horrendous mash of asp.net embedding javascript at runtime which consisted of functions for writing tables whose cells were text inputs with indexed ids so that I could reference them when the form was submitted... other functions for adding/removing rows with onclick events... total. mess.

Before it went to production, the project was moved to a different department and while I was on leave, someone thankfully rewrote it and that code never made the light of day.

It did give me some appreciation of what is actually going on in real ajax toolkits though.
Our Personal WTFs Quote
03-29-2011 , 07:23 PM
When I first started programming, I was waiting a response from X service. So I thought I'd do a loop, 1 to a billion as a timer.

I have plenty of WTF moments looking back at how horrible I was starting out.
Our Personal WTFs Quote
03-29-2011 , 07:26 PM
Quote:
Originally Posted by thunderchicken
When I first started programming, I was waiting a response from X service. So I thought I'd do a loop, 1 to a billion as a timer.

I have plenty of WTF moments looking back at how horrible I was starting out.
At least you didn't starve while dining with philosophers!
Our Personal WTFs Quote
03-29-2011 , 08:06 PM
Quote:
Originally Posted by thunderchicken
I have plenty of WTF moments looking back at how horrible I was starting out.
This.

I still have an app in use by a few hundred users that is all one 2000ish line JSP. Shhhhh....
Our Personal WTFs Quote
03-30-2011 , 04:29 AM
I ran an SMS site once, it would let you send an SMS via my API if you account balance was >= 0 as supposed to > 0. I had one douche bag user that realised this and kept signing up for accounts and sending SMS's on loops spamming people in his country because it only deducted credits if your balance was > 0 so as to not go into a negative balance. I kept banning his account/IP and searching for the source of the problem.

Anyway it took me way way too long to find out the source of the problem and cost me hundreds of pounds. You live and learn I suppose! The most expensive < character.
Our Personal WTFs Quote
03-30-2011 , 11:36 AM
When your employer sends you a 1000 miles over the ocean to a client who's based in the country side in South America to adapt and implement software to his needs.

They usually argue for weeks who pays the flight, hotel and phone bill.

You get to a country which language you didn't even hear before that moment.

You get there, try to get comfortable in a tropic environment as a very pale, blonde, tall guy which draws the same amount of attention as an Alien.

You spend a day setting up your tech stuff in their office.

They then tell you with their hands and weird noises that they don't have internet for the next couple of weeks and that there's usually a power outage around noon for 4 hours.
Our Personal WTFs Quote
03-30-2011 , 11:39 AM
^ Sounds like a dream job imo, just go and chill on the beach with some brews
Our Personal WTFs Quote
03-30-2011 , 11:51 AM
Quote:
Originally Posted by Gullanian
^ Sounds like a dream job imo, just go and chill on the beach with some brews
You think so only until you realize they don't really have cabs that can bring you to the beach and back during the daily 4 hour power outage.
Oh, and that the guy who speaks English and is supposed to be your sidekick because the environment involves a lot of risks, was lying about his English but gives you free shots glasses of home made rum all day long, starting at breakfast. He also never moves. Never.

You then think, whatever, landscape is amazing, it's not far, I'm gonna walk.

Spoiler:
And then a donkey tries to rape you.
Our Personal WTFs Quote
03-30-2011 , 05:13 PM
Quote:
Originally Posted by wellju

Spoiler:
And then a donkey tries to rape you.
well, at least there are SOOOME perks.
Our Personal WTFs Quote
03-30-2011 , 05:25 PM
Quote:
Originally Posted by 00Snitch
I wrote an asp.net app which included a dynamic table with all the cool stuff you would expect. Dynamically add/remove rows, sort columns, etc, etc. All that cool stuff you would expect in an ajax app... thing is I didn't know any ajax toolkits or apis or even what ajax was, so I wrote it from scratch.

It was a horrendous mash of asp.net embedding javascript at runtime which consisted of functions for writing tables whose cells were text inputs with indexed ids so that I could reference them when the form was submitted... other functions for adding/removing rows with onclick events... total. mess.

Before it went to production, the project was moved to a different department and while I was on leave, someone thankfully rewrote it and that code never made the light of day.

It did give me some appreciation of what is actually going on in real ajax toolkits though.
eh we all make mistakes. Couple of years back, I was on a tight deadline and shipped all error logging as writes to the database because I had a crappy time previously arranging for read/write access directories for text logs and couldn't face dealing with sysadmin nazis about it. However, I hadn't thought through that what if the error is the database isn't responding...which threw an error writing to the database... etc etc


I sure drove that server into the ground during prelim testing, and kept blaming some 3rd party for the issue (which it kind of was, cos they had a crappy database connectivity...but even so, real schoolboy error I made not thinking that logging issue through).
Our Personal WTFs Quote
03-30-2011 , 07:23 PM
Same guy that wrote the code I mentioned in post #2 also wrote a logging system for our app. He got a little carried away; the database table for the log was growing by about 1GB/wk on average, and doing that in a day during busy times. Needless to say, they had to turn off the logging when it kept bringing down the site.
Our Personal WTFs Quote
03-31-2011 , 12:28 AM
I never took any advanced math classes and didn't pay much attention to math courses in high school.

Long story short I wrote this really disgusting function to get the results I needed for a problem and it took about a week (on and off, in my free time... just thinking about it and experimenting) to finish it.

I showed it to a friend of mine with no programming knowledge at all but was a straight up math beast. He simplified my function in about 5 minutes after I explained some very basic logic instructions to him (what an if statement does, etc.).
Our Personal WTFs Quote
04-01-2011 , 02:05 PM
Sigh

This morning, I made a change to live data

It was supposed to be a small change, a little administrative detail, that only affected me

Sadly, my WHERE clause was missing the "user_id=Zurvan", and thus, KABLOOIE

OK, not really kablooie, but it certainly caused some panic for the lead developer/CTO, and seriously inconvenienced some customers

The lesson today:
1. Don't edit live data before your morning coffee
2. If you're depending on Safe Query Mode in MySQL workbench, don't index irrelevant fields
Our Personal WTFs Quote
04-01-2011 , 02:33 PM
Trying to explain percentages to a QA person that doesn't have a basic understanding of math is tilting.

My chart
2 bars - each representing a resource(s) allocation of effort across a month based on actual working days.
Bar 1 - 17%
Bar 2 - 25%

Total average over two months
(17 * working days in Feb(20)) = 340
(28 * working days in Mar(23)) = 644

(340 + 644) + (numbers of days in both months(43)) = 22.8%

her math
(17 + 28) /2 = 22.5

WHY THEY NO MATCH?
I'm going home.
Our Personal WTFs Quote
04-01-2011 , 02:47 PM
I can +1 the..."gotta drink that coffee first"

spam = SomeLibraryClass()
ham = spam

...took me way longer than it should have that ham is just a pointer to spam and it should be
ham = spam.copy()

...which reminds me that I still need to write some testcases :P...
Our Personal WTFs Quote
04-01-2011 , 02:47 PM
Quote:
Originally Posted by Zurvan
Sigh

This morning, I made a change to live data

It was supposed to be a small change, a little administrative detail, that only affected me

Sadly, my WHERE clause was missing the "user_id=Zurvan", and thus, KABLOOIE

OK, not really kablooie, but it certainly caused some panic for the lead developer/CTO, and seriously inconvenienced some customers

The lesson today:
1. Don't edit live data before your morning coffee
2. If you're depending on Safe Query Mode in MySQL workbench, don't index irrelevant fields
LOL! I've done exactly this, but I'd forgotten until I read yours. One afternoon I was fixing a stupid typo on something or other, and updated the product name of every single stock item past and present in our shop to "AMD Duron 700MHz". spaz-pressed enter, wondered why it wasn't running - "oh, missing semicolon, ; [enter], blam >Update 564534 " Totally forgot the WHERE clause, since then I usually write it first then cursor back to write the rest lol.

Had daily backups so rolled back to yesterday night, but had to sit there and manually enter all of the day's trades based on the carbon copy from the receipt printer, fun times.
Our Personal WTFs Quote
04-01-2011 , 02:51 PM
Probably a good idea to somehow find a way to digitize those receipts just in case smth. like this will ever happen again (in which case you can just write a small script FTW)

Just saying because...it will happen again :P
Our Personal WTFs Quote
04-01-2011 , 03:29 PM
Fortunately we keep a clone database, so they were able to restore that one table to about 15 minutes before my change, and given the table, there was likely no data loss
Our Personal WTFs Quote
04-01-2011 , 04:00 PM
During one of my COOPs during college, the company I was working for asked me to write something to profile the server they just bought. The main thing they were focused on was if they needed to buy more memory for the processing they were using it for. Full Disclosure: I had very little Linux exposure before being assigned this task.

So I wrote this script that would scrap top for information about the memory usage and the active processes. I stored all this in a spreadsheet* and then use the spreadsheet to produce pretty graphs that could show the manager how the server was running over the course of the week. After a bunch of work to get all the pieces together, I finally had a graph of the weeks usage. I showed it to the manager and we were close to maxing out the memory at all times. He took the graph to accounting and used it to justify doubling the memory of the server.

The next day I was talking to the guys in the department about the data. They thought it was weird that we were always maxed out, even when not running the big processing task. Turns out the used field includes memory being used by the kernel to cache things and not just memory used by running processes. After a quick change to the formula, the graph now showed that we were well below the memory available to the system.

*Yes, I was using a spreadsheet to store all this data. The system admin refused to install mysql on the server, so I couldn't use a real database. Instead I ended up with these massive Excel files holding data points for each time information was recorded and records for each process that ran and how much it was using at that data point.
Our Personal WTFs Quote
04-01-2011 , 04:03 PM
Heh that's a pretty awesome story (I like it because it resulted in "free" memory)
Also: Screw the admin and just use sqlite FTW
Our Personal WTFs Quote

      
m