Thursday, July 29, 2010

Steam

I've been singing the virtues of Steam for a while now. Lots of people find it very intimidating as a service but I've just been doing some quick mathematics and have confirmed to myself *why* I use it, even with it's known "disadvantages" (Most people's complaint is the "DRM" - Steam is the only DRM that I actually tolerate, it's so reasonable, and why people get out of their pram over other people knowingly and willingly buying into Steam, I have no idea).

My Steam account started in 2003 from a Half Life "Generations" pack (actually 2, one each for myself and my brother) that we'd been playing for years before Steam even existed. When WON died, we were forced to move onto Steam, and it generated a lot of bad feeling back then.  Over time I slowly added games until my current situation where I have 141 games on my Steam account.

I went through the history of the account recently and worked out that I'd spent almost exactly £400 (not including the initial cost of the Generations Pack). Doing some quick mathematics on the exact figures, I worked out that my Steam account had cost me approximately £1.11 a week since I'd started it. That's £1.11 of my money, when I choose, spent how I like, when it's convenient to me.  There is no game-rental service that can even come CLOSE to that, and I "own" these games forever (as much as anyone "owns" a copyrighted work).

For that price, I got nearly 150 games, of which, say, half a dozen were completely free and another half a dozen were freebie crap thrown in with other purchases that I wouldn't have bought but ended up with because they were free. That's £2.83 per game, and I apparently bought a game every 2-3 weeks on average over those years.

There were several times when I just did not have the money to buy the game I really wanted, or the one that I'd been waiting to be on a "weekend special" for years, so I actually paid more than I needed to in order to own what's on my Steam account now. I also ended up buying some games a couple of times over - sadly they weren't ones that would credit my Steam Gifts, so I couldn't give them to other people and they were "lost" purchases. I can remember one game that I bought and the next week bought again because it was in a ridiculously cheap bundle with lots of other good games that wasn't available the previous week.

So, how many hours entertainment have I got out of this Steam account? I have no idea. I can only go by recorded statistics which were added to Steam quite recently. That shows that I got 519 hours of recorded gameplay since they started recording. This, of course, is not spread evenly over all the year but also doesn't contain several thousand hours from the half-a-dozen years that Steam did not record such statistics. If I had to estimate *actual* game time on Steam alone, it would be at least 4-5 times that figure. Hell, my Counterstrike:Condition Zero stat alone would probably show more than 519 hours of gameplay.

So, what's that in terms of value - Well, I can easily say that with that huge choice of games available at the click of a button, I waste no time with crap games and only play those that I find entertaining.  Some games have literally never been installed on my computer, others have never left it even when I was trying to find a few hundred extra MB's of space. Altitude has already knocked up over 100 hours of gameplay and that's only been released relatively recently. According to Steam, I've played 16 hours of games in the last two weeks - an hour per day, or thereabouts. Assume that's the same since I had the account (and that sounds a very reasonable estimate) - that's 2500 hours at least since I started - which is marvellously in line with my 4-5 times estimate.  So let's say I got about 2500 hours of playtime out of 141 games for £400 since I started my account in 2003.

So how much did this entertainment cost me per hour? £0.16p. Let's compare that to some other leisure activities:

World of Warcraft: £8.99 for a month's subscription.  Assuming you only ever wanted to play that game, with my same usage (about 7 hours a week) that would be £0.32p per hour.  Close, but that's still double the price of my Steam account, and only on a single game (albeit an MMORPG).

A cinema ticket: £9.80 for a basic seat in my local cinema, during their quietest time to see a just-released, non-3D, 140 minute movie - £4.20 per hour. One-off and can't watch again without paying.

A DVD: £9.99 for a just-released DVD of a 102 minute movie from Amazon - £5.87 per hour (but arguably the same price as the cinema on average). I can keep watching that over and over as much as I want, though.

A Blu-ray: £15.93 for the same movie - £9.37 per hour (assuming I had the equipment to play it).  Again, I can keep watching that over and over as much as I want.

Paintballing: £9.99 per person for a full day (7 hours) - £1.42 per hour assuming I could find enough people also willing to pay that.  A one-off event.

Abseiling or caving: £18 per person for a three-hour session - £6 per hour.  A one-off event.

Pottery course: £143 for a 15-week course (two hours per week) - £4.76 per hour.  A one-off event.


Now, you can argue that similar activities are probably more exciting or more worthwhile, that I gain knowledge / skills, that I interact with people more, etc. And, great, that's good and I obviously do some or most of the above anyway.  But if you're a gamer, it's undeniable that you're getting lots of good value for money there compared to some other similar "time-wasting" activities that you could do to fill up a slow Sunday afternoon.  16p / hour is a fabulous price for myself to pay - I can't find anything else that I really get that much entertainment out of for such a cheap price, and I *have* had to be dragged away from the computer by partners in the past.

The reasons for the value gained, of course, are many.

1) Steam give some good bundles and discounts. Even if you don't include their regular "Free Weekends" of various games, they often have astounding weekend deals like a bundle of modern, big-name games for £10 that were selling for £50 in the shops.

2) You can choose what you buy and when - which obviously biases it to your exact tastes. Don't have a game to fit that hour of spare time, or for your little brat of a cousin to play when he comes round? You can probably find something in Steam's Under £4 or Under £7 categories. Strangely, they're the only pricing categories available at a single click and yet £7 wouldn't even get you a budget game in most video game stores.  The range of games is huge, too, and virtually every genre is covered.

