Wednesday, February 24, 2010

It's amazing I wrote some of this old code...and yet I don't regret it.

Another of the mini-goals of this iteration was to provide a "Welcome/Title" screen to magecrawl, allowing the player a place to enter a character name and choose between save files. As I might have mentioned before, this "attempt" at Magecrawl is not my first. I've written parts of my game before in C/C++/python before a settling on C#. My wonderful wife has heard more than one time about me throwing everything away and starting again (or wanting to). I had the title/welcome screen from a previous attempt laying around in an old svn account, so I figured I'd salvage that as a good place to start.

My goodness, if I didn't know for sure I was the author, I'd want to disown this code. Ignoring the horrible style of capitalization and spacing I must have once liked, I've found multiple WTF moments. See this. One involved a corner cases with the color scheme that sometimes overflows into an exception. One was a half a dozen lines of code trying to reinvent Path.GetFileNameWithoutExtension(), and doing it poorly. The other memorable one was me declaring an enum to record what menu item we were pointing to, then ignoring it in a half a dozen places and comparing directly against (0,1,2). I hadn't given the enum a numerical set of values, so it just "happened" to work.

There is a proverb in Go that says, "Lose your first 50 Games as quickly as possible". The idea is that in the beginning, you don't know what you are doing, so don't overthink your moves. After 50 games, you can begin to see what looks like a good move and why people play as they do.

I'm starting to think the same idea might be valid for programming a roguelike as well. Experience has taught me, and while I wouldn't suggest throwing all your work away over and over again (like I did), just getting out there and coding will make you a better coder. While I haven't entered a 7 Day Roguelike context myself, it sounds like something I'd suggest and should do myself in the future.


Ben said...

Ours truly seems to be a profession where there is absolutely, positively, no substitute for experience. As hard as I have resisted accepting this, I am coming around to seeing the barriers in front of me because of the years of experience I don't have. The good news for you and me, however, is that the love of coding drives us to put in the work that will slowly make us better.

Mingos said...

My first attempt at Umbrarum Regnum was some horribly written C code (still in MS-DOS, in a Borland compiler from early 90's) which eventually evolved into a @-walking-on-an-empty-screen demo, with "FOV" that simply calculated the distance between the PC and the tiles in range (no FOV-blocking). All using conio.h (I didn't even know what Curses was). It was laughable.

Then came the 2nd attempt, in Borland Turbo C++ (2005?). Didn't even reach the @-walking-on-the-screen stage.

Third attempt: a Java roguelike. I coded a Swing-based console emulator that was dreadfully slow, but displayed cool CA caverns.

Fourth attempt: C, in M$VC (and then switched to Code::Blocks). The code went unmanageable at an early stage, but managed to code map generators and monsters to fight. The code was refactored to resemble C++ (although was just a mix of the two).

Fifth attempt: the current one. Was going really good, there's some neat eye candy - but the code's lost its initial modularity and introducing changes has become very difficult.

The game's awaiting a sixth attempt.

Now, each and every step of this RL coding evolution ended more or less miserably. But each and every one has taught me so much that I'd never be able to code what I code today without these attempts. Each was an experience that shaped me as a programmer.

To cut the long story short: don't be ashamed of your old and sh*tty code. It has taught you a lot too.