Life on Rails » Technological travels in Flex, Air, RIA and life in general
Imagine a beautiful autumn park, and a bald ginger man reading books and playing guitar, and doing other stuff

TDD or not TDD, that is the question

I’ve seen the light. For so long I thought I was doing TDD, I thought I was being agile, and I hate to admit it, but I wasn’t. I was trying too hard. I was thinking too much, and secretly holding to fears and misconceptions that were stopping me from realising the benefits of some of the best agile practices.

I’m not hung up or bummed out though – it was fair enough really – the project’s I was on didn’t really allow for a truly agile approach for the majority of the time. The fact is you have to breathe out before you breathe in, and I was in a situation where there was no breathing space at all.

But I eventually did get some breathing space, and a neat reading list and as fate would have it, that coincided with one of those periods that we all get as software engineers, where you get real hungry. I’m not talking raid the fridge hungry, I’m talking knowledge hunger – process hunger, efficiency hunger.

I’ve been lapping up some great stuff and it made me see where I was going wrong in a lot of areas. The biggest one I came to realise was that I wasn’t really doing TDD.

I kept trying, but I’d always buy into THE OLD LIE. You know – “it takes too long to write the test up front, I’ll just nip back later”. Recently though, I sat myself down after my latest book bout and had a word with myself.. what was stopping me from doing this?

It turns out it was actually something quite simple – it took so long for me to compile and run tests on the projects that I was in, that I had a skewed opinion of TDD. I was literally associating the amount of time it took to build and run a full testrunner (often times in excess of 800 tests) with TDD. In short I had been foolish.

I think it was the nazareen who said “if thy eye offends thee, tear it out”, which though seemingly grim, is actually good advice. And tear it out I did.

I basically came to a new understanding – this is it: The testrunner is the total suite of tests for the entire application, The testrunner is the docuemntation of the API’s of the entire application, The testrunner is ueful for regression, The testrunner is useful when building to ensure the application is in a healthy state, The testrunner actually is more and more depending on how many books you read, and how good your memory is.

One thing the testrunner is NOT however, is a harness for doing TDD.

This has been my single biggest leap in understanding of TDD. Quite simply the apps I work on are so big that building and running the entire testrunner in order to do TDD is simply unbearable.

On my last project some of us would sometimes remove all the tests from the testsuite, save 1 or 2 (remember, if thy eye offends thee – tear it out ;-) ). However, we never formalised this process – sometimes with disastourous consequences: You’d run the testrunner and find someone had deleted ALL of the tests in the app.. Looks like that build that went out might have only gone out with 1 out of 1,000 tests being run on it..

I can’t believe how obvious the answer is.. I just made a new rig – TDDRunner.mxml, and a new testsuite AllTDDTests.as. It’s really simple – each developer has their own AllTDDTests file which they keep the tests in that they need at any given time, and never check it in.

I’ve been doing this for a week now and with great results. I’m genuinely able to do TDD without any painful overhead, waiting for the compiler, or other tests, or risking deleting the testuites, or without even losing concentration. It’s a dream come true.

As I write the tests, I add them to the main testrunner, and I run this whenver I reach a mile stone (such as finishing a presentation model, or a domain model ) to ensure that regression is not caused elsehwere.

I cannot emphasize enough how great the benefits of this approach are. Myself and a couple of colleauges are literally buzzing off TDD as a result of this. It’s also much easier to sell to others who are usually closed to it.

It’s gone from barely being able to justify it to some colleagues to the point where they now have no excuse for not doing it.

Perhaps with other languages this isn’t such a problem, but with actionscript, or I suspect with any app with a large testsuite, I suspect this simple process improvement will lead to more developers practising TDD.

FlexBug.. well sort of

I’ve been a huuuge fan of firebug for sme time and longed for a version for flex. FlexSpy has been around for some time, and is really great, but it needed a bit more, especially in terms of invoking it. Currently it has this target button, but it’s a bit naff, and slow..

As such, I’ve taken some code I’ve posted about earlier, and some more code from the great Ralf Bokelberg – to create FlexBug.. it might be cheaky using this name, or indeed using the excellent flexspy code like this, but wtf afterall flexspy is released under the wtf license ;-) (check if u don’t believe me).

The new changes allow you to right click on the stage and it will list a child hierarchy – selecting any element opens that element up in flexspy – making it easier to identify ui components and also quicker (no more parsging tons of xml inside the swf).

I’ve also added FlexTrmp to this as well – which can allow you to execute rudimentary actionscript in real time.

