Yesterday a comment on HackerNews got me thinking about the horrible horrible code I used to produce as a young human (and to this day)

To be honest, I wouldn’t worry too much. Everyone is like “I was programming since I was 10!” Nobody ever asks what they were programming at 10, most people wrote relatively simple stuff until they grew up and got a professional job.

Now to wait for replies from people who designed OSes when they were 12 :)

I started programming when I was 9 because there was a class at my school. Without that class I’d probably become something silly like a writer or a linguist. Thank you ZRI and the awesome professor whose name I can never remember. You guys are great!

Back then I used Logo, which was fun, but the real fun started when they let me loose on Pascal at 11. I have no idea how good a coder I was for an 11 year old, all I know is that I was a terrible coder by real standards.

Here is a non-exhaustive list of the worst monstrosities I have created in the past 13 years.

1. A maths tutoring program

Age: 11

Tech: Pascal and text “graphics”

I wanted to make maths exercises and present them to the user. Use random to produce infinite examples.

But, I didn’t know about GotoXY yet and couldn’t print things at specific points on a text screen. That’s why I implemented the welcome screen as a set of procedures that would print an increasing number of empty lines before the “WELCOME!” line.

I needed many procedures because I didn’t know about loops either – each had a hardcoded number of empty lines. They were called as a huge chunk of code with a delay to make it smooth.

Code lost to history.

2. A space invaders game

Age: 11

Tech: Pascal and BGI graphics

English: One of several aliens found in the se...

This is NOT how my invaders looked (Photo credit: Wikipedia)

I called this game space invaders – I had no knowledge of the real space invaders game. Mine was just two spaceships floating above you that you would shoot at from below.

I discovered BGi graphics so I could draw pretty things on the screen. I even knew loops this time. The problem was that I didn’t know about arrays yet so there were roughly 200 global variables in the code. I remember the main problem being that Pascal said “Hey, your line of code can’t be _that_ long!” so I had to break up variable definitions into separate lines.

Code lost to history.

3. An “OS”

Age: 12 to 13

Tech: Pascal, text graphics and a mouse driver

Something like this

Something like this

I wanted to make a general interface to my computer that looked just as cool as Turbo Pascal 7 did. I called it an operating system even though it was really just a visual shell running on top of DOS.

It had a lot of general programs for doing various tasks – I can no longer remember how many, but I know there were a lot of menus you could click around to get to stuff. You could even run native programs (I often used it to launch Doom). You could, of course, set up different settings for how things looked and even sign in as different users.

There was a secret way to type a password so you could go into Admin mode and mess around with settings of other users!

Version 2 featured a much slicker GUI. (no screenshots remain, sorry)

I eventually had to learn how to properly use functions and procedures because the GOTO instruction couldn’t jump around the 4000+ line monstrosity anymore. And all those “programs” you could run? Monolithic codebase, not actually different programs.

Oh and I still had the problem of having to split up global variable definitions into separate lines.

Code lost to history

PS: I later tried to implement this in BGI graphics, but never got past the stage of drawing windows

4. Space Invaders v2

Age: 12 or 13

Tech: Pascal and BGI

At this point I still had no knowledge of the real Space Invaders game, so I made a game where you were fighting against two opponents flying to and fro above you. When you shot them down new ones would fly in.

I think this was mostly due to limitations in the code (array size? number of variables for opponents? don’t know).

The coolest thing about this game was that you could purchase new weapons and ammunition and that the AI players could run out of ammo as well, at which point they would just crash into you.

For some reason there was a potato head guy on your dashboard, offering encouragement and tips. There are no more screenshots, but I could probably reproduce the GUI with pen and paper.

By this time I had gotten past my obsession with GOTO jumps, but records were still beyond my grasp. I didn’t know about readability either so most of the variables were a, aa, ab and so on. But I finally started indenting my code! That was lovely.

Code lost to history.

5. Space Invaders v3 (might have had a different name)

Age: 13

Tech: Pascal, 24-bit graphics, mouse driver, BMP sprite library

This was my first game that started looking good. Due to limitations of memory and such you could still only play against four opponents at a time, but they finally started flying around in 2D space instaed of just left-right at the top.

You could also fully play with a mouse this time so your spaceship replaced the mouse cursor and you could click to shoot. That was lovely. And so was the fact I started using BMP sprites and 24-bit graphics – it was all really shiny!

Unfortunately just drawing the parallax effect on the stars in the background wasted so much resources there wasn’t much that I could add to the game beyond moving around and shooting. I also had a lot of trouble with array size and the amount of bullets that could be drawn on screen.

