<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Programming in the 21st Century</title>
<link rel="self" href="http://prog21.dadgum.com/atom.xml"/>
<link rel="alternate" href="http://prog21.dadgum.com/"/>
<id>http://prog21.dadgum.com/</id>
<updated>2012-05-08T00:00:00-06:00</updated>
<entry>
<title>You, Too, Can Be on the Cutting Edge of Functional Programming Research</title>
<link rel="alternate" type="text/html" href="http://prog21.dadgum.com/138.html"/>
<id>http://prog21.dadgum.com/138.html</id>
<published>2012-05-08T00:00:00-06:00</published>
<updated>2012-05-08T00:00:00-06:00</updated>
<author><name>James Hague</name></author>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">In 1999 I earned $200 writing an essay titled <a href="http://www.gamasutra.com/view/feature/3367/toward_programmer_interactivity_.php">Toward Programmer Interactivity: Writing Games in Modern Programming Languages</a>. It was an early, optimistic exploration of writing commercial games in Haskell, ML, and Lisp.
<br/><br/>It was not a good article.
<br/><br/>It's empty in the way that so many other "Hey everyone! Functional programming! Yeah!" essays are. I demonstrated the beauty of Haskell in the small, but I didn't offer any solutions for how to write state-heavy games in it. There are a few silly errors in the sample code, too.
<br/><br/>Occasionally during the following years, I searched for information about writing games in functional languages, and that article kept coming up. Other interesting references turned up too, like papers on Functional Reactive Programming, but apparently I had accidentally become an authority. An authority who knew almost nothing about the subject.
<br/><br/>I still didn't know if a mostly-functional style would scale-up past the usual toy examples. I didn't know how to build even a simple game without destructive assignment. I wasn't sure if there were even any legitimate benefits. Was this a better way of implementing game ideas than the usual tangled web of imperative code--or madness?
<br/><br/>As an experiment, I decided to port an action game that I wrote in 1997 to mostly-pure Erlang. It wasn't a toy, but a full-featured game chock full of detail and special cases. I never finished the port, but I had the bulk of the game playable and running smoothly, and except for a list of special cases that I could write on a "Hello! My Name is" label, it was purely functional. I wrote about what I learned in <a href="http://prog21.dadgum.com/23.html">Purely Functional Retrogames</a>.
<br/><br/>Now when I search for info about writing games in a functional style, <i>that's</i> what I find.
<br/><br/>Sure, there are some other sources out there. Several times a year a new, exuberant "Haskell / ML / Erlang is a perfect match for games!" blog entry appears. Functional Reactive Programming keeps evolving. A couple of people have slogged through similar territory and managed to bang-out real games in Haskell (<a href="http://raincat.bysusanlin.com/">Raincat</a> is a good example).
<br/><br/>If you want to be on the cutting edge of functional programming research, it's easy. Pick something that looks like a poor match for state-free code, like a video game, and start working on it. Try to avoid going for the imperative pressure release valves too quickly. At some point you're going to need them, but make sure you're not simply falling back on old habits. Keep at it, and it won't be long before you're inventing solutions to problems no one else has had to deal with.
<br/><br/>If you come up with something interesting, I'd like to hear about it.
<br/><br/>(If you liked this, you might enjoy <a href="http://prog21.dadgum.com/18.html">Back to the Basics of Functional Programming</a>.)
</div></content>
</entry>
<entry>
<title>The Most Important Decisions are Non-Technical</title>
<link rel="alternate" type="text/html" href="http://prog21.dadgum.com/137.html"/>
<id>http://prog21.dadgum.com/137.html</id>
<published>2012-05-06T00:00:00-06:00</published>
<updated>2012-05-06T00:00:00-06:00</updated>
<author><name>James Hague</name></author>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">I occasionally get puzzled questions about a <a href="http://prog21.dadgum.com/57.html">parenthetical remark</a> I made in 2010: that I no longer program for a living. It's true. I haven't been a full-time programmer since 2003. The short version of these questions is "Why?" The longer version is "Wait, you've got a super technical programming blog and you seem to know all this stuff, but you don't want to work as a programmer?"
<br/><br/>The answer to both of these is that I realized that the most important decisions are non-technical. That's a bare and bold statement, so let me explain.
<br/><br/>In the summer of 1993, I answered a newspaper ad looking for a "6502 hacker" (which I thought was amusing; the Pentium was released that same year) and got a job with a small company near Seattle writing Super Nintendo games. I had done game development prior to that, but it was me working by myself in my parents' living room.
<br/><br/>The first SNES game I worked on was a Tarzan-themed platformer authorized by the estate of <a href="http://en.wikipedia.org/wiki/Edgar_Rice_Burroughs">Edgar Rice Burroughs</a> (it had no connection to the Disney movie, which was still six years in the future). I had fun working out ways of getting tropical fish to move in schools and creating behaviors for jungle animals like monkeys and birds. It was a great place to work, with the ten or so console programmers all sharing one big space.
<br/><br/>The only problem was that the game was clearly going to be awful. It was a jumble of platformer clich&#233;s, and it wasn't fun. All the code tweaking and optimization and monkey behavior improvements weren't going to change that. To truly fix it required a project-level rethink of why were building it in the first place. As a "6502 hacker" I wasn't in a position to make those decisions.
<br/><br/>While it's fun to discuss whether an application should be implemented in Ruby or Clojure, to write beautiful and succinct code, to see how far purely functional programming can be taken, these are all secondary to defining the user experience, to designing a comfortable interface, to keeping things simple and understandable, to making sure you're building something that's actually usable by the people you're designing it for. Those are more important decisions.
<br/><br/>Whatever happened to that Tarzan game? Even though it had been previewed in <i>Nintendo Power</i>, the publisher wisely chose to pay for the year of development and shelve the finished project.
</div></content>
</entry>
<entry>
<title>A Forgotten Principle of Compiler Design</title>
<link rel="alternate" type="text/html" href="http://prog21.dadgum.com/136.html"/>
<id>http://prog21.dadgum.com/136.html</id>
<published>2012-04-25T00:00:00-06:00</published>
<updated>2012-04-25T00:00:00-06:00</updated>
<author><name>James Hague</name></author>
<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml">That a clean system for separately compiled modules appeared in Modula-2, a programming language designed by Niklaus Wirth in 1978, but not in the 2011 C++ standard...hmmm, no further comment needed. But the successor to Modula-2, Oberon, is even more interesting.
<br/><br/>With Oberon, Wirth <i>removed</i> features from Modula-2 while making a few careful additions. It was a smaller language overall. Excepting the extreme minimalism of Forth, this is the first language I'm aware of where simplicity of the implementation was a concern. For example, nested modules were rarely used in Modula-2, but they were disproportionately complex to compile, so they were taken out of Oberon.
<br/><br/>That simplicity carried over to optimizations performed by the compiler. Here's <a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.39.9965">Michael Franz</a>:
<blockquote>Optimizing compilers tend to be much larger and much slower than their straightforward counterparts. Their designers usually do not follow Oberon's maxim of making things "as simple as possible", but are inclined to completely disregard cost (in terms of compiler size, compilation speed, and maintainability) in favor of code-quality benefits that often turn out to be relatively marginal. Trying to make an optimizing compiler as simple as possible and yet as powerful as necessary requires, before all else, a measurement standard, by which both simplicity and power can be judged.
<br/><br/>For a compiler that is written in the language it compiles, two such standards are easily found by considering first the time required for self-compilation, and then the size of the resulting object program. With the help of these benchmarks, one may pit simplicity against power, requiring that every new capability added to the compiler "pays its own way" by creating more benefit than cost on account of at least one of the measures.
</blockquote>The principle is "compiler optimizations should pay for themselves."
<br/><br/>Clearly it's not perfect (the Oberon compiler doesn't make heavy use of floating point math, for example, so floating point optimizations may not speed it up or make it smaller), but I like the spirit of it.
<br/><br/>(If you liked this, you might enjoy <a href="http://prog21.dadgum.com/114.html">Papers from the Lost Culture of Array Languages</a>.)
</div></content>
</entry>
</feed>
