Category Archives: Programming

Building software.

Quora Answer: What did Steve Jobs mean by programming ‘teaches you how to think’?

I originally wrote this as an answer to a question on Quora.

It forces you to figure out how to solve a problem in a way that can be explained to a computer.

By doing this you learn to break down a problem into its components, how to define the problem using constraints (you have to figure out what’s going to go in and what’s going to come out of your code), you have to be precise, and you have to have a full understanding of all of the components of the problem and its solution in order to solve the problem.

This define and disassemble approach to problem solving is something that is very applicable to problems across many domains, especially science, engineering, and mathematics.

Quora Answer: What are some ways that programming was better in the past?

I originally wrote this as an answer to a question on Quora.

In the “bad old days” the actual programming work wasn’t much different, just worse. Monitors were smaller and lower-resolution, chairs more uncomfortable, you had to spend a lot more time waiting for the computer to finish what it was doing, hardware was much more expensive, tools were barely capable, there weren’t pre-existing libraries for much of anything, open source wasn’t a thing, and there weren’t good marketplaces for selling what you created.

There was no internet, no StackOverflow, and no communities to go to for help. You did not have a Meetup group in your town where you could talk to other people working with similar technologies.

The one thing that was better in some ways is that fewer of the “interesting” problems had been solved yet, and many of the solutions and applications that were built were created by a single person with an itch to solve a particular problem.

Though sometimes I wish I could go back to a time where Java did not exist yet, programming really was awful in the old times. The same goes for the web. Sometimes it feels like it would be nice to go back to a time before it was hypercommercialized and mainstream – a time before the popup ad existed and before you couldn’t avoid being inundated with inane celebrity gossip on sites like Twitter and Facebook – but no. It was nearly useless back then.

Quora Answer: Which career is more fun, networking or programming?

I originally wrote this as an answer to a question on Quora.

Full question:

“Say networking is a blanket, for IT, systems administration, and network security. We’ll say programming is basically web app development. Can anyone with experience in either of these fields give some pros and cons about what they do and do not like?

I have basic knowledge in web development and none in networking, but I have recently taken a liking to getting involved with network security, and I think I would like systems administration more than programming so I am curious as to your opinions.”

I’ve done both, and still do both.

I almost always prefer building software, but there are almost no days where it’s easy. The big draw for me is that it’s creative work and is a form of artistic expression, more in the way that literature is than painting. I also find that my level of enjoyment is inversely proportional to the number of people involved in the process.

Both paths rely on having a great deal of knowledge. While you can look up specifics, having enough background to understand the specifics takes a lot of  learning and experience. Once you know the material well, networking and system administration are usually easier and less stressful, requiring a lot of thoroughness, attention to detail, and keeping track of things.

Both rely on having a set of tools that you rely heavily on. In software, it’s your IDE, debugging tools, libraries, frameworks. In systems it’s a set of utilities, commands, scanning tools, or even hardware tools.

What I dislike about what you put in the umbrella of “networking” is that if you’re good at it, it can get to be pretty boring. When systems are running well, you’ve earned your pay, but it’s when things are breaking that it gets most interesting. And stressful. And you get the least recognition for your efforts. Though ages ago I was an MCSE and worked with Microsoft products regularly, I’ve grown into being a Linux bigot and can’t stand working with non-open-source systems. Luckily I’m in a position where I don’t have to, but you may not have a say in what things you end up working with.  Same goes for programming, really.

One place where it gets interesting is when you combine the two, and that’s what I refer to as DevOps. It’s system administration AND programming. This involves working with tools that create and configure servers, deploy things, set up security, and perform all sorts of IT administration tasks, but instead of being done by a team of 20 IT staff, they can be done by one person. Things like Chef, Puppet, Vagrant, Salt Stack, Ansible, Fabric, Capistrano, and Nagios are popular and worth exploring.

It’s a lot harder to find a “sane” work environment in programming. Almost nobody who hasn’t done it appreciates how incredibly difficult it can be. Douglas Crockford said that “computer programs are the most complex things Humans make”. Being able to manage an environment like that where people aren’t just cogs in a machine takes a special kind of person, and unspecial managers abound. Lots of little things can add up to make a chaotic and stressful environment. It’s often more “interesting” in product companies, but those are a small part of programming. Most programming is writing “boring business apps”, like order entry systems, sales report generators, accounting tools, and other business-specific pieces. It’s no less challenging, but often less stressful and more stable than building software products. The challenges are just different, and one’s not better than the other. I’m a product person, you may not be.

