// this:var id:int = 0;
varname:String = id.toString();
// as opposed to this:var id:int = 0;
varname:String = "name_" + id.toString();
// and ESPECIALLY this:var id:int = 0;
varname:String = "obj_" + "name_" + id.toString();
Conclusion: each additional concatenation adds roughly an additional 20% to processing time
Twenty percent is a lot if you’ve gotta run through a long loop and assign properties to a whole bunch of properties. Anywhere where you can avoid concatenation you should. Storing values indexically with integers seems by far the best way to go with this, whether you are storing your data in Arrays, Dictionaries, Objects or your own bespoke class. Concatenation is going to drag you back wherever you use it.
Having put the original cellular automata swf up a couple of days ago I found myself in a coding frame of mind, so I decided to devote the whole of yesterday to it. I abstracted the data sections of the previous version out so i could use their mechanisms to produce new generative visualisations and having done that got straight down to making a second. Here it is, just click the wee arrow to get going:
That’s the description of a problem Flex Builder just presented me with. Not too descriptive is it? With so little to go on, I assumed there was some file corruption somewhere and hunted high and low to find it, to the point of checking my whole project out from scratch. Nothing helped.
I found the problem eventually though. It was this:
switch (someValue){
}
That’s all: an empty, half-finished switch statement!
I’d recommend making sure you finish coding your switch statements before casually hitting ’save’ if you don’t want to waste time like I just have.
This is a great little bit of generative art, probably the best I’ve ever made. It’s based upon ‘cellular automata’. Click the wee arrow to start. Be warned though: it moves at a pretty slow pace and takes a good five minutes to get really good. i like it that way.
For some background as to what cellular automata are and an explanation of what the black & white squares along the bottom signify, read on…
// this:publicvar id:int;
// as opposed to this:privatevar _id:int;
publicfunctionget id ():int{return _id;
}publicfunctionset id (id:int):void{
_id = id;
}
Conclusion: Public properties are roughly 20% faster than private vars with getters & setters
If you don’t need to run any code on a class property why bother writing a getter and a setter for it? It’ll take longer to type (FDT users aside), make your code fatty and run slower. Tell me the advantage in all that. Instead, why not just use a public variable with the caveat that if you need to turn it into a private variable with a getter and a setter later you can?
I did a bit of generative art in Flash earlier this year. A decent bit too, thanks to some good tip-offs by snail-brain supremo Peter Passaro. Wanting to get it running as efficiently as possible I spent a day back in May trying things out and discovered a couple of tips that didn’t feature in John Grden’s awesome AS3 optimisation list. There were quite a few and I’ll try to get through them over the next few weeks.
FlashBrighton’s Joe ‘Lego’ Chung & Neil ‘Fleecie’ Manuell have spent much of the past few months developing an AS3 version of BBC 2’s popular ‘Robot Wars’ game. The basic idea is to build a framework that would allow coders to write their own fighting Bot class by implementing a Bot interface and letting said bots slog it out to see who codes the baddest bad-@ass bad-bot. Awesome!
The game is far from finished but we had our first rumble-off Tuesday just gone and I’m pleased to say that I was that bad-@ssed winner! With just 5 TUFF LINES OF CODE I out-muscled the opposition with my unstoppable tactic of… er, retreating to the edge of the arena and letting the others knock the stuffing out of each other.
Get in!
I don’t think it’s a tactic that’ll work twice but that’s ok, I’ll happily take Round 1 and adapt to the changes next time. I’m already frying up an idea or two to try out…
Man, I thought Flash on the Beach was good… and I was right, it was! But BarCamp is better. BarCampBrighton2 took place at Sussex University over the weekend just gone (15th & 16th March, 2008) and I was there. It was my first BarCamp but it definitely won’t be the last. It was ENORMOUS fun.
Last night, sometime around 10pm, a tired and understandably ‘bit grumpy Niqui Merret pulled her little grey car up outside my house and dropped me off after a gruelling 12+hr road trip home from FITC Amsterdam. I took my bag and my wooden pink elephant inside and went di-rect-ly to bed. ‘Shouldn’t take that long to get from Amsterdam to Brighton but when SeaFrance Ferries get it into their head to have a strike it leaves a lot of people stranded, tired and hungry on the dockside for hours, whilst P&O struggle to help everybody out. I’m glad the union movement is still strong in France, I just don’t want to sit and stare at the suburbs of Calais for 3 hours.
But that aside, what a blast man! I’m not going to go into tedious detail but it was ENORMOUS fun. Shawn, you can have me back in Amsterdam anytime you want. Where do I sign?