Show HN your embarrassing (old) code

9 points by samlev ↗ HN
First I'll start off:

http://pastebin.com/ATdDUStd

That was from January 2008. I was young and stupid. I'm probably just as stupid now, but at least I can see now how stupid that was.

So let's open up the shame files, and show how far we've come by recognising how bad we used to be.

5 comments

[ 4.2 ms ] story [ 90.2 ms ] thread
Well, I don't know how embarrassing that is, and that's pretty embarrassing already. I can say that everything I've done for school is probably a good candidate, and 1 out of 3 practices using CodingBat is as well.

I love learning!

The code has long been lost to the great pastebin in the sky, but my first serious PHP project was an absolute nightmare. I built a disbursement tracking system for a local food bank/church while I was in high-school (~6 years ago).

The system was your basic CRUD application that tracked who the food bank gave money/stamps/assistance too. It also allowed them to generate some fancy reporting.

The code was so. damn. bad. This was before I even knew what an MVC framework was. The "main" control panel page was a single, enormous PHP script that was switch-cased. There was zero data validation, zero security, zero maintainability. It was a nightmare in retrospect.

To be fair, I did it for free and the church loved it, so oh well :)

This post prompted me to open up the first web app I ever wrote - a Rails 1.something app that was eventually upgraded to 2.something. It was pretty awful.

But as I went back to look at it, I found it wasn't unintelligible. It was just noobish. Lots of silly working around things that do not need to be worked around - that sort of thing. My models are mostly empty, if that tells you anything.

It's a testament to the Rails structure and convention that someone with no experience and a book can write something that not only works, but is reasonably readable despite being totally wrong.

As a side note, I made several thousand dollars off that app before shuttering it. Had it worked (the idea), I no doubt would have done some major rewriting. But it didn't so now I sit here looking at the fattest controllers known to man.

Can't post it because I don't have it but at my first job I was working late(2am) to get something ready for an 8am demo that absolutely HAD to happen(people flying in from across the country, stuff like that). I found a solution that would give me the right answer. It consisted of a switch statement. In each case of the switch statement was another switch statement. In about 2/3 of the cases in these switches was a GOTO to the top of the function to repeat the process. What can I say, it worked and was pretty good for 2am work(I am not a night person.) But even my year out of college self knew the code was bad and that I would have to re-write it. Except for the fact that the demo went great. Our processes would only let me change code if there was a bug. Try as I might, I could never find one. That code is probably still in use 9 years later.