The parser is shite – sorry, it’s just a spike that I’ve never had time to improve, but still – there’s basic code completion, object inspection and code snippets.

Further more – if you hold control while clicking on object’s that are in flexspy view (e.g. presentation models, or other classes) a variable will be created in the code console.

why?

The motivation is simple – I wanted a simple means of getting maximum use out of every build. I’ve worked on a cuple of projects now with huge build times, and I hated when something screwed up that stopped me verifying some functionality. Ok TDD theoreticaly prevents this, but we all know there are frequent exceptions to this, and moments when we wished we could hack about – especially when investigating defects, familiarising with new code or working on spike’s.

I hope you find this combination of flexspy and the ContextMenuItemProvider and FlexTramp helpful. I’ve also included the excellent IsDeveloperVersionChecker, also from Ralf – if you look at the downloaded rig project you will be able to see it’s use – check the compiler args for more info.

Please – no gripes about code etc.. as I said it was only a spike – if anyone seriously want’s to take this on and turn it into a proper open source project – well please let me know.

For working example visit:

for source code download this. flexbugalpha download !+

For more info on flextramp – see my flextramp blog post -it has syntax, etc..

please note – I’m doing this off dial up speed internet (damn bt so much) – my connection is so slow that I can’t really upload working example’s etc yet – you’ll have to trust me and download the zip.

once I got my broadband connection, I’ll upload proper examples and screenshots here..

Animating text in flex - solving scaling problems

I’ve been working on a project recently and made a pod component. There’s a requirement which has the text animating on the pods as they scale up and down. However, we’ve been stuck because the text animation is jerky and jittery and looks wrong.

There are lots of pages about this problem, and the solutions vary from making bitmap data copies (which look crap when they scale up), to using flash, to some random things involving font embedding tags.

However,none of them work – but one of my colleagues stumbled upon the solution..

Use this tag. fontGridFitType

It’s used like this:

here’s a snippet:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
  3. <mx:Text id="jerky" text="some jerky text" />
  4. <mx:Text id="smooth" text="some smooth text" fontGridFitType="none"/>
  5. <mx:Zoom id="grow" targets="{ [ jerky, smooth ] }"
  6. zoomWidthTo="3" zoomHeightTo="3" duration="2000"/>
  7. <mx:Zoom id="shrink" targets="{ [ jerky, smooth ] }"
  8. zoomWidthTo="1" zoomHeightTo="1" duration="2000"/>
  9. <mx:Button label="eat me" click="{ grow.play() }"/>
  10. <mx:Button label="drink me" click="{ shrink.play() }"/>
  11. </mx:Application>

The reason it works is beacuse if the fontGridtype is set to anything other than none , it plays with the kerning horrendously (making the letters land on pixelboundaries) – which makes it appear jerky.

I was sOOO glad to find this out – it was driving me mad!!

Have fun with it.

1and1 does it again, great hosts

Just a short note to say that I truly love the web hosts 1and1. That’s who my server is hosted with, and who is responsible for hosting all of the sites I have.

They have great dedicated server packages that are super fast, with loads of bandwidth. I actually run visualchat.co.uk on on of their dedicated servers, which has ample bandwidth for all the audio and video of the webcam chat sessions.

In short,

  • the servers are fast,
  • they got great control panels,
  • the support is actually really good, both written, and on the phone,
  • the bandwidth is phenomenal,
  • you get free ftp backup with each dedicated server,
  • they never go down.

They really are great – I strongly recommend them… However, I’m not writing because of that – I’m writing to let you know that they have exceeded my expectations again:

In September 2007 I took up a new server package, a beefed up dedicated server, that came with 3 months free contract, then 18 months minimum term. Now, I was intending to migrate my existing dedicated server (contract expired) to the new server.

However, I started working for Adobe, and was so busy that I never got a chance to move the server, and therefore ended up paying for both dedicated servers. Now 1and1 get a few bad reviews for locking people into contracts, but I have to say – they were great with me – I called them, explained what had happened, and they simply asked me to fax them the details.

The server is now cancelled: Including the 18 month contract! Yep! they just let me back out of it, by being reasonable and human about it all – so next time someone tells you that they are monsters, and hold people in to contracts, I suggest you ask them how they spoke to their staff, and how they treated them – I know other people who have been rude, and they get what they give..

I don’t know any other host that would do this – I can definitely tell you 3 other hosts that wont budge at all on these matters (though I don’t want to name them)...