3) The pricing is immediate, sometimes short-lived, the purchase goes through instantly, the download starts immediately after, you don't have to configure or install things - 99.9% of stuff will "just work" after you click download and double-click the game - and so impulse-buying is a big factor. Steam is probably the only program that I allow to "keep me informed" of new releases. I abhor advertising and have learned to ignore but, actually, the Steam deals are worth looking at quite a large amount of the time.  Hell, some of the games I already owned, I bought the steam version so that I could install them conveniently.

4) Freebies. If you have an ATI graphics card, you get a freebie. If you have an NVidia graphics card, you get a freebie. If you just hunt down some forum posts you can get free games entirely legitimately (http://forums.steampowered.com/forums/showthread.php?t=851573) - Alien Swarm is the latest one, and Valve made a big fuss of advertising that *everyone* can get it for free, but there are lots of other good games there. And that's before you even look at the demo's of existing games that are available, or the numerous free Steam Mods if you have the Orange Box.  Let's not forget - Steam is free to own and there's a dozen or so free games on those lists.  They may not be brilliant (but Peggle Extreme made me buy Peggle, the HL-based mods available are out of this world, and TrackMania Nations will make you lose time like there's no tomorrow - and made me buy TrackMania United) but they are good enough, and they are free.

5) The extras - you can move your Steam account to any PC you own (or don't!) and download the games and play them.  Most games will even carry over your settings and savegames too.  You can even shift quite a lot of stuff onto a Mac.  So long as you don't try to run your account on two computers at the same time, you can install it and play it wherever you like and get all the games you've purchased (or been given as freebies, or as gifts from Steam friends).  Most games have achievements, rankings, stats so you can find a reason for even that brief five-minute game just before dinner ("Hold on, darling, I just need to kill two more people with a grenade and I've got all my achievements for this game").

Steam is undeniably good value.  Maybe not for every single individual gamer on the planet but I can't deny that I've more than had my money's worth out of the games on it.  The only other thing that comes close was GOG.com (Good Old Games) which sell DOSBox-wrapped and other older games for about $4.99 each.  So do Steam sell those sorts of games, though.  And they also sell top-of-the-line, pre-release, etc. games that need a huge stonking PC to run them.

To me, Steam is one of the best game-purchasing methods out there.  It makes me want to add games to my account, it makes me want to play the vast majority of the games that I've put on there, it makes it easy and simple to play them and it costs me less than 16p for every hour that I choose to play.  If I had more time, had no life, were interested in more games, I could easily spend a lifetime on there and, even with every Steam game added to my account, still get the value down to about 10-15p per hour.  There are other costs, of course, but they are incidental to my usage of Steam anyway - Internet bandwidth, PC cost, hard disk space, etc.

It's truly ridiculous to then look at such "new" competitors as OnLive who are demanding the same game prices (and it looks like they just photocopied a portion of the list of Steam games), plus a monthly rental, plus you supplying roughly the same hardware but 10 times the Internet bandwidth.  Or a video game rental store.  Or purchases from a video game store.  Or most of the download-software stores.

Steam truly is remarkable value.  I gain nothing by saying so, but hell - the best £400 I've ever spent.  I know some people who could burn through that amount in a month's, let alone seven year's, worth of gaming.

Monday, April 12, 2010

Copyright, and the UK's Digital Bills to clamp down on my viewing habits

Just been reading The Register's article on the Digital Economy Act. Thought it was finally time for a bit of a rant...

The way forward is, was and always has been encryption. It just wasn't needed at any point in the past because the chances of being caught, the implications of being caught and the mass of possible defences made it a non-issue to be caught. Tor exists and does a pretty damn good job at stopping people knowing who you are. It's just that nobody has bothered to integrate such facility into a popular file-sharing protocol that's widely used because, to be honest, it hasn't been needed. When the necessity arises (and such a Bill being implemented in such a way *in real life* and not just in a politician's head would be that point), encryption destroys all the chances of monitoring such activity.

But "Piracy" as a concept isn't something that will die easily because it's mainstream and solves many mainstream problems much more effectively than anything else available.

The piracy problem, as thus stated, won't be solved by "looking for" people doing it. The record industries did that with a group of individuals and most of them either ignored their demands, provided a reasonable defence, cost too much to convict or when the record companies took them to court they made enough of an argument to stop things happening. Literally only a handful of cases ever made court, maybe a lot more were settled out of court, and still it's a tiny, tiny, drop in the piracy ocean (with maybe a handful less grannies and 10-year-olds downloading songs because they "got caught").

When you look for people, you only find those that *want* to be found or that aren't taking care not to be found. The people who are the real problem (the warez groups, the industry insiders providing pre-release movies, etc.) very, very rarely ever get traced back and hardly ever face any sort of sanction. Who gets stung? The people trying to view the content they would like to see. And those same people 99.9999% of the time have a reasonable defence, whether the government likes that or not (and, no, I don't consider "I'm pirating out of protest" to be a defence - but something like "I own it on DVD and wanted to watch it on my foreign DVD player" I consider pretty reasonable).

Of course, there is an obligation to uphold the laws but the fact that piracy is *so* prevalent, so tricky to define, can be made *so* hard to track / prove by the simple step of running, say, TOR, can be understood and performed by uneducated users, and provides material that just isn't available any more means that's it's not going to be pushed underground quietly.

It's almost a service now. And the problem is that the whole piracy thing goes ten million times deeper than "kids posting MP3's online". Let me give you some real-world examples that have occurred since only the beginning of the year (so only 3-months or so).

I was on a trip around Europe with some friends. We wanted music to play in the car. I don't buy, download or otherwise listen to music (the only CD I have ever personally owned was Jive Bunny and that was because someone bought it for me to go with a CD player they'd bought me, which never got used) but my passengers insisted on having something. They copied the tracks from their iPod to an SD card and we played it in the car (the fact that I have only a tape-player and that we had to use an SD-to-tape adaptor should tell you how often I listen to music).

