Friday, August 14, 2009

Python, a little too permisive?

Also known as, why static typing can rock.

So today I was tracking down a subtle bug. It is a long standing one that we have been having trouble with and things were finally quiet enough to really start digging in. Here is the type of problem it ended up being.

Say you have a bit of python that looks like this:

ids = {foo,bar,baz,moop}
for id in ids:
fxn(id)

with fuction doing something like:

def fxn(id)
"""
@param id: id of thing we are working with
@type id: str or unicode
"""
somedict[id] = do_stuff

Now, this will all work find untill you do something like:

names = {foo,bar,baz,moo}
for name in names:
fxn(id)

Now, what just happened here? At some point someone went and edited the loop and changed a variable name in one place, but not another. 'id' in python is a build in function (gives you the memory address of the parameter), so no error is raised for unknown variable.

However, once we get inside fxn, there is nothing making sure that 'id' is, in fact, a string. Instead it is happily using it as the index for the dictionary.

The result you get is, instead of:

foo: foostuff
bar: barstuff
baz: bazstuff
moop: moopstuff

you get

: moopstuff

and of course any further use of the dictionary will be missing 3 elements and the 4th one is misnamed so you can not access it anyway.

the two basic problems here:

(1) Permissive overloading by wildly different types: id the function gets replaced by id the string and no errors (or even warning) are raised.
(2) Permissive passing of arbitrary data to functions: nothing stops to warn the user that the function expecting a string just got a function instead.

Now, of course there are ways to protect against this,... for instance what I did was:

assert(isinstance(id,str) or isinstance(id,unicode))

Which essentially reimplementation strong typing.

So yeah.... python's permissiveness is a really powerful tool, but wow can it catch you as a project ages and is maintained. That tends to be the problem with loose and agile technologies/methodologies.. they are great for throwaway stuff, but they become increasingly difficult to maintain and keep 'correct' as they age. This is a class of bug that even C/C++/ObjC would choke on and not let buy. And Ada probably would break your fingers to boot.

Saturday, August 8, 2009

C++ Concepts

I think after reading Bjarne Stroustrup's interview on concepts, I have reaffirmed by belief that C++ has become the wrong answer to pretty much any question.

The language just reeks of 'bored programmer syndrome'. More and more stuff added to it for the sake of expanding the language because using simple languages is 'boring'. C++ is crammed full of geek cred.. so many obscure features, strange interactions, special rules, etc. This is not a good thing for a language. A language should be quick and simple to learn with lots of useful APIs to use.

C++ on the other hand turns learning the language into a skill in and of itself. A bit like victorian erra protocol for dating. The complexity seems to exist purely so you can say you learned the complexity and thus show your aristocratic heritage. Meanwhile it did not actually change any of the actual abilities to date.

Social Networking Games.

Social network games are all the rage. For casual developers they are the next big thing. Or at least many seem to think so.

I am seeing a lot of casual games being shoe-horned to become 'social network' games. One of the ones I have been watching is Farm Town, which seems to be rather typical.

What these games seem to be focusing on is providing incentive to build up as large of social networks as possible. This is done though gatekeepers (i.e. certain functionality can not be turned on unless you have X friends in game) and gifting.

Both of these seem to be features for the sake of having features that can be called 'social'. The gatekeeper one is an especially shallow feature and does little more then either (a) keep people from features or (b) encourage the player to friend list a bunch of people for no reason.

The later, gifting, is a bit more clever and gives a real reward without actually preventing people from play. Still, the feature feels kinda hokey, something slapped on to make it 'social network compliant'.

This is a case where I am really not sure what a better solutions might be. It could be that the 'right' solution is none at all. Adding features for the sake of having them is not always a good thing.

An example of this would be Wii titles. For every title that has a good reason for motion control there are 5 that force motion control into the game just for the sake of having it. Generally when this has been done it has resulted in a title that does WORSE for it. For instance, DeBlob. Good game... if they had just dropped the motion control. It was not needed, added nothing, and detracted from the game.