BTW, I’m not an affiliate – I haven’t joined their program, so I’m genuinely objective – check them out if you want dedicated servers- for any small-medium scale project (read as, don’t need a server farm and fail over), they’re great!

I passed my Adobe Flex Exam

I passed my ACE exam,

Adobe Certified Professional

I’m now an Adobe Certified Professional in Flex. Whoohoo!

I’m really chuffed, I scored 86%, and got 100% on the UIComponent section, which is no surprise really, as I do lots of ux work on our current project. Getting to the exam was hilarious. It was on a Sunday and we don’t have a train service on a Sunday, so I planned it precisely: cabs, bus, tube, the lot. 2 hours of travel to get to the examination only to find… I’d gone to the wrong place!!!

I couldn’t believe it, I had just 45 minutes to get to the other side of London. Fortunately, I found a mini cab office next door with a cab driver who was like something from a Jason Staham movie (think “the transporter”). This guy was super cool, and drove like a maniac. I had to use his 10 year old map of London to find the way to the proper examination centre, which made me sooo travel sick, it was unbelievable..

But we got there, and despite me being late and so sick that I had to sit down for 10 minutes, I passed! I have to say it, the exam is quite hard – you need to know a lot of stuff to pass. Here’s a pic of all the notes that I made over the last 3 weeks. If you’re gonna do this, even if you’ve been doing flex for a year or more, I really suggest reading up, for a few reasons:

  • the areas covered by the exam are very diverse,
  • you need precise knowledge of some controls in order to choose between bogus properties, and real properties,
  • It tests you on some of the finer points of framework, such as low level event architecture and the collection and renderer interfaces,
  • best of all – you learn loads by reading up.
More...

flexTRAMP - "Achieve something with every build"

This is my new open source project…

Flex TRAMP is a testing Runtime Actionscript Mini Parser,..

which means it allows you to interact with your running flex app, and:

  • create variables,
  • assign objects,
  • update attributes,
  • call methods
  • and basically interact with your flex app.

Why?

Me and some colleagues are currently working on a flex app that takes a while to build. It’s very frustrating to do a build, then see that some variable, or object is initialised with the wrong value, and have to rebuild again..

I’m used to working with FIrebug – if something goes wrong with my js, I can modify it on the fly, and try again.

Take this example: We’ve got a part of our app that prints some info out. To get to it, you have to enter lots of registration info, and perform lots of tasks.

With FlexTRAMP, I can fire up the app, and in the command line window that appears when I click the FlexTRAMP button, I can create and initialise all of the objects I need, and call the print method, again, and again and again.. no need to go through the whole registration process. Lots of time saved, I’m more productive, and therefore happier :)

Another example – only just today – I did a few changes and made a build. I found that the currentState of one of my component’s was wrong.. This meant I had to go back and rebuild again… however, using FlexTRAMP, I could still set the state, update a few vars, and one method call later, debug a transition I had, which I found needed a slight tweak.

So you see, I didn’t end up doing a build and achieving nothing.

For anyone used to Firebug, or Microsoft’s command line processors, you will know the use of this approach. It’s not a replacement for unit tests, but a very useful tool for when you have to get hacky with some defects, or trail blazing some code.

But I thought Actionscript doesnt have eval?

More...

Flex unit, and asynchronous tests

Thought I’d share this with you..

If you’re using flexUnit and want to test some class or method that dispatches an asyncrhonous event, then this snippet is for you.

I’ve seen this done a few ways, but I recently discovered this neat little feature of flexUnit. If you know this already, then good for you, but if not, let me introduce you to the addAsync method.

Basically, this TestCase method acts as a proxy between you’re addEventListener call and FlexUnit, giving you a teeny bit of extra functionality on the way. The basic use is:

  1. myObject.addEventListener( eventName addAsync( handlerMethod, timeOutInMillisecs ) );

It’s quite straight forward, you provide it with a handler in your TestCase, and if a matching method is not dispatched in the prescribed amount of time, the test fails. Neato.

More...

FLEX EXAM

I’m going for my Adobe Certified Exam in flex later this month. Most people wait till they pass to make it public knowledge. You’re sat next to someone for months, then one day they suddenly come out with : “yeah, I got my ace now”, or you read a blog post “I passed my ACE”.... well, balls to that! I haven’t passed mine yet… I might fail and look like an utter cock in the process! However, at least this way…

  • More pressure on me to pass,
  • I’m being straight with my friends and colleagues, and not just suddenly being like “oh, yeah I was just walking to work the other day and wow! there was this exam hall right there and they just happened to be doing the ACE exam, which I’ve never mentioned to you ever before, and I just happened to be on the register, and just happened to go in and pass, so yeah, yesterday I wasn’t an ACE, but now I am..”
  • At least I can blog about the learning process with some gusto… I wont elaborate, but what man ever takes his missus out to dinner again, once he’s had desert…