Technically, I'm not even sure if that's legal or not. Is that "broadcasting"? Is that distribution? Should I be required to report my friend? Did my friend pay for the track originally? My friend is Australian - does that mean she might have contravened international laws and/or license restrictions on her purchased music? I have no idea whatsoever, and the SD card got wiped because I needed it for my digital camera. To the layman, we were just playing some music in the car, the same music we hear on the radio for free but without the annoying guys talking over it or stupid "customisations" of songs (we heard Capital's version of Kesha's Tik Tok which had a ten-second intro "sung" especially for Capital... it just made us laugh).

I was talking to my girlfriend about an advert that used to be on TV. She's foreign and had never seen it. I found it on YouTube, in what looked like a recording from an old videotape. Is that copyright infringement? Should I have reported it? Does the company that made the squirrel-assault-course ad for Carling Black Label care, or are they grateful for the publicity? How long would it take to find all the rights-holders for that 30-second clip and ask their permission? Was Youtube broadcasting it in contravention of international / UK law and/or was I doing so in showing my girlfriend?

I wanted to show her Button Moon, Count Duckula, Trap Door and Dangermouse. I have a load of episodes of each on DVD (not to mention the complete set of Batfink and Dungeons & Dragons cartoons) and the DVD's were in the room next to me. Time how long it takes to hunt a disc, remove from box, insert it into laptop, set up the DVD software, wait for the disk to spin up, etc. It was ten times quicker to go on Youtube and show her them. Was that wrong? Does the average person understand that stuff on Youtube may not be there legally? How does that mesh with content-holders who post *all* of their stuff legitimately on Youtube? Does the rights-holder for some of that material even exist any more? I have no idea. Technically, Happy Birthday is only licensed legitimately if you pay money to a corporation... how many average people even *KNOW* this let alone care, let alone would bother to report themselves, let alone pay, let alone want to sing it if they had to pay for it? It's no excuse, the law is the law, but the law sometimes make an ass of itself by painting itself into a logical corner filled with nonsense and then realising its mistake only decades later.

The same girlfriend had never seen The Good Life, and I wanted to show her. I have the complete set of DVD's at home with every episode ever made, but they were about 3000 miles away. I couldn't find anything but clips online except on torrent sites, and we were having a quiet evening in and wanted something to watch. I downloaded the torrent. It took three clicks, 20 minutes and less than a Gig of disk space and I had every episode. We watched them. Is that illegal? Is it immoral? Did the BBC suffer through my actions? The program is over 30 years old now, are the BBC still making money from it, or relying on it to generate revenue for them, or expecting it to do so indefinitely?

The same girlfriend also loves QI. We have all the books and DVD's. We watch one or two every night, along with things like Have I Got News for You or Whose Line is it Anyway. We were abroad, though, and didn't want to miss the latest one, but I couldn't access it. I used a UK proxy and get_iplayer and after about 5 minutes had a copy sitting on the hard drive. I was very, very careful not to download it while it was being broadcast because that would be illegal because I don't have a TV licence at home (no TV's!) and I knew I was bypassing the BBC's protections already. I knew my actions would be traceable but I didn't really care about the temporary storage and later viewing of that episode, though, only the TV license. I have quite a good knowledge of copyright law, but even I know that's still a grey-area and I still "take the risk". How does the same situation translate to a layman?

I've religiously bought every one of the QI DVD's and ripped them to my laptop (our primary viewing apparatus) for convenience - the DVD's occupy a coveted and well-guarded section of my DVD-shelf and would just add to my baggage allowance. Have I broken DMCA-type-laws by downloading them illicitly, or by decrypting the DVD, or transporting them to regions they aren't licensed for? Am I hurting content producers? If I let my girlfriend's family watch the episode with us (they don't speak English anyway, but hypothetically), is that illegal? I have *absolutely* no idea.

We both love Whose Line Is It Anyway and love the fact that 4od has them all online. We're slowly working our way backwards (the early series were crap) through them all. I used a proxy to do this from a foreign country after reading the following snippet from their FAQ:

"Can I watch 4oD in another country?
Rights agreements mean that our 4oD service is only available in the UK and the Republic of Ireland, (although C4 does not always have rights for programmes in ROI). Even if you are a citizen of the UK or ROI you cannot access the service from abroad"

It was easier to leave a program running on a computer left at home because I *know* I'm English and that if I was at home, I could watch them. I have lots of the DVD's but they don't really have the complete set available in a simple fashion (it's lots of old VCR compilation-tapes and things to get *every* episode, I believe). We even looked for a way to buy/download the episode quickly online, hoping that a British-registered card would allow us to download them even abroad. No chance, according to Wikipedia:

"A Download to Own (DTO) or "Buy" feature was once available on selected content, allowing users to purchase a programme and keep it for as long as they wish. This service has now been suspended..."

