Saturday, 16 January 2010

Dependcy Injection and using an IoC container for Unit Testing not Functional Testing

I had to justify at work that there were benefits to using an Inversion of Control container for benefitting Unit testing.

The argument follows in the letter; Comments please.

Hi I'm emailing this to you to let me know what you think it to convince developers to use an IOC container for DI to facilitate TDD.

Many tests that are called unit tests are actually functional tests in that the method under test is in a class that uses other classes and these classes in turn use even more classes.



VERSUS





See href="http://www.javaranch.com/unit-testing/too-functional.jsp


To me a unit test should test a method as that is a true unit. Especially if you are doing TDD as private/internal methods needed to be tested too. Not just APIs of classes and if a high target test coverage is to be measurably achieved then limiting tests to APIs of classes is inadequate.

Now because of our classes using classes that in turn use even more classes, what happens is to test a method we have to satisfy all the dependencies that our method uses not only in the class the method sits in but in all the other classes that method depends on. Thus creating a dependency chain.

These other classes which are dependencies are rarely written by one developer in fact they are often written by several developers of varying abilities and in doing so progamming methods are not employed that facilitate dependency injection.

In particular:
1) Avoiding the instantiation of the dependency in the class itself by the use of interfaces and then using setter or constructor injection.
2) Writing code like classAInstance.classBInstance.property creating a dependency chain and tight coupling.
3) Using Flex's data binding mechanism to pass dependencies through the application instead of setters/getters.
4) Creating dependency chains by having in ClassX object1, in Class Y object1.object2 where object1 was got from ClassX and in Class Z object2.object3. where object2 was got from classY.

This fourth one is particularly subtle in that only when you look at the classes as a set can you often see the problem.
And often arises when we pass a complex object from a service into ClassX and then pick apart this object in classes Y and Z it would also help if we had shallower objects rather than deeply nested ones requiring this picking apart.

To alleviate these it's useful for a class to contain only the things it must have and nothing else.

To develop with this in mind given that we are often given complex objects with sub-objects need parsing and refining before we can use them in a particular method being tested. Often we use a delegateStub that passes in this complex data that is then put through the uravelling process in 4), and then passed to the method under test. However this creates functional tests rather than unit tests and hides the need for doing 1).

For effcient TDD only the objects that the method under test needs should be passed in. This isolation is important as it allows to distinguish more clearly what's necessary for a particular method and what's not, than passing in additional unused data. To pass in this data for a test in a way that doesn't require the unravelling of a delegate stub means having stubs for the method under test and being able to inject this stub or the real thing into the method. This is where a IOC Container is useful as a easily modifiable central and shared repository for all the stub types that all the tests and developers are aware of and can use rather than them being created in several TestCase/TestSuite classes hidden away until the next developer happens to come across the class AND the method within that class. The Container highlights and calls out the data and models being injected and facilitates their use throughout the application by simply using the [Inject] metatag.

Now once our classes are set up so that they can be injected into with concrete implementations of interfaces. We can inject stubs or the real classes that are used in implementation and the configuration that a container provides facilitates this in short. A container allows us to move away from functional testing created by 1)-4) and closer to unit testing.

Thanks,

Comments will be appreciated.

Monday, 14 December 2009

Eclipse plugins for flex development

A collection of useful plugins:
Flex Formatter:
This is an Eclipse editor tool to provide source code formatting for Adobe Flex code (i.e. Actionscript and MXML). the guy ernestpasour a set of formatting options which hopefully covers the most popular coding conventions.
http://sourceforge.net/projects/flexformatter/

AnyEdit:
Plugin adds several new tools to the context menu of text- based Eclipse editors, to output consoles, to Eclipse main menu and editor toolbar. AnyEdit contributes also Import/Export working sets wizards:
http://andrei.gmxhome.de/anyedit/index.html

AIR GEAR:
Is an Eclipse Plug-In which provides RAD development for Adobe AIR. AIR GEAR provides following features:
http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=AmaterasAIR

IDE Factory:
The Source for Enterprise Flex Development Tools apparently currently beta and I don't think this will be free when released.
http://www.idefactory.com/

KeepResident:
Supposed to improve performance by Windows virtual memory manager not keeping resident RAM for eclipses java processes. This is supposed to help with that.
http://suif.stanford.edu/pub/keepresident/index.html