Before making a decision, I’d recommend exploring the world of DevOps first. Not only is it a growing trend and career path, it’ll give you a taste of the administration side of things and you may fall in love with it. Or you may like every part except for the programming and go full IT.

Quora Answer: Is it rude to change a co-worker’s badly written code?

I originally wrote this as an answer to a question on Quora.

Full question:

“I joined a company as a new grad and currently working with two mid level and one senior designer. It’s a chip design company. One of my co-worker’s code is very badly written and I am pretty sure there are many other good ways to implement the same thing. Badly written code bugs me a lot and I’m tempted to change/improve it. Will it look bad if I go ahead and change his code? Or should I ask his permission beforehand ? I’m not sure what will be a good move as I’m comparatively new in industry. I don’t wanna look arrogant!”

Yes. It’s also rude to write bad code.

The best way to handle that is a code review. It’s not necessary to have anything formal – just spend a few minutes going over the code together so you can point out what had issues and why.

Just changing the code without communication will cause two problems: The original writer is likely to resent it, and the original writer won’t learn anything and will keep doing things the same way. There’s also a risk that you don’t fully understand the intent or scope of the changes and your “fixes” might break something.

Don’t make it adversarial or approach it in a way that puts the other developer on the defensive. That will make them non-receptive to the conversation, and the goal is to improve the code and the developer both now and in the future.

ModernMUD Source Now on Github

As dumb as the name might be, I decided to go with “ModernMUD”.

The source code is available on Github under the BSD license:

https://github.com/Xangis/ModernMUD

There’s a lot more to be done with documentation, but the XML comments are decent enough to make IntelliSense useful. I’ll probably be posting more about invidiual sections of the source, particularly the clients (all four of them!), in the near future.

If you’d like to chip in, or use the code to build your own MUD, you are more than welcome to do so.

Preserving Newlines in XML Serialization

With .NET’s XML serialization, it kills newlines when you serialize XML to disk. More specifically, it converts a CR+LF into just an LF (\r\n becomes just \n).

This was causing annoyances with the spell editor, since you can edit source code for spells with it, but the code would appear all on one line after saving and reloading.

The fix was to declare XmlWriterSettings with a newline preference.

The code was this:

         public void Save()
         {
             XmlSerializer serializer = new XmlSerializer(GetType());
             Stream stream = new FileStream(FileLocation.SpellDirectory + FileName,
                 FileMode.Create, FileAccess.Write, FileShare.None);
             serializer.Serialize(stream, this);
             stream.Close();
         } 

And now it’s this:

        public void Save()
        {
            XmlWriterSettings ws = new XmlWriterSettings();
            ws.NewLineHandling = NewLineHandling.Entitize;
            XmlSerializer serializer = new XmlSerializer(GetType());
            Stream stream = new FileStream(FileLocation.SpellDirectory + FileName,
                FileMode.Create, FileAccess.Write, FileShare.None);
            XmlWriter writer = XmlWriter.Create(stream, ws);
            serializer.Serialize(writer, this);
            stream.Close();
        }

I can have my newlines and eat them too. Oh joy!

I Am Addicted To Github

Until recently, the only code I’ve released as open source has been the Magma MUD codebase.

In the process of posting the Magma source on Github, I kind of got hooked on posting code online. Since then I’ve posted the source for a handful of applications, a mix of Linux and Windows desktop apps. A 12-day commit streak so far, yay!

I’m also considering open-sourcing the Basternae 3 codebase. The main things that make it easier to work with than old-timey C-based MUDs are the use of C#, which has amazing exception handling and debugging capabilities (no more attaching gdb to a core dump), and speaks XML natively, so data files are Human-readable, portable, fairly robust, and extensible. The editor is also getting to be pretty good.

To open source Bast3, I’d need to write a lot more documentation, and I’d need to “genericize” a lot of things that are specific to Basternae. It’d be a lot of work, but I think it’d be a fun project. The source is already in a private repository on Github, but that’s the easy part.

Using MonoDevelop

I’ve almost always used both Windows and Linux, but I stopped using Windows a few months ago.  One of the things that only runs on a Windows machine is Visual Studio.  The Basternae code was compiled on a Windows machine and then uploaded to the Linux host.