Perhaps what social network games need is to stop trying to be social network games and start adding in social features as they truly extend playability.

I will be curious to see what CCP does with COSMOS. They are going the other direction, taking an existing game and adding a social layer to it from scratch. So building a social network site off a social game rather then building a social game off an existing site.

Time will tell.

Wednesday, August 5, 2009

CCP Case Study: On the problems of scale

Rambling a bit about someone else's upcoming difficulty.

EVE Online has a new feature in the works called Walking In Stations (WIS). It will actually be a backport of an engine they are developing for another game, specifically WhiteWolf's World of Darkness. The basic idea is that players will be able to get out of their ships and walk around as full bodied avatars in one of the stations in-game. It will not be an FPS, but instead something closer to second life.. you walk around, you talk, emote, and that is about it. They will probably expose some kind of store functionality, which really means taking the existing market controls and given them an agent front end. So no new gameplay. From the sounds of it, it will probably be very close in functionality to those virtual meetings packages that no one uses beyond the first two weeks, only with much prettier graphics.

Now, one of the problems they will probably encounter is one of the classic issues sci-fi games (and movies/tv) run into. What to do with scale.

Sci-Fi has a bad habit of making everything really really big. You see it in most movies/shows/games. There are even these wonderful image files out there that show how big things are in comparison to real world objects like famous building and air craft carriers. The usual result is that even small ships are bigger then the biggest thing we have built today because, well, big is really impressive and futury. But it poses a problem when you actually try to interact with it.

Agent or actor, at some point you have to create assets to present the viewer. If you are on a multi-mile long space dreadnaught that requires thousands of people and untold rooms and corridors, you somehow have to communicate this to the player. There are generally three ways to do this:

(1) Lots of repetitive auto generated content. Got 100km of corridors? Let the player walk around 100km of corridors. They all look the same and the only real cost is changing the {x,y,z} coordinate of the avatar. Add nearly identical shops every once in a while and backfill with NPCs, ideally with lots of canned dialog and motion to give the illusion of a bustling metropolis. This is generally the approach that sandbox games take (with varying degrees of custom content depending on your art budget).

(2) Limit the player's motion and include lots of huge background images and occasional giant rooms. Sure you only have two rooms for all the players, but look out the window at that immense city scape! This lets you concentrate your assets in a small area and make them fairly rich. It also allows you to concentrate your players in a small area so they interact with each other, minimizing the need for NPC clutter.

(3) Let players create content. This takes elements form (1), specifically lots of blank real-estate and (2) players concentrating assets into 'switched on' areas. Second Life does this to significant success. This lets the players participate, fills the space potentially with LOTS of content, but takes artistic control away from the company which CCP might not like.

Now, what could CCP do? (3) is unlikely. They will not even allow players to add aesthetic structures to POSes (Player Owned Starbase)(which NPCs do all the time, resulting in really cool looking places to visit or mission in), so if they will not allow that then i can not see them releasing artistic control on this level. (1) is unlikely due to, well, CCP built a huge universe including thousands of stations that are probably hundreds of cubic kilometers each.

My guess is that they will do (2). Probably some type of tram-system where you can go between multiple disconnected locations, each with a fairly rich (but identical between different stations) area that players can wander between. Both the tram and the rooms will likely have awe-inspiring vistas that can not be interacted with. They will probably consider connecting areas like hallways or malls but drop them as they run into scale issues. One of the problems is that stations can have either a handful of people (0-5) or hundreds at a time (Jita might have 1000+ people in it for instance) and thus any solution they put together will have to support either extreme without making these huge stations feel empty or cluttered.. since 0-1000 player avatars SHOULD be little more then a drop in the bucket.

How would I have approached it? I admit, I am a big proponent of (3), but I don't care about artistic control too much. I also would have made stations (and ships) fairly small things, with the idea that space is big and cold and lonely.