Sunday, March 23, 2008

Darren on Flex: Binding Expression Clash With HTML Entity-Reference Delimeter

You fellow Flex programmers should know all about the handy binding notation provided as a language construct in MXML. For those that don't know, it makes short work of event-wiring; forget implementing interfaces and defining handlers - just bind it. With binding in mind, recently I tried to bind to the AND logical result but received an error in FB3. This highlights a feature of MXML, that is, the overlap of the symbol/name/token/something-space of embedded AS code and that of HTML/XML. To be clear, I am no talking about (instance) variable namespaces or scopes, Flex handles this seamlessly; what I am talking about is the names for constructs (or maybe it's syntax tokens) in those respective languages. For example see the following code:
<application mx="" model="com.zuhlke.tutorial.hibernate.model.*" creationcomplete="eventDS.fill(events, '', [])" layout="vertical">


In this snippet we routinely assign an expression, in this case a function call, to be evaluated in response to the creationComplete event. Notice that to pass a String (i.e. '') as an argument we have to switch between quoting characters to maintain valid XML - not adding anything new here, this trick is age old. The following example demonstrates what I was trying to do, as described above:
<mx:TextInput id="eventTitle" width="100%" />
<mx:DateField id="eventDate" width="100%" />

<mx:Button id="add"  label="Add..." enabled="{eventTitle.text != '' && eventDate.text != ''}" click="addHandler()" />
This code will not compile in FB3 as the && ie. logical AND operator in the binding expression for the Button.enabled property clash with the entity-reference language construct for XML notation. So with knowledge converting between different logical expressions in the same equivalance class, we can re-write the binding expression such that the compiler is kept happy:
<mx:TextInput id="eventTitle" width="100%" />
<mx:DateField id="eventDate" width="100%" />

<mx:Button id="add"  label="Add..." enabled="{!(eventTitle.text == '' || eventDate.text == '')}" click="addHandler()" />
Now this is really a matter of taste; you can of course use the following instead:
<mx:TextInput id="eventTitle" width="100%" />
<mx:DateField id="eventDate" width="100%" />

<mx:Button id="add"  label="Add..." enabled="{isEnabled(eventTitle.text, eventDate.text)}" click="addHandler()" />
where a function with the signature isEnabled(title:String, date:String):Boolean does the job. Note: it seemed necessary to pass in the text properties of the TextInput and DateField components, I suspect because these are bindable properties, where the components themselves (in their context) perhaps are not.

Thursday, March 20, 2008

What's In The Name

Well here is my long awaited maiden blog (in-joke... on me). As a blog virgin I struggled to come up with a good name for my blog. I thought I'd dedicate this first blog to my thoughts and feelings behind 'It's Not Personal... Well , Maybe Just A Little Bit'.

Firstly, why this name? Not too long ago I found myself toing-and-froing with my company's IT support centre over some (unimportant) issue. This was flagged and raised with my line-manager who gave me some advice, '...take a different stance "It's Not Personal, It's Just Business", don't get so...' blah blah or words to that effect. BTW, Zuhlke IT support are great guys and gals and a pleasure to talk and work with, especially when it that means going to Switzerland, but mainly because they are just a nice bunch. I digress.

Even though I say, '... Well, Maybe Just A Little Bit', I should actually say a 'Huge Bit' - when is it not personal? One of the reasons I decided to work for Zuhlke is it's stance on Agile development. Admittedly on finishing my MSc I knew very little about Agile, TDD or even xUnit testing. In fact my first project for the company was largely a discovery of Agile. The problems found where Agile is not, as described in various texts on the subject, resonated a lot with me. My lasting impression of Agile is that it's a people process (if I can call it a process) much in the same way that software development is a people game. I advocate Agile because in my opinion, it is more humane: I don't want the stress of a defect surfacing the week before a release, when it is way too late to do anything (safely) about it; I don't want to work through the night - I've worked with a client who has done this, literally, to the early hours of the morning - because a defect was found in UAT one day and the release 'has to go ahead' the next day, sod that for a can of beans; I rather not give up my personal time that I'd never get back - I'd much rather go home and watch the next episode of East Enders or America's Next Top Model (or, obviously if I had my way, Top Gear).