Without access to that, it was time to try using MonoDevelop.

MonoDevelop
It was able to load the Visual Studio solution, with some exceptions:  The client WPF project didn’t load, nor did the abandoned Silverlight project.  I could probably install more packages to make WPF work, I’m not sure yet.

I noticed that the compiler works differently for some things, like terminal characters.  The ECHO_ON and ECHO_OFF sequences broke logging in, but some weird prompt formatting that’s been around for a while just fixed itself.  It will be interesting to see what other diffferences turn up.  Even though C# is supposed to work the same on all platforms, I suspect that it might work better when both the build and run machines have the same operating system.

You Can Now MUD on webOS (TouchPad)

Much of my not-at-work development time has been spent on webOS lately.  The TouchPad and webOS version 3.x are great fun to work with and the only mobile devices that have APIs that don’t suck to develop for (I’ve worked with Android, iOS, and Win7 and none of them are fun from a C++ developer’s perspective).

Today my Telnet application was published in the catalog.  It’s still not perfect yet, but thanks to that application it’s now possible to MUD on the TouchPad.

Win32 Visual Styles

Nothing to do with Basternae, this is just a reminder to myself how to enable the visual styles for controls available in Windows XP and newer in a WIN32 project in Visual Studio 2010.  Had to do this at work and it’s a little tough to look up.

1. Edit Project settings.
2. Under Linker->Manifest File edit “Additional Manifest Dependencies” and add:

type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*';%(AdditionalManifestDependencies)

Suddenly Win32 controls will stop looking like they’re from Windows 3.1.  The modern control styles were introduced in ComCtl32.dll version 6, and Windows apps use version 5 by default unless you tell them not to.

New Game: Dragon Wilds

http://dragonwilds.com

I built this oldschool over-the-2400-baud-modem game in my spare time over the past week using Python and Django (it’s about 500 lines of source code, 500 lines of HTML templates). I don’t know whether I’m going to spend more time on it, but it was fun to build and a nice break from the to-complex-to-work-on-with-the-brainpower-I-have-left-after-work state Basternae 3 is in. If people like it I’ll probably make more of them or improve the existing game. First time I’ve done a web-only game.

Let me know if you can break it. As can be expected, there’s really not that much depth to it and you may well get tired of it quickly.

Back to WPF

A while back I made a start on building the client using WPF, the Windows Presentation Foundation. It only made sense to give it a shot since the whole MUD is based on C# and .NET.

That effort stalled due to a roadblock or two, probably because I didn’t know about routed events and partly because I didn’t understand RegEx very well. I have a better handle on regular expressions thanks to spending some time with the Django web framework.

In the process of trying to rework the C++/wxWidgets-based client to support the new tiled map graphics I’ve experienced a lot of pain. The kind of pain that can only be explained by the fact that a string is not a first-class object in C++ and that text parsing can get to be unbearable when you have a complex stream over TCP.

That has prompted me to take a look at the WPF version of the client again. Rather than being based on some ugly recursive character-by-character text processing code, it’s based primarily on regular expressions — one to parse out the ANSI codes, and one to process the XML tags for the various client data (life meter, map info, room description, etc.). The first one was done when I left off, but the second piece hadn’t been started yet. Well, it’s in place now and I can continue building the rest of the newer client.

Getting the WPF version up to and past the usability of the wxWidgets version will probably be faster than untangling the text parsing in the spaghetti code.

C#: Compiling For 32-bit Systems on 64-bit

I recently upgraded from 32-bit Vista to 64-bit Windows 7.  I may be one of the only people who didn’t have anything bad to say about Vista.  For me it was a huge step up from Windows XP, but since I have 6GB of RAM in my system it’s a little silly to run a 32-bit OS.

I understand the differences between 32-bit and 64-bit C++ code behavior quite well, but I really haven’t spent any time digging into the differences between 32-bit and 64-bit .NET IL code.  Apparently it’s all quite a bit simpler in managed code.

Just right-click on a project, click properties, click on the build tab, and then select “x86” under “Platform Target”.

Visual Studio 2010

Three months ago I switched from Visual Studio 2008 to Visual Studio 2010 as my main development environment.  Functionally it’s the same as it’s always been, but there are two things about it I consider great improvements.

