sammyt's posterous http://www.ziazoo.co.uk I wish I got it right more. posterous.com Wed, 12 May 2010 13:05:08 -0700 The fussy type http://www.ziazoo.co.uk/blog/2010/05/12/the-fussy-type http://www.ziazoo.co.uk/blog/2010/05/12/the-fussy-type Recently I have been creating a lot more libraries for the flash player that rely on reflection, dawn being one of those.  I found that my reflection requirements where not easily met with the current tools, and so, Fussy was born! Love it or hate it describeType is the only (almost) way to preform reflection on types in actionscript, it returns a XML document containing information about a type in one big dump! There are a number of excellent and proven libraries out their that can convert that XML dump into a nice OO data structure for you to code against, and it crossed my mind several times while developing dawn that they could make my life a lot easier. I however, created another reflection library... what was I thinking!? Thing is, I have never needed a full strongly typed objected orientated representation of my type! That would be nice of course, but when I turn to reflection its not to create Method and Parameter objects (I'd rather the runtime did that to be honest) its because there are specific things about a type that I need to find. A simple example of what I need reflection for in dawn would be to find all the methods in a type that have been decorated with the [Inject] metadata and have one or more arguments. i.e. all the injectable methods for a Class. Whether the reflection API gives me a XML document or the same information parsed into types I'm still going to have develop a way of finding all the methods with Inject metadata. Maybe that will be with e4x or maybe a loop over some objects (perhaps ensuring that they are methods not variables/accessors), then I will need to check that those methods have some arguments and are thus injectable. So whatever the means the types reflection information is provided by, the actual logic of my task is entirely up to me to develop and test. With all that in mind, I built Fussy to be a little different from current reflection libraries (at least those that I know of). I wanted something to help me query my types, where the query represented whatever I wanted to find out about my types. To show you what I mean by "query", lets see how fussy allows me to find the injectable methods on a type (the problem from above) Start by creating a fussy
var fussy:Fussy = new Fussy()
Now to describe my query
var query:IQuery = fussy.query().findMethods().withMetadata("Inject").withArguments();
Now I can execute that query against any type, and get a array of strongly types Method objects
var methods:Array = query.forType(MyClass);
And TA DA! I have strongly typed method objects that satisfy my query for MyClass.

So what is Fussy?

Seems quite late in this post to be asking that, but I figured it would be easier to explain after an example. I call fussy an actionscript reflection query language. It does of course perform reflection, and parse the result of that reflection into strongly typed objects (only after a query has run) but the main aim of fussy was to make the logic of reflection (the reason why I was reflecting in the first place) easier as faster. Fussy is a work in progress, I still think I can make the query API more elegant and there are lots more query extensions I can think of to add but its already pretty useful. It now supplies dawn with all its reflection needs, and what was a huge proportion of dawns code (searching and parsing types) base has been reduced down to one class. Got lots more plans for Fussy, including things like metadata schema validation.  I find its pretty useful, so figured someone else might too. Oh, here is the github link :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Mon, 26 Apr 2010 10:33:14 -0700 Similar, but different! Private Configurations http://www.ziazoo.co.uk/blog/2010/04/26/similar-but-different-private-configurations http://www.ziazoo.co.uk/blog/2010/04/26/similar-but-different-private-configurations I've just added another feature to the development branch of dawn, called private configurations. So, what are they, and why did I bother? When I first demoed Dawns injector in a LBi tech talk (almost a year ago now) one clever chap asked how it could be used to create a number of very similar, but different objects graphs. I only half got my head around the question at the time, and blurted out something about named injections. Then sometime (and some beers) later after discussing the problem more it became clear that Dawn didn't really have a very elegant solution to the problem. Time to explain the problem (if you've heard of the robot leg problem, thats the one!). How can I create two similar object graphs, with some defined differences without having to create new concrete classes to represent those different graphs (thats what you would have todo today btw)? Example time. Picture a Car class (or just read the one below)
class Car {

  var engine:Engine;
  var transmission:Transmission;
  var driveLine:IDriveLine;

  public function Car(engine:Engine, transmission:Transmission, driveLine:IDriveLine) {
    // set properties etc //
  }
}
Engine and Transmission are base classes that have a number of subclasses like PetrolEngine, DieselEngine, AutomaticTransmission and ManualTransmission. IDriveLine is an interface for the various type of drive the car could have, FrontWheel, RearWheel or FourWheel etc. The Car class itself is pretty flexible (polymorphism is handy like that), depending on how we construct the car we could get a four wheel drive diesel or an manual transmission, rear wheel drive etc. In Dawn today you could create a configuration for your Car and install it into the injector.
class CarConfig implements IConfiguration {

  public function configure(mapper:IMapper):void {
    mapper.map(Engine).to(PetrolEngine);
    mapper.map(Transmission).to(ManualTransmission);
    mapper.map(IDriveLine).to(RearWheel);
  }
}

// then where you create your injector