Eventually I scrapped the project because I kept getting the equivalent of a “null pointer” error and I didn’t know what a pointer was.

Code lost to history.

6. Space Invaders 3D (might be a different name)

Age: 13

Tech: Pascal, 24-bit graphics

I wanted to make a 3D engine and failed miserably. designed it around the idea that the universe is a cube and when I update whatever is on the screen, I simply have to update everything else that you don’t see as well.

After adding two objects to the screen my computer would run out of memory (16MB of RAM) and it took forever to update a single step anyway, so the “game” was completely useless.

Code lost to history.

7. A personal calendar app

Age: 14

Tech: Delphi

I think this app was some sort of way to keep track of tasks and stuff. It would show you a calendar – that I implemented manually of course. You could add events and stuff to get reminders later.

Except I didn’t even know how to properly calculate when it’s a leap year (hint: not just “is it divisible by 4″). But it did win me the 3rd prize in a national program developing competition.

Code lost to history.

8. A ww2 shooting game

Age: 14

Tech: Delphi

You know you’re bound to fail when you set out to make a 2D shooting game in Delphi with the idea that you can make a running animation by quickly changing sprites on an object in a window.

After spending a few months getting the game menu just right, with good pictures and ominous music I lost interest and never even started working on the gameplay itself.

Code lost to history.

9. An assortment of early websites

Age: 15 to 16

Tech: PHP

I can’t pinpoint a specific project from this era. There were many smaller ones and a few big websites designed for the webcomics I thought I could make in those days.

The main issues I had were understanding that I can’t just pass state around like I’m used to in a dynamic program, HTML being a stateless protocol confused me to no end. Most of my code also relied on register globals and other monstrosities like that.

Figuring out how sessions work took forever.

Code lost to history.

10. Chlorine Boards – a website-making system

Age: 17 to 20

Tech: PHP

After I got frustrated with the phpBB system of mods and extensions I started working on an opensource system for creating websites so that modules didn’t have to know about each other at all.

Essentially a good idea that even got used in the wild by some large-ish websites because I convinced a web agency that they should hire me because I can use this thing.

There were at least several failings

  • I used relational databases very incorrectly (at first). To the point of not knowing how a many-to-many table works
  • I wrote my own template engine and language – complete with a poorly implemented template-to-php compiler
  • There was a package manager that couldn’t resolve dependencies and was implemented as a 2000 sloc function
  • Everything was a singleton
  • others I can’t think of

Code still lives on sourceforge: Chlorine Boards

11. Text mining engine in PHP

Age: 19 to 20

Tech: PHP, Perl

Around the time Zemanta was launching with a very well implemented text mining system, I started working on my own. From scratch. In PHP. It grew out of a tag cloud generator and was actually pretty cool – could even make out sentences, find collocations and so on.

But I should have known something was terribly wrong when I had to implement some key regular expressions in Perl because PHP’s regex engine wasn’t fast enough.

Word of warning: don’t write a sentence extractor as a regex. Even if PCRE does let you do that.

I think the guy who inherited that codebase still hates me.

Code lost to NDA’s.

12. Twitulater

Twitulater screenshot

Twitulater screenshot

Age: 20 to 21

Tech: Javascript, Adobe AIR

The idea was simple – a twitter client that lets you filter conversations based on what’s happening. Put links in different tabs, have happy tweets here and conversation tweets there. Modeled very much after TweetDeck, but better! Better in oh so many ways!

Except it was utterly buggy and complete crap. There is something terribly wrong when you have 20,000 lines of spaghetti javascript on your hands, created by a guy who doesn’t know enough about very simple things … such as how Javascript handles closures and how exactly events work.

Code is archived on github: Twitulater

13. A reinforcement learning -based graph clique analyzer

Age: 22

Tech: python, django, databases

Without much machine learning experience I decided that thinking of a graph as a set of objects with forces acting on them would be a good idea. Then you can just run a particle simulation and eventually the nodes that belong together will float to one another and you can pick out  overlaps with a grid-segmentation algorithm.

When new data flies into the system in real-time you can just tweak the forces between related nodes.

Simple stuff.

Except that’s not really how one goes about finding cliques in a graph. I didn’t even know the name of the problem was “finding cliques in a graph” and thought I was breaking some awesome new ground.

At first I even implemented this inside a relational database and, as you can predict, everything broke down. Calculating a single result would take seconds, even minutes … just getting the nodes out of a database was completely untenable. The problem was slightly alleviated once we moved to App Engine and its BigTable.