I’ve so far found that Lynda.com is great to do a refresher course of what you know – and it’s also really good for learning some new stuff too (despite using fms and flashcom, I’ve not had much exposure to FDS or LCDS). I’d heartily recommend going through their excellent Flex videos. I also recommend reading “flex 2 training from the source” and cribbing on “UML demystified” or another similar title.

There are a couple more things you can do as well. This one chap has made ATTest which is an excellent tool for doing mock exams in Flex – it comes with 3 mini tests and 3 exams, and comes for the bargain price of : £20 ($39)... I heartily recommend it.

I’ve been particularly working with E4X and LCDS, which are certainly my weakest areas. My test is on the 24th – so we’ll just have to see how it goes. I’m hoping that I pass though, not least of all because everyone knows I’m sitting the test!

I’ll keep this blog up to date with my progress and let you know any cool stuff I find.

WISH ME LUCK :D !!

Failing that, give me some good advice!! Anyone else done it? Got any suggestions.. wow – look : there’s a comments form below, just for you!

Flex consulting - a cure for cabin fever.

It’s been a while since I’ve written anything on this blog. There I was, getting my ruby on rails funk on, getting all RIA, with my javascript and flex, and planning a startup or 2 with my good friend Jon Baker, when life suddenly decided it had different ideas.

Since then I’ve been working for Adobe consulting, the last 5 months, as a senior consultant with Flex 2. It kinda happened by accident, but boy am I glad it did :).

I’ve been using Flex 2 for more than a year now, and flash for a long time before, but I hadn’t quite fallen for it, if I’m honest. I was still loving all of my Ruby on Rails goodness, and getting quite agile (no pun intended) with js and programming the DOM.

I was using Flex in a very specific way: Writing portal’s and services in Ruby on Rails and mysql, and having the actual “rich” bit (the app), in Flex.

I thought I’d take the Adobe gig for a bit, then get back to the world of freelance Ruby on Rails, and making sites by my lonesome… but that hasn’t happened. I’ve actually totally fallen for using Flex now: No more messing around with cross browser issues, no javascript worries, no DOM Hassle, and the framework is fantastic : Powerful, and very flexible.

It really is what I like to do – I love ECMA Script based languages, and the frustration of js in the browser for me has always been the DOM, and not the js. With flex I get to do the programming I love most. I still get to do some js, and xhtml, and backend stuff like Java and Tomcat and all that (I’m lucky enough to be using Live Cycle Data Services on a project), so I’m still keeping my finger in lots of pies here, and as such keeping myself interested, and always raising my game..

As for contracting – I gotta say it : I prefer working as an on-site consultant, to freelancing at home. Sure, I gotta wear the trousers and shirt, I gotta be on site pretty much in core hours, I’m not my own boss, but man.. it’s great! I like having to wear smart clothes (I can rip them off when I get home and forget about work), I like being there in core hours (means I can’t procrastonate, or waste time), I like being told what to do – I mean, I still end up getting responsibility for stuff (don’t we all?), but at least it’s not ALL on my shoulders.

Biggest of all though, is that I’m not alone at home, with just IRC. No, let me rephrase that, I’ve got good company at work.. In fact, I’ve got really good company – great colleagues who are not only really really technically savvy and know their shit, but who are a great crack – real great blokes – everyday I feel so lucky to go to work, not only with such great technology, but also with such ( professionally and personally ) wonderful people.

So it’s been a real time of change – changing technology (going toward flex, LCDS and Java from Ruby on Rails and AJAX), changing philosophies and changing fortunes. Its meant I’ve been too busy to update life on rails, but I think now I’m ready to write up some more articles, which I hope others will find useful.

Have I gone all Zed Shaw, and turned my back on rails? Shit, no! I still think Rails rocks, but it’s just not where I want to be at the mo. For the time being, I’ve kinda had it with all the pressure of making sites by myself (and supporting them.. yuk!).. and Rails is particularly good for that. I’m enjoying more being part of the whole, and contributing with others, to create something much better than I could make by myself.

I’m keeping the name of this blog, too: “Life on rails”, clearly a a pun on ruby on rails – but after my wild 20’s, travelling around and doing crazy shit, it’s a reminder to me, if anyone, that I’m on the rails, and for the time being, I’m on them with Flex :)