injector.install(new CarConfig());
Using the above code, every time you requested for a Car from the injector it would create one with a petrol engine, rear wheel drive and manual transmission. *Every Time* is not what we want though! Without private configurations we would have to find a way round this, most likely by creating subclasses of Car, such as PetrolCar, which had a constructor parameter of type PetrolEngine, then the same for RearWheelDriveCar, and so on, until we had classes to represent the varieties of object graphs we wanted. Private configurations are a port of Guices solution (private modules) to the same problem. They allow you to create groups of mappings that are only available under certain conditions. Here are a couple of private configurations for the above problem
class SportyCarConfig implements IPrivateConfiguration {

  public function configure(mapper:IPrivateMapper):void {
    mapper.map(Engine).to(PetrolEngine);
    mapper.map(Transmission).to(ManualTransmission);
    mapper.map(IDriveLine).to(RearWheel);

    mapper.expose(Car, "Sporty");
  }
}
class ChelseaTractorConfig implements IPrivateConfiguration {

  public function configure(mapper:IPrivateMapper):void {
    mapper.map(Engine).to(DieselEngine);
    mapper.map(Transmission).to(AutomaticTransmission);
    mapper.map(IDriveLine).to(FourWheel);

    mapper.expose(Car, "4x4");
    mapper.expose(Showroom, "SUV Land");
  }
}
If the two configurations above were just normal configurations we would have a little problem when we installed then into the injector, since they both create mappings for the same types. So the second configuration to be installed would overwrite the first ones mappings for Engine etc. Also notice that both the private configurations make one or more calls to an *expose* method. Installing private configurations is almost identically to installing normal ones:
var injector:IInjector = Injector.createInjector();

injector.installPrivate(new ChelseaTractorConfig());
injector.installPrivate(new SportyCarConfig());
Installed private configurations do not overwrite mappings within other normal configurations or private configurations. So when we install the SportyCarConfig we have not overwritten the settings in the ChelseaTractorConfig. But how then do we create a car that uses either one of those configurations? Well thats what the expose method is all about! Private configurations are private (hidden) until a special exposed mapping is requested from the injector. Once the exposed mapping is requested the mappings within the private configuration become public, and take precedence over any configurations that already exist in the injector. Lets expand the above code snippet a little to add some default mappings for the IDriveLine, Engine and Transmission.
var injector:IInjector = Injector.createInjector();

// add default normal car mappings
injector.map(IDriveLine).to(FrontWheel);
injector.map(Engine).to(PetrolEngine);
injector.map(Transmission).to(ManualTransmission);

// install the private configurations
injector.installPrivate(new ChelseaTractorConfig());
injector.installPrivate(new SportyCarConfig());
Now if we request a Car from the injector (injector.inject(Car)) we will get the default options:
var car:Car = Car(injector.inject(Car));

trace(car.engine is PetrolEngine) // true
trace(car.driveLine is FrontWheel) // true
trace(car.transmission is ManualTransmission) // true
To activate a private configuration we must request one of the exposed mappings. Ok, lets create a sporty car.
var sportyCar:Car = Car(injector.inject(Car, "Sporty"));

trace(sportyCar.engine is PetrolEngine) // true
trace(sportyCar.driveLine is RearWheel) // true
trace(sportyCar.transmission is ManualTransmission) // true
This time when we asked the injector for a Car we specified the name of the mapping, Sporty. When the injector sees that we are requesting a mapping of type Car named Sporty, it activates the SportyCarConfig, since that is the *exposed* mapping of the configuration! It doesn't matter that the configuration does not supply a mapping for those options (type Car, named Sporty), it just knows that thats the mapping that unlocks it. Now we can create a four wheel drive car
var bigCar:Car = Car(injector.inject(Car, "4x4"));

trace(bigCar.engine is DieselEngine) // true
trace(bigCar.driveLine is FourWheel) // true
trace(bigCar.transmission is AutomaticTransmission) // true
This time we requested a mapping of type Car named 4x4, which is one of the exposed mappings that activates the ChelseaTractorConfig, so the car we get is provisioned with the mappings found in the ChelseaTractorConfig over the default ones. And that in a nutshell is what private configurations are all about. They are a terse and clean way to separate configurations for object graphs which can be activated by special exposed mappings. This is all tested and committed to the dev branch of Dawn awaiting inclusion in the next release :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Wed, 07 Apr 2010 17:48:26 -0700 dawn injectors multi-mappings http://www.ziazoo.co.uk/blog/2010/04/07/dawn-injectors-multi-mappings http://www.ziazoo.co.uk/blog/2010/04/07/dawn-injectors-multi-mappings I just added a new feature to the dev branch of dawn, and since I haven't got changelog files yet (bad sammy!!) I figured I would throw a post up so it doesn't get lost. Seriously though, there will be a changelog :) This feature will make the next version of dawn, unless someone convinces me its bonkers. I am aiming for dawns injector to be a complete injection solution (shiny bells AND whistles!!). Its not doing bad, but there are a few places that some polish wouldn't hurt (better error reporting is a big on one those, its on the way). This latest change was born out of a request from Mr. Tink. He wanted to be able to map one class (in singleton scope) to two interfaces. While such an exciting feat was possible previously, it really required knowledge of factory providers (and consequently some custom code). The new solution is much neater and is as simple as pie... I hope, O.K. an example: Lets say I have a model object that implements a simple interface for views (or mediators or whatever said framework fancies). Simple, except that I also want methods on the object that shouldn't be exposed to the view objects, so those can be added to an interface that extends the original one with the extra functionality.
// for dumb clients things like views etc
interface IAccessData {
  function getMyThing():Thing;
}
// for services/commands etc
interface IChangeData extends IAccessData {
  function updateMyThing(wibble:Wibble):void;
}
class ThingModel implements IChangeData { ... }
ThingModel implements both of these interfaces, and I only want one of my models to be created and that same instance to be injected for anything that require either IChangeData or IAccessData. Previously I would have either had to map to a factory or an instance twice to get this to work, i.e.
// pray it has no constructor dependencies
var myModel:ThingModel = new ThingModel();
injector.map(IAccessData).toInstance(myModel);
injector.map(IChangeData).toInstance(myModel);
or
injector.map(IAccessData).toFactory(ThingModelFactory);
injector.map(IChangeData).toFactory(ThingModelFactory);