In retrospect, I should have used a graph database. They were just getting popular around that time too!

Or, you know, use an algorithm that doesn’t use an incredibly slow and complex process for the first part and then a very slow process for the second part. That might’ve helped.

Code lost to pure shame.

Enhanced by Zemanta
  • http://blog.matejzavrsnik.com/ Matej Zavrsnik

    Is there anyone that didn’t do Space Invaders? :) Congratulations for graphics, my version was ASCII art.

  • http://swizec.com Swizec

    Apparently some people did pac man instead, or asteroids.

    But I really have no idea how it could’ve taken me _so long_ to realize there was a real Space Invaders game out there.

  • sjpwarren

    I love the progression in languages, much like myself. I am curious, did you enjoy PHP? I have had to use it a few times and I find it a mess of inconsistent function names and methodologies.

  • andyclondon

    Back in the 1980s everyone thought they could be come rich and famous by programming games. My two additions to the dustbin were “Bod and the Vampires” a maze like game where you had to collect the garlic and avoid the vampires and “King Penguin in London”, a fighting game loosly based on Renegade witha Penguin theme!. Most of the “programming” was done on paper as it was faster that way…

    http://www.youtube.com/watch?v=oUwEVDprocM

  • http://twitter.com/Sticktalk Sticktalk

    My first “big” program was written age 11. We had a teletype link to a University, but could still only run Basic. I’d read about Cobol and wanted to have a go; so to both learn the language and provide a way to run it, I wrote a Cobol Interpreter in Basic! It was actually pretty full-featured (as that sort of thing goes) and produced a massive array of Cobol “compiler” errors, but the sheer joy when I first wrote a Cobol program that actually ran was worth all the hours staying behind after school and in at lunchtimes. The program size was eventually limited by the length of the reel of paper tape that it was stored on; I was able to tape several together but the spool was too big to fit in the holder in the back of the Teletype eventually…

  • Moutaz Haq

    I actually *did* write an OS when I was 12!

  • Daniel Van Der Werken

    It’s not fair to include stuff you wrote before you were 20 years old. The fact you wrote bad code then is not surprising. What about now? Even now, I look back a few months and say, “Did I write this crap?”
    You’re fortunate. At least you had programming languages and options available at 11 years old. I didn’t start until high school and that was before the Vic 20 days. We had some giant piece of iron at my high school that used a teletype input. Also, a Commodore with a cassette for storage.

  • Paul

    No version of Star Trek – that was what we wrote when I was cutting my teeth as a programmer (15) but then that was 31 years ago. This was also before Paramount put pressure on various Star Trek games to call them something else.

    Basically 100 10×10 grids in a 10×10 grid you travelled around shooting Klingons using either phasers or torpedoes – there were various versions floating around and we even had a multi-user version that ran on the Harris H500 minicomputer at school – or even more ancient – a paper roll on a teletype at the school I atteneded connected by a modem to an ICL. They were not have bad either.

    We also wrote an email system because the official one was so bad – when it finally came out this was BWWW (Before the World Wide Web) so email was pretty new. There was no domain as such – each user had a unique identifier which was their email address.

  • http://blog.outsharked.com James Treworgy

    Haha! Priceless stuff here. My greatest achievement was “Exodus Construction Set” which I happened to find my handwritten “documentation” of in a pile of memorabilia my mom gave me recently. It was a map editor for Exodus: Ultima III on the Commodore 64. Back then we shared stuff “online” at 300 bits per second. I seem to recall writing that stuff in basic, compiled with some long-forgotten basic compiler, with a lot of hardcoded assembly language subroutines for CPU intensive stuff. I actually taught myself to write 6502 machine code in hex before I wrote my own assembly language compiler (in basic) because there wasn’t one… it’s astounding anything worked at all :)

  • Cei Thor

    There is no such thing as bad code. “Bad code” is how you learn to write “good code”, therefore you have learned something, which is always good. So I propose that “bad code” be called “practice code”. :)

  • winston

    When I bought my first computer – an Apple II Plus – I had already been programming real computers for 8 years. To say I was underwhelmed is an understatement. That was 1982. In 1988 I discovered you could put SCO Xenix on a 286 PC. That was a shock. It actually did multitasking correctly, and memory management correctly. All along I thought PCs were crap, when in reality DOS was crap. The 286 was rock solid with Xenix. Multitasking was invented a long long time ago in a galaxy far far away. It took Bill Gates 20 years to sell it back to us bit by bit, and in some ways he still hasn’t gotten it. When I launch MS Word (on Windows 7), my laser printer warms up, and I can’t do anything until it’s done warming up. That’s dos-brained nonsense. If we want to talk about crappy programs written in youth, Bill Gates and MS Dos has to top the list. And whenever any one process is allowed to hog resources – at all – that’s when windows still reeks of dos, 32 years later.

  • Cardin

    When I was 13, there was an individual school assignment to use Flash to create an interesting quiz program. My friend asked for my help, so I helped him create a hard-coded simple arithmetic quiz from scratch. For myself, I created a dynamic quiz generator that randomly gives any maths arithmetic problem. I got a C grade. My friend got an A.

    As you can imagine, I was pretty pissed. But the code I submitted was probably one of the most messed up, non-OOP code ever. I still doubt she understood any of it though, since we never even covered variables in class.

  • Fernando Buelna

    I started at 15 with a Commodore 64. Did some things in text and graphics (also a paint program) and sprites. Then at 17 started a top-view race game in assembler just to find that the assembler I used (found in a magazine from Spain) became errant and scrambled my source code lines. Then I decided to write my own assembler as an extension to BASIC v2.0 called BASSEM and it got published in COMPUTE!’s Gazette in Apr-May 1990 (by then I was 20). That was my greatest achievement before getting a Job… and after I think :P … Later I got my hands in a Amiga 500 and among a few things I did a Connect-4 game (AmigaBASIC) which later translated to C in a PC (Turbo-C) and now I’m trying to re-do it in Objetive-C for iOS…

  • Paul G

    #8. I did that. A lot. I wrote a significant number of pretty *awesome* game menus, actually, less technical failures than they were failures for me to stay focused. My crowning achievement in that category was a game menu written in C, targeted at the ZX Spectrum using the Z88DK framework (maybe 8 years ago now). I found a simple BZIP2 library, wrote code in Linux to compress a screen dump (generated from some line art using GIMP) and write it as a hexdump which was #include’d into the game code. Ported the uncompress function over to the Speccy and had it decompress to the screen. Worked really nicely. I’m sure the game itself would have been awesome if I hadn’t lost interest!

  • nick

    I was thinking that as I read it haha

  • nick

    I remember I wrote a few monstrosities early on in C++ and VB6. I used to love VB6 for rapidly throwing stuff together. With an Win32 API reference, I decided to make a program where a ball bounces around the screen changing colors. An undefined behavior, far as I figure, made it glitch where it moved a bit, then looked like it got stuck between two invisible walls, vibrating on screen. So… I created a window under it right at that spot, sized it appropriately, put in some decoy windowing code, & presented it to the class. To this day, they marvel at how I was able to “integrate Win32 GDI with forms” without any explicit code. Ah, the power of perception. ;)
    I did a C++ implementation of High-low. Not understanding its logical operators, it kept making some weird mistake on equality or converting strings to numbers. Lacking code, I still have no idea what it was. (I came from a QBasic & VB6 background just expecting shit to work intuitively, ya know?) So, it came down to around four conditionals & prolly a 1 page function. However, my version took 5-10 pages of indirection that simulated doing the conditionals. Since the game wasn’t CPU-intensive, the resulting code still met all goals. Good commenting & modularization increased page count, but meant it was maintainable. (HA!)

  • Jorick

    The difference between a good programmer and a bad programmer is that the good programmer learns from his mistakes. Looks like you’re a good programmer.

    I’m pretty sure I wrote the very first computerized Monopoly game back in 1973. But I never got a chance to finish it because I ran out of memory on the HP 2000F minicomputer the school used. It had only 8K core memory. But I cut my teeth on that program and learned a whole bunch of good (and bad) programming practices.

  • Whistler

    Haha – one of my early efforts aged 9 was Random Archery on the Spectrum 48k. I couldn’t work out how to include any kind of element of skill, hence its name. Quite unsatisfying to play…

  • http://swizec.com Swizec

    Thanks :)

  • http://swizec.com Swizec

    Yeah it’s really quite sad.

    But it did teach me one important lesson, _always_ start with the core functionality FIRST.

  • http://blog.ginx.com.br/ Sergio Garcia

    I think we can’t do right at first. We must do a lot of wrong thing before we learn how to do the things right. Your post remembered me of myself, I started programming when I was 14, and like you I did a lot of thing wrong. Unlike you, I started in C.
    Books were for a long time my only source of knowledge, and when I entered the market, I really understand a lot of things that didn’t make sense at time.
    Today I’m 27 and I’m a software architect, now I can say that I did a lot of good projects and a lot of good work, but like everyone I did a lot of bad things.
    Congratulations for your post, it is a very good one.