Saturday, 12 December 2009

Power laws in the social economy

Great Article on 22 Power laws that will govern what many see as the economy of the 21st century - the social economy by Dion Hinchcliffe.

http://blogs.zdnet.com/Hinchcliffe/?p=961&tag=nl.e539

Here are the laws in summary:
Amara's law:
We tend to overestimate the effect of a technology in the short run and underestimate the effect in the long run.

Beckstroms law:
The value of a network equals the net value of each user’s transactions conducted through that network, valued from the perspective of each user, and summed for all.

Dunbar’s Number:
150 the number of social relationships that the average person can effectively maintain before overload occurs.

Gilder’s Law:
Network bandwidth triples every 18 months... thus raw communication capability is improving faster than computing power is increasing also means the cost of communication, no matter how complex, is collapsing rapidly towards zero.

Goodharts Law:
Once a social or economic indicator or other surrogate measure is made a target for the purpose of conducting social or economic policy, then it will lose the information content that would qualify it to play such a role.

Hawthorne Effect:
Shows you tend to manage what you measure and goes hand in hand with Goodharts, it states - Subjects in a setting will improve aspects of their behavior being experimentally measured simply in response to the fact that they are being studied.

Hotelling’s Law:
This is a product rule that says it’s natural and rational for businesses to make their products as similar as possible. Even in the age of mass customisation and differentiation this shows the importance of determining what should follow this law and what shouldn't and instead be customised.

Jakob’s Law:
Users spend most of their time on other sites, and so you must be there too. Take a look at the ways you should push your solution rather than pull them to a site.

http://web2.socialcomputingjournal.com/building_modern_web_apps_better_a_have_deep_competency_in_w.htm



Kurtosis Risk:
Kurtosis Risk occurs whenever observations are occur at high frequency at high frequency at normal distribution end tails.

Long Tail:
The Long Tail or long tail is a retailing concept describing the niche strategy of selling a large number of unique items in relatively small quantities – usually in addition to selling fewer popular items in large quantities. The concept was popularised by Chris Anderson in an October 2004 Wired magazine article, in which he mentioned Amazon.com and Netflix as examples of businesses applying this strategy.



Metcalfe's law:
Metcalfe's law states that the value of a network is proportional to the square of the number of connected nodes of the system. Precisely its the triangle number n(n-1)/2 where n is the number of nodes this is proportional to n squared asymptotically. (for large n). See Reed’s Law.

Moore's Law:
Computing power doubles every eighteen months(see Gilder’s Law). However the speed and capacity of storage and communication networks has greatly exceeded Moore’s Law for quite some time now and consequently is driving dislocation in many traditional computing models where processing power used to dominate. Not only is this making distributed computing more attractive and making new techniques possible, the fact that computing hasn’t kept up with the network ensures that the network will continue to dominate as a growth engine in terms of it’s overall ability to deliver real business value. The fundamental (and slightly oversimplified) implication is that business models tied to computing can’t compete with business models that are tied to communication, which as we’ll see with Reed’s Law, is significant.

Network Effect:
Is the effect that one user of a good or service has on the value of that product to other people. When network effect is present, the value of a product or service increases as more people use it.
Enterprise software is now experiencing the network effect of viral, Web 2.0 platforms, and Dion's seen numerous recurring instances of platforms such as MediaWiki pushing larger, established enterprise installations (Sharepoint!!) to the sides of their organizations through simple patterns such as network effects by default.

Pareto Principle:
80/20 Roughly 80% of the effects come from 20% of the causes.
Any complex system, including social ones, and increasingly social and community dynamics are seen as falling under this rule in numerous ways.

Principle Of Least Power:
Given a choice among computer languages, classes of which range from descriptive to procedural, the less procedural, more descriptive the language one chooses, the more one can do with the data stored in that language.
In practice, it has considerable implications for the knowledge economy. Data that is trapped in complex or obscure formats can’t be searched or otherwise processed, and the success of the Web as a content medium has largely been responsible for giving this principle its credibility. HTML and SQL are good examples of this.


