Monthly Archives: November 2007

Random Numbers

I finally got around to replacing the old outmoded random number generator that the MUD has been using for ages. It’s the Mitchell-Moore algorithm and is present in just about every free codebase.

I ended up building a class that lets you select one of three random number generators to run the MUD engine on.

The first is the plain-old slow, ineffecient, and repetitive .NET random number generator.

The second is the R250/521 shift-register sequence generator. There’s a paper on it here:
http://www.informs-cs.org/wsc97papers/0127.PDF

The third is the Mersenne Twister, a fairly new algorithm by Matsumora and Nishimura. More information is available here:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

The neat thing about how I’ve set up the random number system is that new algorithms can be dropped in easily. I’m sure there won’t be much cause to change random number generators, but it’s a pretty easy option if we feel like it.

We’re now down to 2,591 compiler errors.

More Progress

The compile error count is now down to 2,654.

I’ve also added a codebase section to FindMUD since it seems that codebase downloads are getting harder and harder to track down these days.  There are only a handful posted, but I expect that the list will grow as the site evolves.

Under 3,000

The compile error count is now down to 2,779.

Some of the remaining code rewrites remaining are pretty significant:

  • Telnet/Network Code.
  • Data File Saving/Loading (I’m seriously considering rewriting data storage as database-based rather than XML-based).
  • Low-level string processing routines.

If you think about it, those three things are all you need to build a MUD (well, that and a command interpreter). Even though progress has been good lately, there are a couple whole-weekend projects coming up. With me house shopping and the holiday season creeping up I couldn’t possibly imagine having a running server before the new year.

A New Website

I’ve spent the past day putting together a site called FindMUD. It’s pretty similar in concept to The MUD Connector, but done in my own way. I’m not sure the world needs another MUD listing site, but it was fun to create. Each listing can be rated by users, so as the site develops you’ll be able to get a pretty good picture of what the best MUDs are.

Feel free to visit the site, create a login, and add listings for your favorite MUD(s). Let me know what you think of the interface and whether I left anything important out of what is asked for when submitting a new MUD.

Since the site is brand new (only 6 listings so far!), I’m sure there will be plenty of room for improvement.

A Pretty Good Chunk

Compile errors are now down to 3,293.

It feels a little strange to re-implement some of the core C-language character functions in C#.  Things like isdigit(), isspace(), and isalpha() are easy enough to rewrite, but there’s just something a little surreal about it.

Only A Stupid Programmer Would Try To Be Clever

Huh?

It takes an insecure jerk to write a clever line of code like this:

x?x=y=z=0:x=y=z+2;

What does it say? If X is true, set X, Y, and Z to 0, but if X is false, set X and Y to Z+2. It’s a shortcut written by someone who thought they were being clever. To an experienced programmer it’s readable, but still a little uncomfortable to deal with if you’re trying to trace a bug. The longhand version would be something like (note descriptive variable names):

if( LeftPosition != 0 )
{
LeftPosition = 0;
MiddlePosition = 0;
RightPosition = 0;
}
else
{
LeftPosition = RightPosition + 2;
MiddlePosition = RightPosition +2;
}

(Irritating failure to indent courtesy of WordPress.)

It’s longer to type, but a casual reader is more likely to be able to understand the code at first glance without having to re-read or decipher it.

If you read through any sizeable codebase you’ll find a ton of things done just for the sake of being “clever”. A lot of these are shorthand or obfuscation that has no real purpose since the compiler will generate the same executable code in most cases.

I think it boils down to insecurity. Programmers who don’t have much confidence in their abilities try to be clever and show off. Skilled programmers know a fundamental point about writing code:

Not everyone is as smart or skilled as I am, so I need to make this as simple and readable as possible.

Keeping this point in mind often results in code that is easier to debug, better-commented, and simpler to read.

Cleverness is quite possibly the number one reason why people prefer to scrap and rewrite a codebase rather than fix the problems in it. Code is easier to write than it is to read, and if it’s made all that more unreadable by an ineloquent programmer, then it’s less likely to stand the test of time.

Be a real programmer. Write simple, clear, understandable code. You will have to read your own code someday. Do you really want blood to shoot out of your eyes when you try to read it?

For further reading, check out the infamous “How to Write Unmaintainable Code”.