class ThingModelFactory { ... blah ... }
Either way, I have to create two mappings and its not so fun. If there was a third interface, or I wanted to also map the concrete class to the same instance it would require a third mapping. In the next version of dawn (already in the dev branch) we can just do this
injector.map(IAccessData).and(IChangeData).to(ThingModel).asSingleton();
Ta Da!! Much easier. Under the hood dawn still creates two mappings, its just sugar coated with the mapping DSL and our lovely 'and' Its also "chainable" (is that a word? I doubt it).. so if I also wanted classes that depend on the concrete implementation of ThingModel to get the same instance,  I could just add another ‘and’
injector.map(IAccessData).and(IChangeData).and(ThingModel).to(ThingModel).asSingleton();
And there you have it, multi-mapping goodness.  There are lots of other things coming soon, I just needed to get that one off my chest. Also worth checking out is the asEagerSinglton scope that just made it into 0.8

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sat, 16 Jan 2010 15:16:03 -0800 commanding dawn http://www.ziazoo.co.uk/blog/2010/01/16/commanding-dawn http://www.ziazoo.co.uk/blog/2010/01/16/commanding-dawn Over the last few weeks I have been trying to improve the documentation for Dawn on its GitHub page. I am slowly making progress (hindered a little by starting a new job) but realise there are still some real weak spots. One area in particular is Dawn's use of the command pattern. I built Dawn's commands in a bit of a rush while completing the project that demonstrated the need for them, so have held back giving them too much formal documentation until I can clean them up and add a couple more key features. That said, I still find them very useful in their current state so thought I'd write this little post to give them more of an airing. There are lots of good reasons for using commands in your applications. They are a proven solutuion for all sorts of common problems in client side development such as queueing, cacheing, batching etc. They are also very useful for performing business logic that spans multiple domains within an application, and thus belong in no one domain alone.

Why make another command library?

Enough of why commands are good (we all know that), why does Dawn contain its own flavour of this oh so common pattern? In turns out providing the command pattern is not a simple as it might seem in Actionscript, at least not if you have some design principles you intend to stick to. Most of the frameworks I have come accross in actionscript provide commands in a pretty similar way, the steps are somethings like this
  1. Create a new object that implements some ICommand interface
  2. implement the execute method, which takes some generic object as its argument. Find a way to get hold of any objects you need, perhaps a service locator (PureMVC) or a singleton (Caringorm)
  3. define some string or event (a string type field) that triggers the command
  4. configure the framework to trigger the command on the newly defined event (one-to-one mapping)
So what is wrong with that? How could that be better? It seems to me that those steps break a number of principles I think are fairly important, it also looks like a lot of work which could go wrong. Take step 1. "Create a new object that implements some ICommand interface". Everyone loves a bit of programming to interfaces! But there a snag here with Actionscript, that ICommand interface will have defined a type for its argument e.g.
interface ICommand{
    function execute(event:FrameworkEvent):void
}
In actionscript there is no way for me to extend an interface and narrow the type of the argument, this for example would be impossible
interface MyCommand extends ICommand{
    function execute(event:MyFrameworkEvent):void
}
What that means is that any commands I write that want to get information out of the event that triggered them are going to have to cast the argument! Type safety FAIL! I want to be able to write type safe commands that know the exact type of their arguments. Step 2. "implement the execute method, which takes some generic object as its argument. Find a way to get hold of any objects you need, perhaps a service locator (PureMVC) or a singleton (Caringorm)" You can probably guess what I dont like about that. Commands are so valuable because they can encapsulate complex logic that involves a number of parts of an application. But commands are stateless (created each time they are executed) and tend to be created by the framework, so how can they get hold of the objects that they need to act upon? In most frameworks I have come across objects that need to be involved in commands either need to implement the singleton pattern - the enemy of testable code! Or register with a service locator, which adds new dependencies on the command to a service locator class and a random string against which the object may (fingers crossed) be registered against. I want my commands to have as few dependencies as possible, I dont want to have to rely on strings to get hold of the core actors in my system, and I certainly dont want to fall into the many traps thats singletons lay. step 3. "define some string or event (a string type field) that triggers the command" Having created this command in framework X I now need to think about how to trigger its execution. I might have to create a new object that extends some base event to do this, or I may just have to choose a string name. I can just about deal with this step, I know that there is going to have to be something that triggers the command (I just dont think string or events are very good choices). step 4. "configure the framework to trigger the command on the newly defined event (one-to-one mapping)" This is where the previous step starts to frustrate me. I have to TELL the framework that the object I just created is the one that will trigger the command. This will most likely look something like so framework.registerCommand( MyThing.NAME, MyLovelyCommand ); There are a couple of things I don't like about that, firstly it depends on developer discipline (I dont have that!), meaning it's up to me to check that the value of MyThing.NAME is what it should be, the compiler won't care if all my NAME properties have the same value!! Secondly it's configuration, and configuration does not rock my boat.