But now all their programmes are available for free on 4od or (some) on Youtube. So we went via a proxy (read: my home broadband connection) and we suffer the 20-seconds of ad's quite gladly because they are reasonable (like ad's on TV used to be). They get an extra viewer of their ads and content (which is what their entire business model is based on, I assume, being a TV channel?) and we got the episodes we wanted to watch without too much hassle. Did I break the law? Have I harmed Channel 4 by watching these programs that haven't been filmed for about 20 years with some adverts in them, bypassing their "region protection"?

My ex is a big, big fan of Just Good Friends (remember that?). I bought her Series 1 and 2 from Amazon and we were waiting for Series 3 to come out. Every time the date given approached (even with industry blogs saying dates, and Amazon pre-order dates, etc.) it would slip. Eventually they gave up giving dates and still now, five years later, you can't buy it. It's assumed that it's because of music-licensing rights to some of the music playing on the jukeboxes in the background in the pub and various minor things like that. Have I destroyed Ronnie Hazlehurst's life by downloading that last series so we can finally watch it after about 30 years since it's original broadcast, and five years of waiting for a DVD to come out? Do you really think that a person who's waited that long *wouldn't* buy the DVD if it were to come out tomorrow, just to complete their collection? You can't gift DVD-R's with some torrented AVI's on them - it's not the same. Incidentally - anyone ever seen "The Two Of Us" with Nicholas Lyndhurst available for sale *anywhere* on any format? Me neither. But if I found a torrent, I'd want to see it again. But EVEN THEN, if a DVD was released, I can name at least five people it would make a good present for (myself included!).

My girlfriend's father is a big WW1 fanatic. He has a huge collection of memorabilia and regularly goes metal-detecting in the mountains to get more. I wanted to show him Blackadder, series 4, which is set in the trenches. He doesn't speak English so he can't "watch" it but I had a quick look for it online in case there were Italian subtitles available. I didn't find any (if anyone knows of some, please do tell) but I did find the entire Blackadder, all series, available for streaming from some random website. Almost certainly illegal. Did it really hurt anyone to show him a brief few seconds and explain the jokes and let him look at the set, uniforms, etc. to see if they were accurate? If I could have found some Italian subtitled DVD's, I'd have bought them but would it be a big deal to show him an episode with Internet-posted subtitles so he could see if he'd enjoy it? Are the sites that host foreign subtitles to things like that breaking the law?

Since New Year, I've paid about £200 and downloaded dozens of games for that money from GOG.com and Steam. It's said that Steam uses a Bittorrent derivative to download games quickly to my hard drive (they employed Bram Cohen, author of Bittorrent). All I know is that I click a button, enter my card details and in about ten minutes I have a game on my hard drive. The protocol, then, isn't illegal so it's an enormous job to distinguish legitimate downloading from piracy. Ever Linux distro I've ever used has a Bittorrent download too. I'd hate to go back to the days of HTTP / FTP downloading a 4Gb ISO.

I've been in schools that like to show DVDs to kids at the end of the year (on their "fun days"). I have absolutely no idea about the legality of that at all (I'm pretty sure that's broadcasting). I know that the music teachers have to tick a sheet saying which hymns they've sung that year in assembly so they can be charged for them (ask your child's school - it's pretty universal and quite expensive apparently). I don't think Disney do the same but they would certainly do it if the school would pay. I've also seen people copying tapes of educational programmes (that they have bought legitimately several years ago) that are no longer broadcast onto a DVD so they can play them on the modern projectors through their laptops. Is that illegal? I have no clue at all. What about kids going on Google Images and copying/pasting an image into a Word doc? Stupid, from a filtering point of view, yes, but almost all schools do this. Is that infringement?

So, with all the DVD's I've bought and can't use in the quite reasonable way that I want without (potentially, theoretically and only "possibly") breaking the law, with all the money I've spent online for various games, books, movies, etc., with all the stuff I have on my Amazon wishlist (if it even exists online) and want to buy, with all the content I want to absorb each night, I've somehow played my part in destroying the market and should be monitored, penalised and even taken to court?

The average person just can't see sense in that at all. And so the average person just doesn't *care* about piracy, because they've probably done it inadvertantly dozens of times in the past year. Did you publically perform Happy Birthday this year? Have you photocopied pages from a book? Did you put your music from your CD's onto your iPod? Have you watched YouTube clips?

When a law become ridiculous, it gets ignored. Eventually it gets removed from the statute books because it was worthless, stupid, unenforced and ignored. That's the way such "laws" were heading and these Bills only put a blip in that death-curve. Taxi drivers don't need to keep straw in their boot any longer, because it's irrelevant, outdated, nonsensical and pointless. But for many years, that law persisted even into the era of the motor vehicle. Copyright laws are in the same position, but this time we're not moving from horses to cars, we're moving from traditional media to the Internet.

I don't really care about the TV/movie/music industries. As far as I'm concerned they should make money where they can and if they can't, they should pull out of that market, the same as every other business. The fact is, though, that the only legitimate sites I've ever used are BBC iPlayer, 4od, ITV Player (since the stupid Silverlight requirement was scrapped) and similar. I get the content I can on DVD (because it's the least evil digital method, not because it's perfect) and even go to the extent of buying things on video from bootsales so that my digital content is "legitimate". And even my uses of those sites / media are potentially infringing under certain interpretations. I try hard to stay within the law, but the fact is that staying within the law while performing some quite harmless actions is hard - thus it's a bad law.

