My boy is a fickle customer - he laughs a lot, but it's rare that something that amuses him one day will elicit the same giggles the next day.
Today's giggles came by gently gumming the ends of his fingers while singing "Twinkle Twinkle Little Star". He found this absolutely hilarious.
Making your child laugh has to be one of the best pleasures life holds ;)
Monday, July 26, 2010
Thursday, July 22, 2010
Adventures in the land of functional programming, part 1
I've been programming for a long looong time now, not only in years (over 30) but in terms of a proportion of my lifespan. I've had some formal training in programming while in the beginning stages of a degree course, but the vast majority of my time spent programming has been using techniques and knowledge that I've acrued through practice. I've made many mistakes, and in the beginning at least, I rarely had anyone telling me that my approach or technique was a bad one.
To give some perspective on just how far back we're talking here, my first programming experience was on Research Machines Link 380z machines at school. My first program was intended to print the time, but I managed to put a bug into a two line program, and instead of the time it printed "Tim" over and over again. Given that's my name, I was instantly hooked. It also shows just how terrible I was at ensuring my code was correct, and that's something that's barely changed over nearly 20 years of professional programming.
I've written in a variety of languages, starting with BASIC on a ZX-81 at my dad's house, followed by BASIC on a Dragon 32 at home (and similar experience with Spectrums and Commodore machines). I modified production code written by someone else while trying to complete a game on the Dragon, and had a foray into assembly on the BBC Micro and Spectrum.
Various diversions around making music (Soundtracker and Octamed being the instruments of choice) and graphics followed, before I wrote a program to generate horoscope birth charts, which was my last non-professional step before the games industry.
Writing games is very, very different to just about any other programming persuit. The hardware is always constrained compared to any desktop machine. The expected outcome of a game is something visually stunning, audibly impressive, containing animation, effects, and a whole host of other gloss while essentially performing a simulation of a world running to some constrained set of rules, and by the time I started programming games, this was all expected to happen in real time. In other words - assuming you've got an NTSC telly, you've got exactly 1/60th of a second to figure out the result of simulating 1/60th of a second of your game world and also to draw that result.
It's incredible just how much you can achieve in that timescale (especially so with modern hardware like the PS3) but even when I was writing game code for the SEGA Genesis, if you consider games like Lemmings that emulate the behaviour of tens of critters all walking around in a world - it's pretty darned cool. Of course, to get those results (including all the shiny graphics) you had to cut every corner possible, shave every instruction from the list of instructions, and cheat like a mofo in every action you took.
To give a concrete example - when writing Shadow of the Beast for the Mega CD, instead of accurately modelling what happened when the beast responded to the jump button (how heavy is he? how fast is he moving upwards? apply gravity for 1/60th of a second ... how fast is he moving now? where is his position now?) we simply had a table of numbers which we added to his current screen height, that looked roughly like this: 7,5,4,3,2,1,2,1,0,0,-1 ... Yes, I typed that list in by hand, and tweaked it a few times till it looked right. No, it's nowhere near an accurate simulation of a velocity curve, but who's counting?
Every action in a program has a cost, in terms of how much memory it uses and how long that action takes to perform. On the earlier consoles, even things as simple as multiplying numbers was a very expensive thing to do - if you could stick with multiplying by powers of two, that was a lot cheaper. Don't even think about using floating point values! And when you've got 8 memory registers and 32k of main memory to play with, then you make damn sure you don't waste even a byte of it (and sometimes you make damn sure you're not even wasting bits).
Pretty much every one of these tricks is actually terribly bad if you look at a program in terms of how likely that program is to contain errors and bugs. Starting from questions like, Is your math correct? (obviously, no!) but leading on to, is the program performing the same actions as it was a second ago? (well, no - I just wrote some self-modifying code there because I needed to reuse the memory, so it's definitely not). Is the data in memory you just created from that calculation the same as it was a second ago? (well, no - I re-used that memory to do something totally different a few milliseconds back.) Does that function give the same results when you give it the same input? (it should, but it doesn't - because that global variable there got changed by some other function elsewhere and now it makes the result twice as big).
Over the years, I've moved from simple to complex to insanely complex hardware, and from teams of one or two people to teams of 50 people. The largest programming team I've worked on had over 100 people actively changing code during the last couple of weeks of crunch.
The resulting code is a mess. Elegant? - sure. Fantastically clever? - sure. Brilliantly constructed given the constraints? always.
Correct? Never.
Every single game I've ever worked on had at least one bug in it when it shipped. Some have hundreds or thousands.
Of course, you can blame my lack of skillz as a programmer (and indeed many people have!) but ultimately the reason these bugs are there is twofold. First, the techniques and methods used to write the software mean the bugs are possible. Second, the techniques and methods used to write the software mean the bugs are mostly invisible except under certain circumstances.
There has to be a better way, surely?
If you're expecting an unequivocal yes, then you've obviously never written a program before. But there's options. See part two of this series for more details.
To give some perspective on just how far back we're talking here, my first programming experience was on Research Machines Link 380z machines at school. My first program was intended to print the time, but I managed to put a bug into a two line program, and instead of the time it printed "Tim" over and over again. Given that's my name, I was instantly hooked. It also shows just how terrible I was at ensuring my code was correct, and that's something that's barely changed over nearly 20 years of professional programming.
I've written in a variety of languages, starting with BASIC on a ZX-81 at my dad's house, followed by BASIC on a Dragon 32 at home (and similar experience with Spectrums and Commodore machines). I modified production code written by someone else while trying to complete a game on the Dragon, and had a foray into assembly on the BBC Micro and Spectrum.
Various diversions around making music (Soundtracker and Octamed being the instruments of choice) and graphics followed, before I wrote a program to generate horoscope birth charts, which was my last non-professional step before the games industry.
Writing games is very, very different to just about any other programming persuit. The hardware is always constrained compared to any desktop machine. The expected outcome of a game is something visually stunning, audibly impressive, containing animation, effects, and a whole host of other gloss while essentially performing a simulation of a world running to some constrained set of rules, and by the time I started programming games, this was all expected to happen in real time. In other words - assuming you've got an NTSC telly, you've got exactly 1/60th of a second to figure out the result of simulating 1/60th of a second of your game world and also to draw that result.
It's incredible just how much you can achieve in that timescale (especially so with modern hardware like the PS3) but even when I was writing game code for the SEGA Genesis, if you consider games like Lemmings that emulate the behaviour of tens of critters all walking around in a world - it's pretty darned cool. Of course, to get those results (including all the shiny graphics) you had to cut every corner possible, shave every instruction from the list of instructions, and cheat like a mofo in every action you took.
To give a concrete example - when writing Shadow of the Beast for the Mega CD, instead of accurately modelling what happened when the beast responded to the jump button (how heavy is he? how fast is he moving upwards? apply gravity for 1/60th of a second ... how fast is he moving now? where is his position now?) we simply had a table of numbers which we added to his current screen height, that looked roughly like this: 7,5,4,3,2,1,2,1,0,0,-1 ... Yes, I typed that list in by hand, and tweaked it a few times till it looked right. No, it's nowhere near an accurate simulation of a velocity curve, but who's counting?
Every action in a program has a cost, in terms of how much memory it uses and how long that action takes to perform. On the earlier consoles, even things as simple as multiplying numbers was a very expensive thing to do - if you could stick with multiplying by powers of two, that was a lot cheaper. Don't even think about using floating point values! And when you've got 8 memory registers and 32k of main memory to play with, then you make damn sure you don't waste even a byte of it (and sometimes you make damn sure you're not even wasting bits).
Pretty much every one of these tricks is actually terribly bad if you look at a program in terms of how likely that program is to contain errors and bugs. Starting from questions like, Is your math correct? (obviously, no!) but leading on to, is the program performing the same actions as it was a second ago? (well, no - I just wrote some self-modifying code there because I needed to reuse the memory, so it's definitely not). Is the data in memory you just created from that calculation the same as it was a second ago? (well, no - I re-used that memory to do something totally different a few milliseconds back.) Does that function give the same results when you give it the same input? (it should, but it doesn't - because that global variable there got changed by some other function elsewhere and now it makes the result twice as big).
Over the years, I've moved from simple to complex to insanely complex hardware, and from teams of one or two people to teams of 50 people. The largest programming team I've worked on had over 100 people actively changing code during the last couple of weeks of crunch.
The resulting code is a mess. Elegant? - sure. Fantastically clever? - sure. Brilliantly constructed given the constraints? always.
Correct? Never.
Every single game I've ever worked on had at least one bug in it when it shipped. Some have hundreds or thousands.
Of course, you can blame my lack of skillz as a programmer (and indeed many people have!) but ultimately the reason these bugs are there is twofold. First, the techniques and methods used to write the software mean the bugs are possible. Second, the techniques and methods used to write the software mean the bugs are mostly invisible except under certain circumstances.
There has to be a better way, surely?
If you're expecting an unequivocal yes, then you've obviously never written a program before. But there's options. See part two of this series for more details.
Labels:
bugs,
correctness,
errors,
functional programming,
setup
Sunday, July 18, 2010
One world, idiots
I bought myself a really tasty piece of kit this week, a Korg NanoKontrol. this little beauty lets me control various aspects of music via sliders, knobs and buttons while I play, and allows me to add expression to what is otherwise fairly automated music creation.
In the package I also recieved a coupon to get money off Ableton Live, which seems to be a fantastic piece of sequencing and performance software. I've been demoing it for a few days, and thought, why not? I'll see how much money the coupon gives me off.
So, I go to the Ableton shop, and find that I can buy their Ableton Intro package for 99 dollars or 99 Euros. Given that I'm downloading it, I'll take the 99 dollars, thanks! (A quick google shows that one Euro today is worth around 1.18 dollars). I then have the revelation that the coupon will either grant me 30 Euros off, or 50 dollars off.
Obviously, thinks I, this is a no-brainer! I'll buy Ableton Intro for 49 USD, I get some software, Ableton get a sale, everyone's happy! So I enter all my details.
At which point the website decides that I'll be paying in Euros instead, and reprices the coupon to 30 Euros rebate instead of 50 dollars, taking the grand total from £32 to £58.
Erm, no. No thanks. I'm not giving you twice as much money on a whim just because I live somewhere else in the world - we're talking about SOFTWARE.
So, no sale. Sorry Ableton - you had me on the hook, you had me putting the virtual box into my virtual shopping cart, you virtually had a sale - but you lost it at the last hurdle.
In the package I also recieved a coupon to get money off Ableton Live, which seems to be a fantastic piece of sequencing and performance software. I've been demoing it for a few days, and thought, why not? I'll see how much money the coupon gives me off.
So, I go to the Ableton shop, and find that I can buy their Ableton Intro package for 99 dollars or 99 Euros. Given that I'm downloading it, I'll take the 99 dollars, thanks! (A quick google shows that one Euro today is worth around 1.18 dollars). I then have the revelation that the coupon will either grant me 30 Euros off, or 50 dollars off.
Obviously, thinks I, this is a no-brainer! I'll buy Ableton Intro for 49 USD, I get some software, Ableton get a sale, everyone's happy! So I enter all my details.
At which point the website decides that I'll be paying in Euros instead, and reprices the coupon to 30 Euros rebate instead of 50 dollars, taking the grand total from £32 to £58.
Erm, no. No thanks. I'm not giving you twice as much money on a whim just because I live somewhere else in the world - we're talking about SOFTWARE.
So, no sale. Sorry Ableton - you had me on the hook, you had me putting the virtual box into my virtual shopping cart, you virtually had a sale - but you lost it at the last hurdle.
Saturday, July 17, 2010
Where does the week go?
I started this week with good intentions, and ended up spending most of my time writing music and playing with my new NanoKontrol.
Still, I managed to get the cable run sorted from downstairs to up, even if I didn't manage to get anything under voice control yet. I'm not too far off!
It's amazing how fast a week goes ...
Still, I managed to get the cable run sorted from downstairs to up, even if I didn't manage to get anything under voice control yet. I'm not too far off!
It's amazing how fast a week goes ...
Monday, July 12, 2010
All tied up
A week on holiday brings with it a clear horizon and the promise of getting stuck in to all the work I've been thinking (and talking) about for the last six months.
I've got a spool of cat5 waiting to be put to good use and some cable trunking. Next up, I need to figure out where to drill and which floorboards to lift, both upstairs and down. I'd like to have some neat RJ45 sockets linking the upstairs and downstairs, and I'm also thinking of putting a media/compute server somewhere out of the way and that's probably going to mean I need to get some power and network cables under the stairs.
I've also made good progress on getting some hooks into the Microsoft Speech API - PySpeech looks like it'll do most of what I want, although I'm not sure if I can feed off the voice recogniser without it interacting with the operating system at the same time. The accuracy seems good for phrased dictation, but not so great for single word command sequences which may screw with my plans. I might have to break my command strings into discrete flows and make each stage gate on a selection of similar sounding words. I'm also unsure of how it interacts with different speakers.
Hopefully by the end of the week I'll have the infrastructure in place to voicerec from the bedrooms and the living room, and possibly one item in the house under voicerec control - I'm thinking of starting with an IR transmitter for the various media boxes. TIRA and USB-UIRT both look viable, although I've yet to find a UK reseller. If anyone knows of an alternative option please enlighten me - I'm basically looking for a transmitter/reciever box that connects via USB and has some form of programming API, with the intention of recording button presses on my existing remotes and playing them back to control my satellite and tellybox.
I've got a spool of cat5 waiting to be put to good use and some cable trunking. Next up, I need to figure out where to drill and which floorboards to lift, both upstairs and down. I'd like to have some neat RJ45 sockets linking the upstairs and downstairs, and I'm also thinking of putting a media/compute server somewhere out of the way and that's probably going to mean I need to get some power and network cables under the stairs.
I've also made good progress on getting some hooks into the Microsoft Speech API - PySpeech looks like it'll do most of what I want, although I'm not sure if I can feed off the voice recogniser without it interacting with the operating system at the same time. The accuracy seems good for phrased dictation, but not so great for single word command sequences which may screw with my plans. I might have to break my command strings into discrete flows and make each stage gate on a selection of similar sounding words. I'm also unsure of how it interacts with different speakers.
Hopefully by the end of the week I'll have the infrastructure in place to voicerec from the bedrooms and the living room, and possibly one item in the house under voicerec control - I'm thinking of starting with an IR transmitter for the various media boxes. TIRA and USB-UIRT both look viable, although I've yet to find a UK reseller. If anyone knows of an alternative option please enlighten me - I'm basically looking for a transmitter/reciever box that connects via USB and has some form of programming API, with the intention of recording button presses on my existing remotes and playing them back to control my satellite and tellybox.
Sunday, July 4, 2010
Every week has one WTF in it
Wednesday, Thursday, Friday.
although my weekly WTF frequency is considerably higher now Gabe's around.
although my weekly WTF frequency is considerably higher now Gabe's around.
Saturday, July 3, 2010
Local minima
There's a guy who lives over the road from us. Even though we've been living here 6 months, he's never bothered calling, welcoming us to the neighbourhood, anything like that.
He's quite happy to park outside my house, tho. Rather than reverse into his own space, he'd rather drive forwards into the double space outside my house and park in the middle of the two.
That's about as lazy as you can get.
He's quite happy to park outside my house, tho. Rather than reverse into his own space, he'd rather drive forwards into the double space outside my house and park in the middle of the two.
That's about as lazy as you can get.
Thursday, July 1, 2010
And justice for all
the Finns have just declared that broadband is a legal right for every citizen.
This may seem like fantastic news, but on closer inspection one has to wonder if it will simply mean more people spouting pointless trash on Facebook.
Still, the future starts here and all that. Good for you, Finland!
This may seem like fantastic news, but on closer inspection one has to wonder if it will simply mean more people spouting pointless trash on Facebook.
Still, the future starts here and all that. Good for you, Finland!
Leadership and solitude
I stumbled today across an interesting lecture given to students at West Point earlier this year.
I should probably get a copy of Heart of Darkness, I've not read it yet.
I should probably get a copy of Heart of Darkness, I've not read it yet.
Subscribe to:
Posts (Atom)