Principle Of Least Effort:
Postulates that animals, people, even well designed machines will naturally choose the path of least resistance or "effort".
An information seeking client will tend to use the most convenient search method, in the least exacting mode available. Information seeking behavior stops as soon as minimally acceptable results are found. This theory holds true regardless of the user's proficiency as a searcher, or their level of subject expertise. Also this theory takes into account the user’s previous information seeking experience. The user will use the tools that are most familiar and easy to use that find results. The principle of least effort is known as a “deterministic description of human behavior.”[1] The principle of least effort applies not only in the library context, but also to any information seeking activity. For example, one might consult a generalist co-worker down the hall rather than a specialist in another building, so long as the generalist's answers were within the threshold of acceptability.

Reed’s Law:
Reed's law is the assertion of David P. Reed that the utility of large networks, particularly social networks, can scale exponentially with the size of the network.

The reason for this is that the number of possible sub-groups of network participants is 2^N - N - 1 \, where N is the number of participants. This grows much more rapidly than either

* the number of participants, N, or
* the number of possible pair connections, \frac{N(N-1)}{2} (which follows Metcalfe's law)

so that even if the utility of groups available to be joined is very small on a peer-group basis, eventually the network effect of potential group membership can dominate the overall economics of the system.

Reflexivity (The Social Theory)
In effect action and reaction can feed off each other to create a positive feedback loop that eventually changes the action and reaction and the actors and reactors particularly their expectations and objectives! Explaining the tendency of social systems to move away from equilibrium and often towards extremes (flame wars, viral feedback loops, rapid information propagation, etc including inadvertently falling in love!

Sarnoff’s Law:
Another way to value the network, Sarnoff’s Law, created to describe older one-way networks such as broadcast medium like TV or radio, says “the value of a broadcast network is proportional to the number of viewers.” A more modern version of this is Beckstrom’s Law.

Taleb distribution:
The Taleb distribution is a probability distribution where there is a high likelihood of a small gain combined with a small probability of a very large loss, which would more than outweighs any gain. Taleb distribution is interesting to the social economy for the same reasons as Kurtosis Risk: It can make social business options such as crowdsourcing and other open business models more balanced when looked at in this light because it can appropriately highlight the lack of predictability and identify unacceptable risk profiles.

Thomas Theorem:
The Thomas Theorem identifies a trend that is particularly common within social worlds that any definition of the situation will influence the present. The theorem stresses social situations including in family, business, or other life as fundamental to the role of the participant when mentally creating a social world “in which subjective impressions can be projected on to life and thereby become real to projectors.” This is how social worlds, on a network or otherwise, can take on a life of their own. The reputation and standing of individuals as they perceived on networks, is often very different from what they have in real life. This has implications for HR, promotions, rewards, and motivations in enterprise social computing environments.

Wednesday, 11 November 2009

Unloading Modules

Having spent signigicant time investigating module unloading - I want to highlight the importance of removing focus from the module before being unloaded - see Alex Harui's blog enrty on unloading modules - http://blogs.adobe.com/aharui/.

I tried to set the focus onto something external to my module containing an clickable Advdatagrid however this didn't work so I then ensured that focus couldnt be set on the Advdatagrid not by using ADG.focusEnabled but by setting the selectable property of the ADG to false and then adding event listeners to the column to listen for item click events.

This raised a question finding the item associated with a col when the above properties are disabled the solution was to add a listener to the column as events are still flowing.

the code to get the selctedItem looks like tGhis:

private function firstColumnItemClick(evt:ListEvent):void
{
selectedItem = AdvancedDataGrid(evt.currentTarget).selectedItem;
//first column
if(evt.columnIndex==0)
{
var adgGIR:AdvancedDataGridGroupItemRenderer =
//get the ADGGItemRenderer off the list event
evt.itemRenderer as AdvancedDataGridGroupItemRenderer;

//get the AdvancedDataGridListData open which lives the item property.
var listData:AdvancedDataGridListData = adgGIR.listData as AdvancedDataGridListData;
//set slectedItem to the listData's Item.
selectedItem = listData.item;
//a method to expand the tree node given that you know what item:Object (representing row data)
expandDataGridItem(evt);
}
}


private function expandDataGridItem(evt:Event):void
{
rangerReviewsDataGrid.expandItem(selectedItem, true, true);
}

Tuesday, 28 October 2008

EPSON


This is a custom interactive dynamic carousel I made for the epson homepage while at Sapient. The path of the motion and the easing are all configurable.

http://www.epson.co.uk/

Or in french!
http://www.epson.fr/;

Or in Spanish!!
http://www.epson.es/

Thursday, 13 March 2008

SMILE Mathematics

Here are several older applications that I did at SMILE Mathematics which is no more.

Division Buster
Like the old TV Show BlockBuster but with division questions... Anyway the path checking algorithm was interesting in this!


Nim
The objective of this game is to make sure your opponent is the last person to pick up a pencil I think this game is played with matchsticks but that wasn't deemed appropriate for schools! This game can be played against the computer and again required the development of a logic and a bit of research on the problem to determine a good computer strategy. you'll be hard pressed to beat the comp, and this one does require reading the instructions!


Towers of Hanoi
A classic game that's been seen many times before event on the web. This one records moves and replays them and if you can do three ring easily enough. Change the options.


Enlarging Pentominoes
This is basically a jigsaw but the interesting thing about it is there are several ways to complete each jigsaw this required developing algorithms to analyse that the jigsaw had been completed in a more abstract way.


Building Pentominoes
Similarly as with Enlarging Pentominoes this simple to play game used graph theory to analyse the pentominoes to determine which ones they were regardless of symmetry. So if you created the same shape upside down the program would recognise it. See if you can find all twelve pentominoes!


Darts
Here you're forced to do the maths in this game, one version requires a modicum of skill!


Adds Up To
Again this game required the computer to analyse potential moves - breadth first search - while also preventing the other player from winning.


As did this....Minimax
This requires you to play against and beat the computer using skill this was a good one to do for developing the computer logic for making moves as the numbers come up arbitrarily.The instructions in this are for a different game (The instructions never got finished!) you must try and beat your opponent (try and beeat the computer) by getting either the smallest or largest result.

Frogs
Simple game of can you get the frogs to the other side, this main view is from an isometric perspective. The number of frogs can be changed dynamically and the moves you've made are recorded, tabulated and can be replayed.

Magic Squares
A simple game to play but not so simple to complete. If you like Sudoku you might like this!

Boat
Another nice one to play. Can you get the bugs all other to the other side!

Jugs
This one was another one where the recording and replay was seen as useful.


Some others from way back!
Angle Fit
Maximum Remainder
Tensprint

Wednesday, 5 March 2008

Projects at MRM

I've worked on several projects at MRM Worldwide (www.mrmworlwide.com) Here are some of the more significant ones...

www.msnsearchstar.com

www.msnsearchladder.com

www.microsoft.com/dynamics/everyonegetsit/default.mspx

www.microsoft.com/uk/office/newday/default.mspx

http://int-crackthecode.mrmpweb.co.uk


Answer
0 (Homepage/login)
tcp/ip
1 (top left)
62658591
2 (top right)
0011000100110111
3 (bottom left)
25257
4 (bottom right)
1257632


A True 3d Carousel for a Microsoft Page - used a pretty useful component for this one.
http://www.microsoft.com/uk/amazingoffice/

Another 3d Carousel for the newspaper and marketing association no component this time.
http://nma.mrmpweb.co.uk/brand-landing-page/

An app whose development is near completion is the Unilever - Walls Kids Fun
http://uni-kidsfun.mrmpweb.co.uk/en-GB/index.html
Or if you prefer in French!
http://uni-kidsfun.mrmpweb.co.uk/fr-fr/index.html

Microsoft being a big client of ours has meant that I have been learning Silverlight the first app I worked on being a simple videoplayer. Except that compare to Flash it's not so simple this was done in the older version of Silverlight(1.0) That uses javascript!
http://microsoft-mnp-uk.mrmpweb.co.uk/uk/expression/webharmony/default.aspx
The new version of Silverlight (used to be 1.1 now called 2.0) is out soon. This uses .net languages -and in particular the one I have done some work in - c sharp.

Imagine Cup 2007
This application was developed forMicrosoft as a facebook application it used the user profile pic and the friends pic in conjunction with a .swf and server side code to create and save an image of a friend or users face superimposed on a customisable robot. Unfortunately as it was part of a competition that has now closed its no longer available.