Friday, 29 January 2010

Call a Spade a SPADE!

AAARRGGGHHHH! Once again, I have found myself trawling around some code (ours) which sits on top of someone elses API representation because someone just can't call a spade a spade.

Has the world gone mad over the last year? What is the benefit of making people trawl through some huge long chain of calls just to find out that your asset is (or is not) what you thought it was.

OK, so what is the issue?

Imagine you have Food that you want to describe. Now, each and every item of food is an asset to you.

On top of that, some of those have child 'assets'. So I want to some Weetabix and Banana for Breakfast.

I look in my 'cupboard' (an asset I have) for the Weetabix. What I find is a whole store cupboard full of further 'assets'. So, I check each asset to see if it is Weetabix. I find an asset which is a 'cereal box', containing 24 'assets'. I check its contents, expecting to find Weetabix.

But wait. It also contains 'assets'. Eh? I interrogate the first of these assets, and find that it is in fact a Weetabix biscuit, but what did I miss? Why not have a subgroup or collection name to the cereal box which describes the assets it contains.

It goes further. Someone has taken my fruit bowl away, and instead replaced that with an 'asset'. In this case it tells me it's a bowl, but not what of? Again, I find myself searching down to discover where my Banana is.

And don't get me started on the milk...

I work in a fairly good object oriented world. I accept that objects can have different (and sometimes multiple) class inheritances, (Weetabix is a 'Cereal', which can also be 'Breakfast', 'Food') but why try to force someone to go down from the top - I have an Asset, it is food, that is also Cereal, that I might eat for Breakfast, it contains further assets, which are CornFlakes. That's not the box containing Weetabix then, Great, lets try the next one.
(Of course, finding CornFlakes might make me suddenly change my mind, but my mind 'asset' has had Weetabix coded into it, so I will only accept that today).

There is a reason that Food comes in well labelled cartons (usually). It is so that you don't need to open that carton to find out what is in it (I would imagine Supermarkets not being too happy about that!). I'm all for class inheritance (or Role inheritance in the fantastic case of Moose), but I should be able to get my Weetabix, and then ask questions (should I want to) like: Are you a cereal, breakfast, (an Asset?)?

(It is true that Supermarkets tend to put food into groups, in aisles, but they are usually well labelled as to what you will find in the aisle, you don't need to go down each one).

Rant over. Now, how should I describe Chocolate? Asset, Food, Meal, Essential...


KENTNL said...

Its just annoying when you have somebody in the house decide to reuse the coke bottle for old engine oil, or theres one of those prizes in your weetabix box.

You still have to check that the item you retrieve from the container is in fact the item you wanted, or you might find yourself chewing a plastic toy instead of a weetabix.

( unless of course there were some magical way to prohibit people in the real world from putting items inside a container that weren't what the container was designed for )

Translucent containers have for the most part made our lives easier, making it so we can see into it without the requirement to open it, but its still not enough to discern accurately in some cases ( bottle of water with vodka in it, you cant see the difference ;) )

Also, how is it you know which cupboard in your house contains the container of weetabix? do you have all the cupboards labeled as such? what happens when somebody invariably places a container in a cupboard other than the one you had mentally associated with the weetabix?

And how would you suggest accurately locating all weetabix in all cupboards via a memory system ( becuase computers can't just go "oh, I know where that is", there has to be an algorithm to traverse its own memory to find a given item ). Sure, you could produce a massive global hash table that correlates the term "weetabix" with a path , "Cupboard A, Box Y," but then you have the worry of how you handle such a massive global hash with correlations for all instances of everything.

Running with your theme however of well labeled containers, I guess the best way to find things would be for all container types to be well managed, such that placing anything in a given container updates the containers label to say "there is X's in here" , in a backwardsly recursive manner.

object = Asset( name => 'object' );
fruit = Asset( name => 'fruit' , ancestor => object );
apple = Asset( name => 'apple', ancestor => fruit );
cutlery = Asset( name => 'cutlery', ancestor => object );
knife = Asset( name => 'knife', ancestor => cutlery );

container = Asset( name => 'container', has_childen => 1 );

x = Asset(name => 'x' , ancestor => container );
y = Asset(name => 'y', ancestor => container );

x.insert( apple );
x.contains( fruit ); # true
x.labels; # [ 'apple' ];
y = Asset();
y.contains(cutlery); # true
y.labels('--full'); # [ 'object/cutlery/knife' ]

x.contains(y); # true
x.contains(fruit); # true
x.contains(cutlery); # true
x.contains(knife); # true
y.contains(fruit); # false
x.labels; # [ 'apple','y', 'knife' ]
x.labels('--cluster'); # [ 'apple', { 'y' => [ 'knife' ] } ]
x.labels('--full','--cluster'); # ['object/fruit/apple', { 'container/y' => [ 'object/cutlery/knife' ] } ]

/me shrugs

CAPTCHA: bemona

ramakant said...

Hi, just visited your blog first time, and found it quite interesting. Nice post indeed. Thanks for sharing it to all
Software Development Company Luck now

Andy Brown - SetitesUK said...

RE: Rama - Thanks for the comment.


Thanks for your response. It is great to get someone elses view on things.

The issue I think has come from the fact that rather than expose simple information, the API/code is trying to mimic the underlying structure, rather than a simple 'Real World' view above it. And as such, everytime the underlying structure is changed (optimisation, reorganisation), the API, and code needs to change with it, rather than saying (or at least having some deprecation cycle) we'll keep the API interface the same.

I'm all for Agile development and change, but without some idea of how to ensure that users don't suddenly find they have to take different routes to find the same info, then it is surely easier to call a spade a spade. So as you suggest, something that backwardsly recursively labels an item would be often very helpful.

Thanks again.