There's a point where a reasonable person has to make a choice - (potentially) break a (badly-written, outdated, irrelevant and relatively untested) law or stop consuming certain media. The problem is that piracy measures *don't* add a third choice, they just force you to make a choice between those two even more quickly and decisively. I gave up my TV licence because it wasn't value for money. When "piracy" becomes "criminal", then I have to make another choice - continuing consuming that media (potentially against the law) or take up mountaineering, learn Italian, play board games, etc. Neither of those options help the content makers, but they are precisely the ones forcing me to make that decision.

You know what? I'd rather buy second-hand tapes and DVD's at a boot sale of 30-year-old programs that they don't show any more and keep an old VCR running (and risk potential legal action) than use the other legitimate options available to me. That has to say *something* to the media industries surely?

Please, please get real. Come into the land of the sane. It's nice there, honestly. A £1 / episode download link on iPlayer / 4od / etc., a "Buy the DVD" option for just about everything in your archives. Stop pissing all the money I'm giving you away on trying to criminalise my quite reasonable actions to watch YOUR content that I enjoy. It's a nonsense, and the sooner you force me to make that decision the better.

Thursday, June 05, 2008

Hobbyist programming advice

I've programmed quite a bit, in a variety of languages, for work, for fun and for learning. Quite often, I've chosen how I do it and the other times it's been dictated but I've found that I program to a set of rules unconsciously. These mostly apply to "hobby" coding (games, utilities, etc. that you are mostly making for yourself) but can also apply to school or work if you have flexible working regimes:

1) Program in whatever language you like.

Honestly. It really doesn't matter for "casual" use. Don't program in C just because everyone else is, or because you've heard that it's better. Program in a language that you're comfortable with, even if that's BASIC and people tell you it's rubbish. You're the programmer, you should work to what you know. If you want to learn new languages, do so, but don't write every project in the current-fad language just because.

This also means that if you are confident in several languages, you should program in the most appropriate or your favourite language. It doesn't matter which! The most appropriate will make things easier (e.g. using something like Perl for handling a lot of text, or using Java for an object-oriented idea) but your favourite is likely to be the one you know best and you can make it do whatever handstands you need it to despite its shortcomings.

If someone tells you that you should start a program in C because you might need the performance later, test their theory first. Knock up a worst-case in your favourite language and see if it's worth the effort of learning a new language or coding in an unfamiliar one before you start. Chances are, for most things, just about any language will do.

There's nothing worse than being told that you "should" be programming in C when you're knocking up a twenty-line batch file (yes, batch files are programming, of a sort!). However, knowing whether you want an interpreted vs compiled language can be a help when you start - the chances are that it won't matter though.

2) Ignore coding style.

If you're writing for yourself, you can ignore supposed "best" coding styles and work your own way. Even if you're working as part of a small team what matters is clarity. Whether you space or double-space or crunch your arguments together with their commas doesn't matter so long as it can be read and understood. Stylising the code can come later if it's necessary. And if you're the only person to ever read it, it doesn't matter that people aren't used to your coding style.

I would argue that programming teams should have a system where they all use their own coding styles and have "convertors" so that when they put code back into the global pool, the style gets modified to the "team" style and when they check it out, it gets customised to that particular programmer's style. This way, everyone works comfortably but the central repository stays consistent.

If you're a single developer, spending too much time on worrying about the style wastes the "programming mood". You could write a thousand lines of new code with new features in the time it takes to style your code.

3) Document the code.

Documenting your code is important, even for yourself. You will not get to the end of any significant project and remember why every line is in there or how they all work. But you don't need flow-charts, invariant lists, hundred-pages of specification and all the other rubbish that programmers are taught to do if you're just working for yourself.

A simple comment above each block of code is more than sufficient but what's ABSOLUTELY necessary are warnings to yourself:


REM Don't remove this, because the program crashes without it.

// Don't pass different flags here because they are ignored.

;This line isn't redundant, it's deliberate. Without it X happens.

/* I know it's already supposed to be initialised but
without this, it can pass uninitialiased through
the compiler unnoticed and cause problems.*/


For big projects, you might find a brief Changelog and a Todo come in handy, but everything else should be inside the actual code. It takes long enough to write user documentation without having to document every single thing you do for yourself.

4) Backup

Yes, I know, but you really need to, especially if you're programming. Programs can crash, file accesses can run amok, source code will be heavily edited to fix a basic problem that you'll track down to something else, etc. Ideally make a copy of files you intend to change just before you start a session, and after any major breakthough (which may be as simple as finding the 1-character cause of a serious bug... you will kick yourself if you forget which of the hundred lines that mention "variableX" it was on and have to go through hours of debugging to find it again).

Regularly copy those files to other computers, or a website somewhere. SVN and other source code management programs are useful for this if you do it often but even just a simple ZIP and upload is better than nothing. THIS INCLUDES MAKEFILES AND COMPILE SCRIPTS!

I work on the following basis: At the start of a session, I backup the files I'm likely to change the most (e.g. graphics.c if I'm planning on revamping the graphics), to a dated copy in the same folder (e.g. graphics-2008-01-01.c). If I make significant advances (add a new feature, fix an old bug, etc.), I will copy that file again to the same folder (e.g. graphics-2008-01-01-added-double-buffering.c). At the end of a particular session, I copy all changed files to an SVN folder, which I may or may not decide to "commit" to a remote website. Every time I think I've made enough advances to see that the program obviously works differently, or which would be a real pain to replicate, I copy them to a couple of personal websites/SVN repositories.