Hide os x menu bar

Tags: , , ,

I use remote desktop for windows in x11, as it’s the best version out there – believe it or not, it’s still better and faster than the latest version micro$ft released just a few weeks back. Anyhows, one annoyance for me is that the apple menu strip, often times will overlap your windows applications, making resizing them or closing them a bit of a nuisance.

Well it turns out that you can hide the menus strip in os x on an app by app basis.

You do the following.

  1. View the package contents of the application you wish to hide the menu bar for,
  2. Open the file Info.plist in a good text editor,
  3. Add the following to the list of keys:
<key>LSUIPresentationMode</key>
<integer>4</integer>

Bingo!

Your menu bar will now hide whenever you select the app.

Netbeans not just a nice personality

I was googling about and came across this article by Daniel Fischer. I kind of understood what he was getting at and it made me happy because:

a) I take the aesthetics of my working environment very seriously (which was one of the precursors of me leaving windows), and was glad that someone else understands that an IDE should be beautiful,

b) I’d clearly been so in love with netbeans that I had accepted her as “having a nice personality”

It’s true, when I first got netbeans I thought she was rather, how shall we say it…?.. plump, in the gui department. I remember the first couple of days trying to make a few changes here and there.. however, I fell so head over heals for her that I forgot all about this.

Until now.

Daniel called my gorgeous netbeans ugly, and while she’s not the cocoa supermodel that textmate is, I thought that was a little unfair. So, having been familiar with the gui for some time, I decided to trim some of the gui clunk out. Here’s what I came up with: bare gui Click here for a bigger pic

Here’s what I did…

More...

Netbeans THE best ruby on rails IDE

I use netbeans 6, milestone 10 (get it here as my ruby on rails ide now. I’m a mac user, having moved from windows last year.

I was gonna write a blow for blow comparison of netbeans against radrails, but I really see no point. I figured it’s best just to tell you why netbeans’ rails support is so creamingly good, but so you know I have evaluated both and textmate, firstly – here’s some points about the other 2…

Here’s some groovy ruby code completion to wet your appetite. Click more to read the rest of the article:

Image of code completion

More...

Create new file from context menu in finder

Tags: ,

I often take this for granted, but then friends happen to see me do this and always ask me how it works…

Adding a file from the finder context menu

It’s something I missed on os x after years of windows – the ability to create a new document just by clicking the right mouse button. Thankfall Nufile is a context menu plugin which exists for this purpose, it’s donate-ware and can be downloaded here:.

I’ve used it for almost a year without problems. You can customize it to add whatever file types you like, and even provide templates. The help on the website is really thorough, so I suggest you check that out.

Enjoy.

Finder cut and paste

Tags: ,

Having come from windows, I was looking everywhere for this!

Fortunately, some dude called Illari Scheinin wrote a couple of apple scripts that do the job. A link to his website and these scripts is here

He points out some apps you can use to run these scripts, they may be good or not, I don’t know because I use the excellent Quicksilver. If you don’t know about quicksilver, well go download it!

I’ll blog about it more in the future, but needless to say you can store both of these scripts in a suitable folder somewhere, which quicksilver is scanning. I have a folder specifically for apple scripts which I’ve set quicksilver to scan. It’s simply a case of dump these 2 script files in that folder, make sure quicksilver is scanning it, then set up a trigger for cut files.scpt (I did it with CTRL + APPL + X) and one for paste files.scpt (I chose CTRL + APPL + V). You can now select one or more files/folders in finder, and use cut and paste!

HOORAY! and thanks Illari!

Not writing the same js over and over again

I was doing a bunch of rjs stuff in rails, and lots of ajax goodness, and found myself constantly showing, and hiding the spinner and the update element (like a submit button, or other button)..

I’m a bit of a minimalist where possible and like to get rid of as much code as I can, and being as DRY as I can, and so I decided to make the following function:

  1. function updating_field(field_name, finished) {
  2. if (finished) {
  3. $(spinner).hide();
  4. $(update_ + field_name).show();
  5. } else {
  6. $(spinner).show();
  7. $(update_ + field_name).hide();
  8. }
  9. }

I simply call this method from the onclick method, or sumbit method of elements on the page and it tidies up my code considerably.

  1. <input type="submit" value="Save these changes" id="update_avatars2" onclick = "updating_avatars(false);" />

I can then call this code over and over again… In fact, I do, and I have many other helpers similar to this – which I’ll explore in other blog posts.