First, the UI:  It looks so a lot better and cleaner than earlier versions.  It’s not that older versions were ugly, but it has a cleaner look and is much easier on the eye.

Next, C++ Development:  For the last few versions of VS, C++ developers have pretty much been shafted — no real feature improvements for the most part with all the love going to C#.  C++ received a major boost, gaining just-in-time compilation and error-detection intellisense almost exactly like C# has always had.  It doesn’t sound like a big deal, but it is excellent for speeding up the code-compile-fix cycle.

Only a small portion of Basternae code is in C++, just the client and the Basternae 2 to 3 zone converter, but it is a lot more pleasant to write with Visual Studio 2010.

This project started on Visual Studio 2003, so now we’ve been through four versions.

Zone Format XML Schema

I used the Microsoft XSD.exe tool to generate an XML schema file from the zone classes. That probably means nothing to most readers of this blog, but here’s the .XSD for the Basternae 3 zone format:

Basternae 3 Zone Format XSD

No reason really, just in case someone might be an XML tinkerer and wants to try running it through some of their tools, or if some masochist wants to browse it. I’m pretty sure there are some tools out there that will generate a data editor based on an XSD file format, but I’ve never had my hands on one. I have heard that Java and Eclipse have some pretty good XML tools.

Fun With XSL

One of the good things about having data stored in XML files is that you can use XSL stylesheets (templates) to format the data into HTML.

I created two basic templates, one for races and one for classes, and linked them to the data files used by the MUD. They don’t have any fancy formatting, but they do display the data in a Human-able format.

The result is that the class and race webpages link to the data files being used by the MUD. This means that you can view info about each race and class exactly as it’s being loaded. If we change something in the data file, such as adding a new spell or adjusting a race’s dexterity, the web page that is displayed is updated automagically.

This means that the pages for each race/class will essentially maintain themselves. Neat, eh?

Artificial Intelligence Markup Language (AIML)

One of the things I plan to have the MUD engine support is AIML. That’s an XML-based file format that defines conversational data for a “chatterbot”. I’m sure most everyone has heard of the Eliza, Julia, or A.L.I.C.E chat bots.

The idea is that you can create personalities that respond to certain phrases, much like quest messages do/did in previous versions of Basternae, but you can take it even further by having compound triggers, matches, variables, and responses to previous inputs.

There’s really no limit to how simple or complex you can make your ‘bot’, from responding to only a single phrase to an encylopedia of knowledge that might almost pass the Turing test.

Here’s a bit of info about the format:
Overview from Dr. Wallace, creator of AIML

And, of course, here’s the obligatory Wikipedia link:
AIML on Wikipedia

One tool I’ve found that I like so far is the GaitoBot AIML Editor, which you can get here:
GaitoBot AIML Editor Homepage

If you know any German, the bot on the Gaito site is kind of fun to banter with. I know just enough to make it think I’m an idiot. 😛

If you want to start building your own bot personalities — grumpy Trolls, arrogant Elves, Dwarves too busy working to deal with your nonsense, or schizophrenic tinker gnomes — then feel to grab the GaitoBot app and start building personalities. The intent is to be able to load AIML files directly into the MUD and associate them with one or more mobs.

All I’ve done so far is generate some C# classes from the AIML schema, but that went smoothly enough. I’m not sure yet whether I’m going to build my own bot engine or use an existing open source one.

Visual C++ For C# Programmers

At my dayjob, I’m a C# developer. 2.5 years ago I was a C++ developer during the day. When I wrote C++, it was all for multiplatform applications that never touched any of the .NET libraries. When I switched to C#, it was all .NET. Never once did I try or even look into using any of the .NET libraries with C++. I knew there was something like __gcnew available, but I took one peek at managed C++ back in 2003 or so and got scared, running away because it looked so ugly.

I had heard that it was improved, but never bothered to look into it until now. I picked up a copy of Pro Visual C++ 2005 for C# Developers and in the first 50 pages I learned everything I need to know to be able to mix managed and unmanaged code in a C++ application, or to mix C# and C++ applications in a .NET project.  I’m not sure how much I’ll ever use that, since my main usage of C++ is for wxWidgets or Qt-based applications, but it’s nice to know, and the author, Dean Wills, did a damn fine job of explaining the differences between the two languages in a short amount of time.

The remainder of the book explains more of the intricacies and specifics, but any competent C# programmer can be writing C++ in only two hours with this book.