Even few months or so, backup all that stuff to a CD-R or something. You'll be glad of it in a few years time. "I used to have code that did something similar, let me dig it out for you", etc.

5) Develop on a slow PC.

Seriously. Find an old junker, a laptop if possible because programming is one of those "I'm in the mood" hobbies that can take you any time and it's a shame to waste it. Don't make it so ridiculously bad that you can't use it comfortably, but a machine with less CPU and less RAM will show you the second you start to implement code that is detrimental to performance.

And it will also encourage good practice. Any program that's slow on your development PC will be unnecessarily slow if you ever do intend to scale it up somewhere else. So when that script to rename your MP3's starts struggling with 1000 files on your old laptop, you know that you should fix it before you convert it to rename 10,000 user accounts on the server in work. And when that game starts running out of memory with only a 10x10 board on your laptop, you know exactly how much it'll take on a modern PC before it starts exhibiting problems, when normally you wouldn't have given it a second thought.

This is especially important if you are developing for embedded systems, handheld games consoles, homebrew circuits, anything that's underpowered. You don't need to program on something of the same MHz or less of your target machine, but you need to be able to get an idea of where your program is slowing down while still using your development machine.

Using an old machine will also deter you from using your main desktop to program on. This can be important for a number of reasons - First, the source code (and associated backups) of any prolific programmer will get out of hand very quickly and you don't want it spread across your system. Secondly, you can backup to a different machine easily as part of the "routine" (e.g. a good system is to develop on a PC which is tricky to connect to the Internet - my old laptop has wireless but for simplicity and security, I set it up so that it proxies through my desktop machine for web access. This means that anything like FTP, SVN, etc. I have to deliberately enact or do from another machine, and it's slower to do so, which also provides the incentive to backup the same files to other machines while I'm waiting). Third, it removes the risk of damage to your everyday machine. This is especially important if you are using pointer-based or low-level languages that can potentially crash or corrupt a machine.

6) Test

If you intend to distribute the end-binaries to anyone, test it thoroughly. Good feedback is significantly hindered if your early versions have lots of basic problems or dangerous bugs. And get lots of people to test it for you. Announcing version 1.0 suggests that you've had lots of people testing it, believe it or not, so make it clear it's a test/0.9/beta/prelease version and then improve on it to make the magic 1.0 something special that works first time for everyone.

Testing is multi-stage. You need to test it thoroughly yourself. This usually means running the end program an awful lot of times, with different inputs. You don't need to generate a program to automate a test suite, you just need to use the end program a lot. This is especially good for games - just play the game a lot - until you realise that actually it IS possible for both players in the fighting game to hit 0 health on the same move, and you should add a "Round Draw" sound/routine/graphic.

Another stage of testing is theoretical. As you plough through the code, look for potential problems. "Oh, bugger, I don't test if someone asks for a -1 sized game!". Users are dumb - don't trust users, they are "rm -f *"'ing all the time, so they will find a way to break your program/their computer if it exists. Such analysis is hard to do if you set out specifically to do it but you'll catch a lot of bugs this way. This is best done when you spot a particular bug or as part of your general looking through the code for functions to tweak.

The best stage of testing is undoubtedly giving the program to other people and asking them to test. They won't have the same file structure, hardware, software, way of using the keyboard/mouse/joystick. They won't be aware of or use the little foibles and habits you've got into ("Oh, I only ever run the game from a script within Windows, I thought it would just work without it", "I don't touch the mouse when it's loading up", etc.). And the least experienced the person is, the better. You'll get hundreds of people test a game but only one or two would accidentally click outside the main menu, or tell you that the program says it can't find a common library.

And people who don't know how the program works will be clicking around in a non-obvious way so they will find all sorts of bugs as they try to figure out how it works, whereas an experienced person will just be dragging/dropping and completely ignoring the menus or buttons, for instance. My wife is the best bug-finder in the world. I guarantee that I can put a program thats worked successfully for months for a thousand people onto her Palm and within an hour she'll have crashed it somehow.

7) Have a nice development environment.

This doesn't mean a flashy GUI, it doesn't mean having a multitude of debuggers for multiple architectures. What is does mean is that there area as little distractions as possible when you're coding. You can compile with one command or click. You can place files into a clean test area with similar ease. You have all the tools you need most of the time. You don't need perfect Makefiles, or fantastically complicated scripts to allow it to compile on every architecture in the world, but you do need to have an easy way to do things for yourself.

For my projects, I often have Makefiles but use them sparingly or in a special way. And a lot of the time, if I'm working on a particular part of the code, I'll have a simple script that compiles, links and runs just the part that I need. I don't intend anybody else to ever use that script, I don't even distribute it, but it's a convenience when I'm programming.

If you're developing for another machine, you should have a way to simulate or access that machine quickly. For instance, I develop for the GP2X, so when programming for it, I usually have it close to hand. That doesn't mean I have to plug it in every session but it's easily accessible. I can plug it in and test stuff in it. As there are two main types of GP2X, I have a way to "emulate" the other type so that I can spot potential problems etc. I also have telnet and VNC access to the machine so that I can leave it running and test multiple programs in many ways in one session without having to keep re-connecting and running the machine.

For some people, this might also mean artificially limiting the memory/CPU available to their programs when they want to see how it would run on their target machine. Or running a software emulator. Or connecting the machine itself, transferring the program over and seeing how it works. Especially in the last case, you want to make it as simple as possible.

