Code Bloat Thursday, Dec 27 2007 

I’ve read a recent rant of Steve Yegge about ‘Java bloat’ (; language wars will never end. There always be cool languages and old ones and programmers will always invent something new and what’s cool now will be old within a couple of years…

The idea is that Java is verbose so codebase grows quickly, then it becomes unmanageable and thus it’s better to use other more succinct languages. And so Java developers are doomed. 

First I thought: there are millions of Java developers – how could it happen that they are all wrong? Ok, there is a chicken and egg paradox: Language needs libraries to be usable and libraries have to be written by programmers that use the language. There are two ways to break it: create a superb language so there are enough impressed programmers to write libraries and made existing libraries available through wrappers or some clever hacks. Java was a superb language; it was C – pointers + garbage collection. Now there are so many libraries for Java so it just can’t die any time soon. ECMAScript has chosen the second path – it uses Java libraries. Plus it’s quite popular because it’s the language of web browsers. Other languages like Ruby and Python seem to be not so superb and so have no so many libraries; they have not yet grown out of this chicken and egg hole.

As Joel Spolsky noted twenty years ago it was enough to read C book from K&R to be a programmer. Now there are lots of technologies and APIs available; programmer should know much more. I can’t remember all classes and constants from JDK; even those that I used in my code vanish from my brain after a while. Eclipse API is huge too. The only way to stay productive is to be able to quickly find information you need and good IDE is an information retrieval tool! Why people use autocomplete feature? Not just because it’s faster to type code; you can quickly find a right class method or attribute. Eclipse even shows javadoc comment for the methods in autocomplete list. Another crucial feature is the type search: you can press a shortcut to bring ‘Find Type’ dialog and type part of the class name; in the list below you will see all matching classes and may open the one you need. I’ve noticed that I rarely read JDK documentation – it’s so much faster to just find the appropriate class! And of course source code navigation; put cursor on the class or method and press F3 to open it’s declaration, press Cmd+Shift+G to find all its usages. There lots of other things that allows you to discover the code and semantics behind it; people use Java because strong typing makes code discovery possible. From the dirt point of view languages with strong typing imply structured dirt like houses and bridges while languages without type system imply just piles of dirt.

Using smart features of the language won’t save you from the complexity. The only viable cure for quantity is abstraction; and this means only one thing – create and use DSLs. Now it’s really easy to spawn your own language: have a look at ANTLR, it will do all the routine job for you. There will never be a problem with your boss that insists on using Java; you may always hide your DSL in Java app as configuration files. And yes, it’s the ‘Interpreter’ design pattern; your boss likes GoF, isn’t he? 


UFO Friday, Dec 14 2007 

Most computer games exist only within a very limited period of time. As computer abilities grow new games with better graphics and more complicated AI take minds of the players. But some of them remain enjoyable for years and become the ‘cult’ games. One of such pearls is ‘UFO: Defense’ (also known as ‘UFO: Enemy Unknown’) and its sequel ‘UFO: Terror from the Deep’. Released in the very end of 1993 it featured pseudo-3D graphics in tactical mode and polygonal 3D globe in geoscape mode. I’m writing this in the very end of 2007 and I admit that I still play in this game occasionally and prefer it to many other modern games.

Searching for the ‘ufo game’ you’ll find a number of remakes, but none of them matches popularity of the original. The only good one is ‘Pocket UFO’ but it’s more of a clone for a pocket pc rather than a remake. So looking back over the 14 years of the game existence I’ve tried to capture what was so great about this game that made it such a success.

1. Two games that feel like one.

First is called ‘geoscape’ and it shows the Earth globe; you build bases, do research, earn money, hunt UFOs and manage equipment. Second is called ‘tactical’ and there you directly manipulate soldiers to eliminate aliens on terrain. The great thing about these sub-games is that they heavily influence each other. Weapons available in tactical mode should be bought or researched and produced in geoscape mode; if you arrive at the UFO crash site in the night it will be dark; aliens and artifacts captured in tactical mode influence research and income in geoscape mode. Most other games concentrate on tactical part and have only rudimentary support for exchanging weapons or carrying them to the next mission.

In other games I often feel myself quite disappointed when I can’t take all captured weapons with me to the base or to the next level; in one well-known game I can take as much as my soldiers can carry in their hands so in the end of each level there were piles of ammo and rifles and my soldiers took most valuable items from the piles – why not just take everything automatically as in UFO? Someone thought that it would be more realistic but in the end it hurts gameplay.

2. Diverse and well-balanced activities.

In a typical ‘strategy’ game user most of the time clicks on units to go somewhere and attack someone. Interest to the game is kept by giving user new landscape and new weapons. Such limited gameplay quickly becomes boring. The great thing about UFO is that there are many more developed activities – managing research, production, building bases, tracking expenses, hunting UFOs and so on. And what’s most important is that they all affect each other. The game allows to build organization where I handle all aspects of it’s existence; this gives me the feeling of control and this means satisfaction…

Example of balance is weapons system: there are three categories of firearms – conventional, laser and plasma. The first one is always available and you may buy everything any time but it’s not very powerful. So you use it at the beginning of the game. Laser weapons should be researched first and you may gradually shift to it. Plasma is the most powerful; it also should be researched but it should be captured from aliens first. So you use plasma weapons in the end and laser weapons turn out to be a dead end. But the top laser weapon – laser cannon – is the best item to produce! It gives the most income so it still makes sense to research it.

3. Atmosphere.

And this one is a hard thing to describe. I think that most of it comes from comics-style pictures and ufopedia (internal library of all available knowledge at the moment in a game). But other things like colour scheme and tragic music also influence the mood. Modern games that use animated 3D models look similar to each other; maybe just because they are not so dark…