Not so long ago I agreed to lead a project that involved flying to and from some other part of the UK. I ended up doing this for what turned out to be a few months; out Monday back Friday, typically. I was able and willing to do this as I am young, free and flexible. No, I'm not single, so yes that means 4 days (or nights rather), away somewhere in the UK that would otherwise be spent with my partner. Of course, there are loads of people doing this, sacrificing time with loved ones to benefit your employer and to get the job done. There is personal sacrifice in there and even though a good employer, like mine, explicitly appreciates such commitment, it is still as much personal for the individual as it is business.

Since leaving university, I have heard various arguments and views on why Java is crap or 'broken by design' or whatever, one such coming from my boss. Now being one of those apparently unfortunate mugs to be reared on Java (I have no problem with it BTW), I used to feel a bit disheartened, perhaps even morose at times, whenever I was subjected to these opinions. Why would that be ay? Maybe due to the emotional investment inherent in my choice to study Comp Sci as a degree for 3 years of my life, learning Java as a consequence and the need and investment made to be good at it to earn my 1st, not to mention the pride therein. And then there's those that so passionately fight the 'Ruby vs. Python' fight, although I haven't heard much of this recently. Then, there's VI vs. Emacs, Windows vs. Linux, Windows vs. Mac and on and on it goes. What's the difference between any of those and a good old Spurs vs. Arsenal battle. They are all laced with passion, personal and emotional investment. I used to work at Tottenham Hotspurs on match days, for 4 years; I remember a middle-aged/elderly couple who made the long trip from Canada once a year, every year, to see their beloved team play football - to them it was a matter of tradition.

If there are any grunts out there reading this blog... have you ever had your head bitten off after touching some code that wasn't yours? Well I have, without any bitterness or resentment. People can get very protective over their code. I imagine in changing someone's code you could be saying 'this is crap', 'what was this dude thinking', 'I have a better idea' or simply 'WTF!'. These are quite subjective or opinionated motives to do something. It could just be that you picked up a different 'How to write good software' book to the original/preceding programmer, thus possibly subcribing to a different philosophy, methodology or approach. I believe my opinion on personal investment in one's choices, as expressed above, also applies here.

Then there is job-snobbery, where there is a definately a difference between snobbery and pride. I remember the conversations back at university in the labs:

Monkey A:Have you applied to Merrill Lynch yet?
Monkey B:No, I'm still on my Goldman Sachs application, but I got in my app to Deutsche Bank before the dealine though.

If it weren't finance, it weren't nothing. Perhaps this is/was some status thing, which I suspect most of us are guilty of to some degree; a display of self-worth or self-esteem maybe.

I recently attended the SPA-2008 conference, which I found on the whole grossly dissatisfying. I did find interesting some of the talks including that given by Michael Feathers of Object Mentor. His talk entitled 'Big Ball of Money, Big Ball of Mud: Economics and Legacy Code' covered various interesting things. A couple of things in particular struck me as relevant to this blog post: He spoke about professionalism and invited the audience to offer definitions for the term. He commented that to be a professional, or at least to be really good at something, you really need to love it - while we don't normally see C++ programmers running around professing their love for their compiler (in honour of the only guy to put his hand up in the 'Awesome Acceptance Testing' session by Dan North and Joe Walnes), I totally agree; Michael also commented that, while it's becoming increasingly rear, some open-source projects in the past have been driven by one-man teams, for example Ghostscript developed solely by Peter Deutsch for 10 years and Emacs by Richard Stallman, both I imagine in parallel with paying work. Michael posed the question, "What codebase would you be willing to dedicate a significant portion of your life to?". Quite a personal question, eh?

Ultimately, I have seen fit to blog about this stuff as I feel tacitly (until now) passionate about it - so how could that not be personal.

Michael: My apologies if I have misquoted you - feel free to correct me. Comments welcome.
Edited: 2010/03/19 - I re-read this and laughed a lot... but cringed a whole lot too. So I fixed a few things, but left the essence of the blog intact, with my fresh out of uni outlook; It's still my truth, for the most part, however many years on.