Debuggers are useful but you should only be using them relatively rarely. Simple problems are much easier to solve with code inspection. You'll usually know exactly where it crashed and a quick glance will give you the why. Tricky problems can be isolated with a couple of printf's or their equivalent. And difficult problems don't NEED the facilities of a debugger, they need your brain the most, but a debugger can then be a big help.

Have easy access to manuals and function references. Visual Basic used to come with a massive function reference manual that was incredibly useful. Sometimes just flicking through it would give you ideas about how to solve problems because you found functions you never knew existed that could do things in a different way for you. The TI-85 calculator was the same, and even the ZX Spectrum came with a BASIC manual. Even a "For Dummies" book can be an incredible reference for a seasoned programmer, especially if you switch between languages often ("Is it Select Case of switch() in this language?").

If you're programming with a particular library, say SDL, have access to a complete reference to it, with examples. This is immensely helpful, even if it's just a bookmark of a good site. I use one for SDL that lists the C prototype of functions and structures (which I copy/paste straight into a program and then edit to turn it into an actual function call), a brief description with lots of hints on what is and isn't possible (e.g. don't run SDL functions inside SDL threads etc.), and an example or two of using each function. It's amazing how much more helpful a simple example can be over a documented manual. Even a Google for a function name will turn up uses and tricks that you'd never have thought of, plus a variety of sites publishing "gotcha's" for using it.

8) Don't worry about the "proper way" of doing things.

You can't use GOTO. You should write performance-critical code in C. You shouldn't declare global variables. You should get structures down to their minimum required size. You should optimise all your functions. You should consolidate duplicated code.

Rubbish. Program for operation FIRST. You're not a NASA shuttle engineer, you're not dealing with 1000's of financial transactions. There are not going to be people sniffing over your code with disgust because you saved yourself having to restructure a hundred lines of code loops by using a jump instead.

If you intend to teach a programming course, or you're entering code into a critical programming project, then you should follow quite a lot of this advice. But if it's for a quick game that only you or a handful of people will ever want to see the code for, don't worry about it. A few of those items will help make you a more structured programmer, a few will reduce the risk of you leaving an accidental bug in your code, but the majority of them are pendantic ramblings of people who learned to program on punchcard and consider every cycle sacred. Don't get me wrong, I hate unoptimised programs with shoddy algorithms that bloat memory and slow the CPU, I can describe a bucketful of pathfinding, tree, sorting algorithms and their O(N) scales and there was a time when I would audit Z80 assembly and literally save hundreds or thousands of cycles in even the smallest listing, but for casual programming all that sort of stuff can come later.

9) Think.

This is the best bit of programming. Getting your head around why the 100% logical machine in front of you isn't doing what you ask. Invariably, it's because you've done something wrong but finding it is the best part. Programming requires you to think not only logically but creatively ("I haven't got a way to use floating-point numbers on this machine, how can I get around that to draw a circle?", "I can't use this function from inside a thread, so how do I get this thread to do what I want?").

The best part, although it's shocking, is that you do NOT need a computer to program. Argh! What is he suggesting? No, I don't meant that you should write a hundreds lines of C on paper perfectly first time, but that you can program in your head or on paper just as easily. You should be able to craft the basic structure of a program in your head before you start to write it, you'll be able to spot pitfalls, estimate which way is better or takes less RAM or less CPU.

You can program on a busy train. You can program in a quiet room. You can program in the garden. And you don't need a wireless laptop to do it. When I was learning to program, the best part was to get so struck with an idea that you dug out some paper to get your idea down before you'd even sat at a computer to try it.

Sometimes this even involved primitive flow charts but most of the time it meant just sketching out some pseudocode and working out some primitive structures.

I would use other people's programs of operating systems and work out how certain things functioned ("This must be a double-linked list", "They must be spinning in a loop waiting for me to press a key", "The AI in that is watching to see when you move more than X units into a small space before it considers it an attack", etc.). And a lot of the time I found myself stumped and sat down to work out how things worked. Or a way to improve them. Most of my ideas never made it onto an actual computer but it's the best part of programming - to stimulate the brain.

10) Enjoy it, and make it fun