how is Dawn different?

Heres an example of what a typical command might look like in Dawn (in a typical hay making application).
class MakeHayCommand{
   [Inject] public var barn:Barn;

   [Execute] public function execute( note:MakeHay ):void{
      barn.makeHay(note.howMuchHay);
   }
}
There are a few things to note
  • there is no ICommand interface
  • the argument to the execute method is specific to the business logic being executed
  • the execute method has [Execute] metadata
  • the barn variable has [Inject] metadata
You might have already guessed that a Dawn command was not going to implement an ICommand interface.  Dawn tries to make the most of Actionscript by using metadata over interfaces here inorder to preserve type safety. When this command is triggered the method that has the [Execute] metadata will be invoked (this also means that we could call the method anything we like, something more meaningful, like, makeTheHay).  Now that we have an argument that is specific to the business logic being executed we no longer need to perform risky runtime casting. My other major gripe with commands is how core actors within a system are reached, Dawn makes this easy by building upon its dependency injection library.  Just like any other object in Dawn, the command need only specify what it needs by providing the [Inject] metadata.  Dawn will ensure that the relavent objects are constructed/retrieved before the command is executed, so all the logic to fetch domain objects via service locators or singletons is removed, making for a terser more testable command. While all that type safety would be good on its own it also hands us another easy win with a bit of dry configuration.  We (and Dawn) can see the type of the argument of the execute method, so we can completely skip the configuration step (thats the nasty bit where we start defining strings all over the place), the command is implicitly mapped to the MakeHay notification. Setting up and triggering a command then looks much simpler We tell Dawn we have a new command (but skip any mapping step)
commands.addCommand(MayHayCommand);
Since the command system is built on top of Dawns other libraries (DI and notifications) we can just send a notification of type MakeHay to trigger the command.
notificationBus.trigger(new MakeHay(numberOfBales));
and we're done.

One more quick win

Another nice feature we get for free by building on top of the notification system is that any command you write is mapped by type, and types can be concrete classes (like the above example) or abstract classes or even interfaces. Here is a command that will log any notification that implements IResponder
class LogRpcCommand {
    [Execute] public function execute( responder:mx.rpc.IResponder ):void {
        trace("making rpc call", responder);
    }
}

Recap

Hopefully I've gone someway in justifying why Dawn implements it's own command pattern.  I wanted to ensure my code stayed type safe, I didn't want to invent verbose ways of getting hold of objects within the system, and I didn't want to map classes to string. I still have someway to go with them, there is more I want from them (queueing baked in etc) but I already find them very useful, and well worth their place in Dawn.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Wed, 18 Nov 2009 15:45:40 -0800 Dawn at FLUG http://www.ziazoo.co.uk/blog/2009/11/18/dawn-at-flug http://www.ziazoo.co.uk/blog/2009/11/18/dawn-at-flug Last night I got the chance to give Dawn its public launch as I presented it at FLUG.  Dawn is a set of libraries I have been developing to aid my actionscript development.  It consists of three core parts
  • A dependency injection library inspired by Google Guice
  • A notification system based on types
  • A simple type safe command pattern
I built Dawn to address a number of issues that I felt existed in many of the current approaches to application development for the Flash platform.  I hope I went some way to demonstrating how I feel Dawn helps you write testable, type safe and agile code. Thanks to all who attended and for the the positive feedback. Below are the slides I used in the talk, or you can download the keynote file

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sun, 07 Jun 2009 10:25:43 -0700 Looking towards declarative interfaces in GWT http://www.ziazoo.co.uk/blog/2009/06/07/looking-towards-declarative-interfaces-in-gwt http://www.ziazoo.co.uk/blog/2009/06/07/looking-towards-declarative-interfaces-in-gwt I have been doing some work with GWT lately, and there is a lot I really like about it. Developing in Java (or any OO language) not only makes me more productive, it enables me to solve problems in the way I understand, without having first to grapple with how another language requires me to think.  The output is awesome since its rendered natively in the browser, making it fast, and familiar.  Basically there is a lot I really like about GWT, and I'm going to be using it wherever I get a chance from now on, but that not to say its all good.