Programming is like a puzzle. The aim of the puzzle is to finish whatever program you started (and sometimes just getting the answer hidden in the yellow squares isn't enough and you have to go and finish off the rest of the crossword). The intellectual challenge is to do that and to debug it when it doesn't work (and some people subject themselves to such intellectual challenges all the time, even when the answer is only a calculator tap away). The point of doing it all is to have fun (once you do the one-millionth wordsearch, or you've spend eight months on the same clue, the puzzles lose their appeal).

Why do you want to subject yourself to decrypting the Enigma code, when you could just as happily do a tabloid crossword? Do things that are within your capabilities, are fun, aren't over-stretching your bain, and that you enjoy doing. That's why people program. That's why there's billions of lines of code just floating out that the people are offering for free... they don't care that it was hard to do, it was fun for them to do it. Fun to prove it could be done, or that it could be done better, or that they could do it, or to get recognition from someone else for their hard work.

This is especially true if your programming games. If you can't enjoy the game at the end, there was little point in writing it you would think, but actually even the worst of games can be fun to program.

Wednesday, April 09, 2008

STPPC2x Beta 2- GP2X port of Simon Tatham's Portable Puzzle Collection

I've just released Beta 2 of my port of Simon Tatham's Portable Puzzle Collection to SDL/GP2X. It is much improved and the only remaining "problem" is that mines doesn't work. The other 26 games run fine from start to end.

I think the problem with minesis due to endian/signedness differences between x86 and ARM within the puzzle code itself (which I don't change in order to port any of the games). The game compiles and works under x86 Linux and runs fine but the GP2X crashes with an assert on mines.

The beta 2 version of STPPC2x (and the associated source code) can be found here:

http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,25,2543

Or on the website where I keep all the released versions:

http://www.ledow.org.uk/gp2x/

Saturday, March 29, 2008

GP2X port of Simon Tatham's Portable Puzzle Collection

Damn it's a long time since I programmed in C.

I've just spent the last few weeks porting the GTK/Windows/MacOS/Palm collection of games that are in Simon Tatham's Portable Puzzle Collection to work on the GP2X handheld game console.

That involved the creation of an SDL "frontend" for the existing puzzle infrastructure (which, I have to say was beautifully abstracted and documented from a programmer's point of view). It worked beautifully well on the whole. The puzzle framework is designed in such a way that it can be easily ported by just filling out the definitions of a few dozen functions. Basing my work off the existing GTK port, most of the simple functions were only a line or two to convert to SDL (using the SDL_gfx library helped a lot too). Even the font functions were quite simple, when using SDL_ttf. And because the GP2X is Linux-based, I was able to prototype all the functions using the GTK functions running simultaneously with their SDL equivalents on the same development PC, as you can see from the screenshot. Each game is running an SDL and GTK copy of the game and synching display and input between the two, while running on a normal Linux PC.

After they all functioned enough to give me a playable game in SDL, I started stripping out the GTK functions, libraries and dependencies and ended up with an executable that only needed SDL, SDL_ttf and SDL_gfx to run. That ran on any SDL-based architecture so I could compile the same code for either the GP2X or the Linux PC. For the GP2X it was the "simple" matter of cross-compiling them to the GP2X's ARM architecture, linking them against some ARM SDL libraries and then testing them on the machine itself.

But it has to be said that the hardest part of all was actually getting things to compile and link properly! I now officially hate Makefiles, gcc and linkers. I wasted more time trying to get code which I *knew* was working to compile and link in various ways without errors than I ever did coding! That really was the most horrible experience and half the time I had no clue as to what the problem was, even after analysing and googling the various weird and nonsensical errors I was getting. Programmers should really not have to play about with such convoluted and finnicky command lines just to get a simple C program with pre-compiled libraries to compile and link. Granted, wanting to compile a program for both x86 and ARM, with dynamic or static libraries should mean a little tweaking but it should never be as difficult as it was. I was actually *scared* to touch the Makefile each time in case I broke it and I kept more backups of that than I did the actual SDL interface code.

Anyway, I eventually got the puzzles to the point that they were mostly playable, mostly fun, mostly working and mostly pretty-looking. I've tested them all on GP2X and they are, on the whole, working (there is one that errors out in the actual game code, which I haven't touched, but only on the GP2X - a Linux machine with exactly the same code doesn't error. The other problematic one is just a bit too slow because it tries to do a lot in a short time on a slow processor). I was working my way through them one at a time to release them, because some of them exhibited subtle bugs, some of them required more work on input to allow them to "enter" numbers into the puzzles and at least one of them was (and still is) just being a pain in the bum. But now the vast majority of them work and I've built "beta 1" of what I have called (in a rare fit of originality) STPPC2x, or Simon Tatham's Portable Puzzle Collection for the GP2X. :-)

I'm surprised at how well and how fast they work, considering that the development 600MHz machine doesn't run them any faster than the GP2X at 200MHz and I'm not even using the hardware acceleration on the GP2X properly.

The first beta, with 25 out of 27 games playable, most of them near-perfectly, has been released on both the GP2X archive and at my website: http://www.ledow.org.uk/gp2x/ You can get the source code and toolchain that I used from my website too, because I find the most annoying thing about picking up other people's code is when you don't have the same compiler/libraries/filesystem setup as they do, so it's a problem to compile even before you start coding.

I consider it a good piece of work, considering that my last C excursion ended about an hour after starting it and I ended up writing the program I needed in something else instead. That was several years ago but I was able to pick this up and run with it. I estimate the total *actual* development time on STPPC2x to be approximately 48 hours for approximately 1000 lines of actual code (not including the Makefile), spread over a period of two and a bit months (it's hard to get in a mood where you want to fight with compilers, pointers and libraries). At least six of those hours was getting the Makefile to work properly. At least two were creating scripts to compile and link each file individually because I was sick of the Makefile not working properly and needed something that worked *here and now* so I could work on either the Makefile or the actual code at my leisure. At least ten hours on top of those 48 were things like "waiting for stuff to compile", "waiting for stuff to copy", "waiting for stuff to upload to my website/the GP2X archive", "preparing screenshots, instructions, proper licensing info, directory structure etc. for releases" and "waiting for the GP2X to finish writing to the SD card". A 600MHz development machine trying to copy megabytes of files over a USB 1.1 connection to an SD card isn't ideal, especially when you trying to write instructions, take screenshots, upload via FTP, etc. simultaneously. :-)



Anyway, it's been my first big programming project for a while. I'm always writing *something* whether it's a shell script or batch, a VB program to do a quick job etc. or something for my own entertainment but they all involve different standards of work - either I'm the only person to ever use the program at all, or it's for a limited technical audience, and it's very rare that the source code is ever looked at in either case.

In the first 24 hours, it saw 100 downloads from the GP2X archive alone and I haven't looked at my website's logs yet. At least I know that it was worth my while.