Mini Gripe

I do have a mini gripe with the current implementation (well maybe I'll have a few, but this one stands out), it's the way interfaces are described in Java.  For all Java's benefits, it remains a verbose language, and developing UI structure with it looks clumsy and hard to maintain, in fact I know it is.  I can say that with some confidence since development  in GWT is almost identical to Flex development. In Flex, if you try to develop all your interface in actionscript you end up in a similar situation. Classes quickly become very large (huge createChildren methods) as many nested components are instantiated and associated with one another.  Fortunately this can be avoided in Flex, as its is better practice to construct your layout using xml, leaving the declarative part of interface development in the language that suits it.  Xml is not just better for interface development because its declarative, it also lends itself to input from other disciplines since many types of developers and designer are used to html as the language of website structure.

Gripe Solved (soon)

That's not the end of the story, as I learnt from the Google Wave: Under the Hood video, where a project named UiBinder is briefly mentioned.  The project sounded like exactly what I am after, and means of defining GWT interface in xml.  After a little hunting I found this document and this post.  Which explain what UiBinder is and importantly where it is (currently only internal to Google, though shortly to be released to you and me, w00).

UiBinder, briefly

UiBinder, according to the docs is a "service to generate Widget and DOM structures from XML markup".  Which after reading the proposal (the document is a proposal for UiBinder as a GWT feature) I figured out basically means it does exactly what I was hoping.  So how does it work? (I've taken the code below out of the proposal document since I cant yet try this myself. humph) First the interface is defined using XML
<!-- HelloWorld.ui.xml -->
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'>
  <div>
    Hello, <span ui:field='nameSpan'/>.
  </div>
</ui:UiBinder>
This describes the interface for a a classic hello world component.  What I particularly like about the approach is how this file is then used from the Java, there are no nasty inline script tags or clumsy code behind super classes.  The template xml file is bound to the Java class explicitly.
public class HelloWorld extends UIObject {

  interface MyUiBinder extends UiBinder{}
  private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);

  @UiField SpanElement nameSpan;

  public HelloWorld(String name) {
    setElement(uiBinder.createAndBindUi(this));
    nameSpan.setInnerText(name);
  }
}
The first line of the constructor is the interesting one, the UiBinder method createAndBindUi is called passing in this as the argument. This constructs your UI components and assigns them to corresponding private variables within the class, making the next line where the text is assigned to the span possible without ever having to directly construct the SpanElement within the java. What you end up with is a very elegant separation of layout from logic.  Cant wait to get my hands on it! If you don't have much patience there are other options, if you take a look to the bottom of the UiBinder proposal there are some links to similar projects at the bottom, though I've yet to look into them.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sat, 16 May 2009 18:59:36 -0700 Installing psycopg2 on Leopard http://www.ziazoo.co.uk/blog/2009/05/16/installing-pscopg2-on-leopard http://www.ziazoo.co.uk/blog/2009/05/16/installing-pscopg2-on-leopard Have been building a site using Turbogears 2.0 of late (which is awesome), and decided it was time to start setting up my staging and production environments.  Thus far I have just been developing locally with sqlite, but in production I want to use postgresql... so tried to install psycopg2 via distutils and was met with the following error
NameError: global name 'w' is not defined
Eek! Finding the solution seemed to take me far too many googles... so thought I’d pop up here so I have no excuse for forgetting next time I do exactly the same For me the solution was to add the following to my path, since I appears that pscopg2 requires postgres to be installed before it can compile (My version of postgres is installed via macports)
export PATH=/Library/PostgreSQL/8.3/bin:$PATH
Once the postgres bin folder was in the path pscopg2 compiled without any troubles. Win

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Wed, 03 Dec 2008 15:42:22 -0800 Woo, I presented at Max http://www.ziazoo.co.uk/blog/2008/12/03/woo-i-presented-at-max http://www.ziazoo.co.uk/blog/2008/12/03/woo-i-presented-at-max I gave my presentation at Adobe Max this morning on building Flex applications with PureMVC.  It was a real privilege to get the opportunity to speak, and I hope those who attended found it useful. I also feel fortunate that I had such a good topic to talk on, as that always makes it easier :) so many thanks to Cliff for doing such a great job with PureMVC In case anyone is interested I have uploaded the slides and the sample code... code slides (keynote) slide (swf)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Mon, 01 Dec 2008 15:33:33 -0800 Day one at Adobe Max Europe http://www.ziazoo.co.uk/blog/2008/12/01/day-one-at-adobe-max-europe http://www.ziazoo.co.uk/blog/2008/12/01/day-one-at-adobe-max-europe The highlight of the first day was always going to be the keynote. Whilst there was nothing revelatory, it was inspiring to see Adobe showcase their products. This was perhaps helped by the impressive circa 30m wide video wall. I particularly enjoyed the talk given by the BBC. The somewhat muted service they provide for non-Windows users has always been a bug bearer for me. I was pleased to hear though that they have been handed a solution to their licensing issues by the DRM support in Air 1.5. This means we can now have the same download manager facilities, along with some notification goodness, wrapped up in a shiny cross-platform AIR app - result. Another demo that caught my eye was a news reader for the New York Times. I was shown the current New York Times news reader about a year ago. It’s a chunky WPF application, so no good to me in Unix land. What it did do very nicely however was display column based text in whatever sized window you might have the app open in. That same functionally is now available (or soon to be, I’m not sure if it’s out yet) in an Air application. This is no doubt made a lot easier by the new text rendering engine within Flash 10, which allows text to flow between containers. For some more info check out this report Ohh, and for general information about the Keynotes go here ta ta ps, I'm also posting on the LBi blog, check it out here

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sat, 01 Nov 2008 17:17:56 -0700 Project Snooze http://www.ziazoo.co.uk/blog/2008/11/01/project-snooze http://www.ziazoo.co.uk/blog/2008/11/01/project-snooze A little while back I started a project called Project Snooze.  My idea was to port the basic functionalty of Hibernate to Adobe AIR, in the hope of making working with SQLite in AIR a much more fun/agile process.  I got quite a way with it back when I was commuting as I worked on the train.  Since then I have let it slip a little but now I've decided its about time I finished what I started! The basic idea is that with a nominal amout of metadata Snooze can create your database, and perform CRUD operations for your objects.  It supports the most common relationship types, one-to-one, one-to-many, and many-to-many, and I am planning to build a querying api into it. If your interested in finding out more about it you can check it out on github... where hopfully you will see a lot of commits from this lazy geek!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sat, 01 Nov 2008 16:51:19 -0700 Speaking at Max http://www.ziazoo.co.uk/blog/2008/11/01/speaking-at-max http://www.ziazoo.co.uk/blog/2008/11/01/speaking-at-max Some exciting news I left off the last post (as I thought it deserved its own) is that I have been confirmed as a speaker at Adobe Max Europe.  Im going to be speaking about building Flex applications with PureMVC, so a lot like the FlexCamp talk only this time I will be going into more detail.... I'm currently trying to figure out how to communicate something quite abstract without sounding dry, or making the usual mistake of just saying something is elegent without backing it up with facts/justification.  Hummm, righto back to keynote!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sat, 01 Nov 2008 15:37:58 -0700 Lazy sammy http://www.ziazoo.co.uk/blog/2008/11/01/lazy-sammy http://www.ziazoo.co.uk/blog/2008/11/01/lazy-sammy Wow, been a while since I did this! Since March (when I last posted) I’ve had a rather busy time.  I have settled into my new Job at LBi (not that new anymore, I started in February 08) and have finally moved to London.. so no more moaning about First Great (really not very great) Western! Here are some brief highlights: Getting published by adobe Seems someone did read my blog after all (though probably not anymore as I have been a little quiet) as I was contacted by adobe after they read my blog and asked me to write an article... you can read it here.  Not sure its very good to be honest... and I might have some different things to say if I were writing it now, but I guess thats all part of the learning process.  Mostly I was just flattered that asked! Building some cool apps Things have been going well at LBi, and I have been lucky enough to work on fairly awesome apps... probably the most exciting has been a platform game for Centrica.  We had a team of 5 actionscript developers working on it, and I think there are somewhere in the region of 1000 class files making it up, so it was no small feat!  Its a PureMVC application, with the physics engine Box2D providing the core of the game engine. Check it out here Speaking at FlexCamp We use PureMVC to build all our apps in the RIA team at LBi, consequently we’ve ended up knowing a fair bit about it.  We got a chance to share some of that experience at FlexCamp the other month.  I presented along with Justin Clark (me boss) on the basics of creating Flex applications with PureMVC.  I was pretty nervous... but I think it went well, and we did get some good feedback on the day. phew... I think there may be more, but I'm hungry! so think its time I signed off and shut up :)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Mon, 03 Mar 2008 20:44:20 -0800 I hate First Great Western http://www.ziazoo.co.uk/blog/2008/03/03/i-hate-first-great-western http://www.ziazoo.co.uk/blog/2008/03/03/i-hate-first-great-western I really really really hate First Great Western!!!!!... I just needed to get that off my chest!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Mon, 14 Jan 2008 14:25:48 -0800 BlazeDS with Spring http://www.ziazoo.co.uk/blog/2008/01/14/blazeds-with-spring http://www.ziazoo.co.uk/blog/2008/01/14/blazeds-with-spring With the release of BlazeDS from Adobe building your business logic in java just became a lot more accessible! In this post I'm going show the basics of setting up a Java, spring based application, then connecting to it from Flex via the flex.messaging.factory.SpringFactory . I'm going to keep the the domain (business logic) as simple as possible, and I'm not going to be persisting anything to a database. This is so I don't get bogged down in details and can get straight to the point... connecting Flex to Java/Spring with BlazeDS.... so here we go! What you'll need. The Steps! Creating The Java
  1. Create a Spring project in eclipse named BlogExample and set the output folder to be war/WEB-INF/classes.
  2. Find the directory you unzipped the BlazeDS download into and navigate to the following directory {blaze install dir}/tomcat/webapps/blazeds/
  3. copy the contents of this directory into the new project (you should have copied two folders, called WEB-INF and META-INF. These folders contain the necessary libraries and config files for connecting to Java from Flex)
  4. Copy spring.jar file from {Spring unzip directory}/dist/ into the war/WEB-INF/lib directory of the project. The project now contains all the necessary library's to connect Flex to Java. However as we are using Spring we will still need one more jar file which we will get in step 9
  5. Next you need to create your business logic, I have created a very simple POJO called SimpleBook.java, which contains two properties with getters and setters (you can download the complete project here which contains this simple class).
  6. Create a new Spring Bean Definition File called beans.xml inside the WEB-INF directory.
  7. Add the following lines to the new beans.xml file, it tells spring to instantiate SimpleBook and set its properties <bean id="myBook" class="uk.co.ziazoo.example.domain.SimpleBook"> <property name="name" value="my book" /> </bean>
  8. Next we need to edit the services-config.xml and remoting-config.xml so that flex can connect to the application. Your can download mine from here (remoting-config.xml, services-config.xml). Be sure to change the endpoint in the services-config.xml to point to your local tomcat server. I have used the tomcat that come with the BlazeDS download as it comes pre-configured to work with BlazeDS.
  9. If you take a look within the services-config.xml you will see I am referencing a class named flex.messaging.factory.SpringFactory which doesn't currently exist in the project. We can get this file thanks to http://www.igenko.org... here blazeds-spring-beta1.jar
  10. Once you have downloaded the blaze-spring-beta1.jar just copy it into the war/WEB-INF/lib folder
  11. Next its time to configure the web.xml file. The web.xml file that come with BlazeDS needs a little tweaking to get it to work with our spring app. Firstly the included file uses the older DTD based syntax, we need to change this to the newer XML scheme method. Once we have done that we need to change the <listener> property such that it fits the spring based development ideas. (The changes essentially allow Spring to instantiate the business classes, rather than letting Flex do it... this is crucial to the whole idea of Spring, and its called IoC, Inversion of Control). Once that changes are made the web.xml file should look like this web.xml
  12. The Java code is now complete, all that remains is to deploy it to the tomcat server, I have done this using Ant, blogging how to setup Ant and starting tomcat are all fairly in depth and very dependent on the system they are being installed on, so I'll keep quite on that. If you are stuck I recommend reading the build.properties and build.xml files in my project.
The Flex I am using Flex Builder 3.0, so these steps will vary for other IDS etc
  1. Create a new project and select the application type J2EE
  2. Set the root folder to to the context root of the java app withing tomcat ie /Users/Sam/Documents/blazeds_b1_121307/tomcat/webapps/blogexample
  3. Replace the contents of the main mxml file with the follow main.mxml
  4. Run the flex app.. and you should see the following
And thats your lot!!! :) OOPS... forgot to upload the full Java code... here ya go Java code

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Fri, 11 Jan 2008 12:17:25 -0800 Flex Cairngorm code example http://www.ziazoo.co.uk/blog/2008/01/11/flex-cairngorm-code-example http://www.ziazoo.co.uk/blog/2008/01/11/flex-cairngorm-code-example Over the Christmas break I finally managed to claw an afternoon of free time together to knock up a little example application. Why bother? Well just about every client I go to meet and potentially work with wants to see some example code first… now since writing code is my job you wouldn’t think that was a very difficult task, but its not quite that simple. Often the projects I work on are very large, worked on by multiple programmers, and dependent on some server side code to run. Even when the projects are small enough to send to someone as an example I’m not even sure I have the legal right to-do so! With the above in mind I though it was about time I created a little application that I could send around to plug my abilities etc, and you can see it here A little about how it works The app is built using Flex 3.0 and the Cairngorm framework. Data is pulled in via XML, and displayed using a simple image viewing component I created. Why use Flex Flex enables me to build the same breed of applications we have all been building with Flash for sometime... only with Flex we can do faster, more reliably, with a fuller api and using a decent IDE... whats not to like? Why Cairngorm Cairngorm is all about building complex RIA's in a consistent MVC manner... adobe puts it like this "The Cairngorm microarchitecture is intended as a framework for Enterprise RIA developers". As you may have noticed the little image viewer I'm using as my example code is no enterprise application, in fact it only has a couple of user gestures, I'm just trying to demonstrate my familiarity with the framework. I think Cairngorm is very important to the Flex developer community, it offers a well proven methodology for building applications, which separates concerns, promotes testability and leads to very predictable, scalable solutions. About the view I wanted to build a little set of classes that would allow me to display items (which could be anything from products to images etc.) in a number of ways, and was simple to extend. The snappyviewer, which is the name of the component displaying the images is an implementation of those classes. The main classes the view is built around are two interfaces IItemView and IItemDisplayer. Both interfaces contain a function named display. The display function in IItemVIew is intended to delegate the displaying of items to the IItemDisplayer via composition. The display function in IItemDisplayer is implemented for various display types, ie, displaying items in a grid, or in a row (GridItemDisplayer & SlideItemDisplayer). To change which type of view the IItemView uses I can set the IItemDisplayer though the dispayer setter function in IItemVIew and hey presto, the view is updated. You can check out the code by right clicking on the application and selecting Source View. Any feedback welcome :) ps.. you can see the application here

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Thu, 04 Oct 2007 09:32:17 -0700 Flex fights back with thermo http://www.ziazoo.co.uk/blog/2007/10/04/flex-fights-back-with-thermo http://www.ziazoo.co.uk/blog/2007/10/04/flex-fights-back-with-thermo Over the last few months I have been keeping my fingers crossed for some real big changes in the Adobe Flex camp, they just arrived! Since I first heard about Flex over a year ago and started working with it I have been very impressed. It’s a great platform for developers to create amazing web applications on… but for me there has been one big elephant in the room, and that’s the designer developer workflow! We’ve all seen Blend combined with XAML now, and if you're anything like me the first thing you thought when you saw it was why on earth cant Adobe do that with mxml!!!! And now it looks like they have with the project codenamed Thermo.
Thermo allows designers to use the tools they love (like the mouse...) and to draw the application as that want it. Thermo will then convert, on the fly (or when imported from a program like photoshop) the graphics into mxml! Perfect! It even allows for visual tweaking of motions and transitions. Its looks the the application I have been dreaming the Flash IDE would become for ages! I personally can't wait to see what comes of this… my hope (and this may be pie in the sky right now) is that we can in the not too distant future say goodbye to the Flash IDE (well, us developers at least). This would enable developers to focus on building applications rather that bullying design into behaving like one! For more info on thermo check out this demo.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Sat, 16 Jun 2007 13:21:18 -0700 yay for events in the display list hierarchies http://www.ziazoo.co.uk/blog/2007/06/16/yay-for-events-in-the-display-list-hierarchies http://www.ziazoo.co.uk/blog/2007/06/16/yay-for-events-in-the-display-list-hierarchies The new event model in actionscript 3 is glorious! At first I didn't really appreciate how useful is was... I was pleased to see that you could create custom events as this, among other things, allows you to send custom objects in events without losing strong typing. Though it wasn't until I came to understand the event flow in display lists that it made a massive difference to my code... (my thanks to Colin Moock for this book, that really helped me get to grips with events in as3)... when you dispatch an event in a display object you can specify a variable in the event constructor (bubbles) which causes the event to propagate through the display list hierarchy, enabling you to listen for events dispatched by DisplayObjects you do not have a direct reference to. This massively helps me centralising my code, de-coupling my code and cuts down on boring code repetition.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Mon, 11 Jun 2007 19:10:54 -0700 moxie makes beta http://www.ziazoo.co.uk/blog/2007/06/11/moxie-makes-beta http://www.ziazoo.co.uk/blog/2007/06/11/moxie-makes-beta More great news coming out of Adobe today... Flex 3 (code named moxie) is now in Beta, and you can download the latest SDK, Flex Builder and Flash player from labs!. I've just had time to play with Flex builder and I'm already impressed.. the refactoring is better than I hoped, it gives you the option to preview the potential changes in a little file comparison window before committing them.. very neat ! Great work Adobe! .... Ooo, I just saw this video on video.onflex.org, it does a awesome job of demoing the new refactoring features!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Wed, 06 Jun 2007 19:03:04 -0700 more books than I can read! http://www.ziazoo.co.uk/blog/2007/06/06/more-books-than-i-can-read http://www.ziazoo.co.uk/blog/2007/06/06/more-books-than-i-can-read I'm loving O'Reilly's safari service... I subscribed last month and since then the learning curve has gone through the roof.. not only do you get to read all the little things you never thought worthy of buying a whole book for.. there are the so-called rough cuts... For me it's all about this book on design patterns in AS3... many thanks to Bill Sanders and Chandima Cumaranatunge for an awesome read!

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams
Wed, 06 Jun 2007 18:48:09 -0700 more Flex 3 from ted http://www.ziazoo.co.uk/blog/2007/06/06/more-flex-3-from-ted http://www.ziazoo.co.uk/blog/2007/06/06/more-flex-3-from-ted Its all about Ted Patrick's blog this week, as more news about Flex 3 is coming out everyday... Today he's blogged on the Components and SDK Enhancements which is all good news... but for me thus far the best changes are those to the code base... refactoring sounds awesome!!.. especially for someone who always makes embarrassing spelling mistakes in his variable names ;)

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/914982/gravatar.jpeg http://posterous.com/users/1l1xELa83dJv Sam Williams sammyt Sam Williams