Git + GitHub + Force.com = Like!

I remember the first time I tried git, just over 2 years ago and just couldn’t get my head round it. So I gave it up and started using subversion which I really enjoyed. Since then I have move onto pastures new and earlier this year started looking into git and GitHub again after seeing the masses of great open source work going on there. So I endeavoured to try again. I found I enjoyed it. Then I introduced it to my workplace and they started to use it and enjoy it to. This post is a collection of best practices, tips and tricks I have found from my use and are a personal opinion only. If you have specific questions following on from this, please comment below or ask me on twitter @pbattisson.

  1. Forget what you know about source control and start learning again. Git is distributed and as such is quite wildly different. It will take some getting you head around the idea of everybody having a repository that is a full system instead of checking in and out, but stick with it.
  2. Use GitHub, they are cheap, they have a fantastic help section, they make coding social and they also help make using git a bit easier.
  3. Use the command line. It will help you understand more accurately what is going on, it is the fastest way to use git and it gives you the most control. And if you are a developer and are not comfortable with a command line then you should be!
  4. Learn how to branch and merge properly – this will help you to really start cooking on gas and make your development effort simple as well as highlighting git’s flexibility.
  5. With Force.com development in a team, use branching and work in your own org. Sharing an org and trying to manage the source control process becomes more difficult. You can easily merge across other peoples changes.
  6. In a Force.com project, make sure you create you repository in the eclipse project folder. Ignore the .settings folder and you should be good to go.
  7. If you do the above, to start working on a project you just clone/fork it into your Eclipse workspace, create a new project with the name of the repo, select none for the initial metadata download and then save all the information upto the server. Easy!
  8. Commit regularly! Push often!
  9. You should per user story or feature you are working on. If multiple people are on a feature, either share an org (for a couple of people) or split the feature into smaller chunks. This will help your code. Remember that a branch is not a separate directory or folder.
  10. All the items you can see in Eclipse are stored in text based metadata files. When merging and fixing conflicts, it is easiest to open the offending file in Notepad++ on Windows or TextMate on Mac. You can see the errors in the merge tags and resolve them from there.

There are a few things I think could be improved though. GitHub recognition for Apex and VisualForce in their code highlighting (I know linguist is open sourced but I can’t say I know where to begin with it) would be a nice start. The Eclipse git plugin needs work (as does the Force.com IDE itself…)  in order to make it easier to work with.

On a side note, I am looking into testing out Jenkins and Stratosource as continuous integration and build systems with GitHub. Anybody got any tricks or tips? I will post something up when I do get one of them running.

Enabling Email Templates in the Winter ’12 Force.com IDE

Update: Thanks to Jon Wu for noticing that the original code wouldn’t compile – wordpress removed the tags for me in a “helpful” way. I have updated the code below to fix this, you can also get it from his gist (which is where I should have put it – will do next time!)

I would like to start this with a big thanks to Andy Mahood, Gary Breavington and Michael Botos for their guidance on this matter which I have expanded upon.

With the release of the Winter ’12 Force.com IDE update, there have been a few teething issues which have caused a number of problems. ONe of these is that it seems when connected to an org you cannot bring down the email templates folder as part of the metadata by default. I tweeted and posted to see if anyone else was having the same issues and thanks to Gary, Andy and Michael I was directed to the following github gist that give an outline of how to change the package file to include the templates.

So the problem with this method is that it can be very time consuming if you have a large number of folders with email templates you have created. Run the code snippet below in the execute anonymous window and it will output some nice XML text for you to copy across into the package.xml file. Easy!

String output = '\n<types>\n';
List<EmailTemplate> templates = [Select e.FolderId, e.DeveloperName
    From EmailTemplate e];
Map<Id, Folder> folders = new Map<Id, Folder>([Select f.Id, f.DeveloperName
    From Folder f where f.DeveloperName != null]);
Set<Id> folderIds = new Set<Id>();
folderIds.addAll(folders.keySet());

for (EmailTemplate template: templates) {
  if (folders.keySet().contains(template.FolderId)) {
    if (folderIds.contains(template.FolderId)) {
      output += '\t<members>' + folders.get(template.FolderId).DeveloperName
                   + '</members>\n';
      folderIds.remove(template.FolderId);
    }
    output += '\t<members>' + folders.get(template.FolderId).DeveloperName
                  + '/' + template.DeveloperName + '</members>\n';
  }
}
output += '</types>\n';
System.debug(output);

Trigger Testing and The Tony Scott Trigger Pattern

Recently, a friend and former colleague of mine posted up a new Force.com cookbook pattern on triggers to help them become more bulkified and streamlined. That pattern can be found here. I can verify that this pattern works really well and makes your code work in a far more efficient manner helping you to avoid the ill fated query errors that can occur.

What I also like about Tony’s pattern is how easy it makes unit testing your triggers. You can test triggers in one of two ways; by using DML operations in your test method that will execute the trigger and exercise the code or if implementing the referenced pattern, by preparing an SObject and executing the methods in the trigger handler upon this and asserting upon the manipulated SObject. This will mean that the trigger methods are run in technical terms without context (you cannot get the Trigger.isBefore method to return true outside of a before trigger running) but it is debatable as to whether you need to test this as Salesforce will have previously ensured this is working. You will have achieved more than a sufficient level of code coverage and ensured your code works by unit testing the methods, before doing a full run through of the trigger in systems integration testing.

Myself, Alex Berg and Andy Ogenoff recently were debating with regards to testing practices and how to handle the situation where you have some code that is written about a particular SObject that then changes (a new mandatory field is added for example). This trigger pattern helps your tests to deal effectively with this, allowing you to test correctly factored methods which are not at the mercy of the SObject changing. Someone could change the SObject in this situation, adding a new mandatory field which will cause integration tests to fail. However, your code, which does not rely upon this new field, will still be tested properly and should not fail.

I know that I will be continuing to use this pattern in all of my work.

Tony is currently looking for UK based Force.com contract work. You can find him here on Linkedin. I can highly recommend him.

A Discussion on Apex Testing

A week ago I read a brilliant post by Alex Berg on patterns for apex testing (you can find it here). We then had a good discussion (along with Andy Ognenoff) on Google+ about the different viewpoints we had around how testing should be done. I then disappeared for a week on holiday formulating a rough blog post on the topic in my head. I also want to make it clear that this is a technical discussion not a commentary on anybody’s work. So here goes.

I am going to start of by generalising the way in which we can go about setting up our tests with data:

  1. Creating the data in the test method inline
  2. Extracting the data creation to methods in the test class
  3. Creating an external class which is a factory for creating data (I will differentiate between variations on this method later)

We will discuss all of these in an attempt to decide “which is best”. Before we start however, I would like to clarify, I am looking at this from the viewpoint of a developer performing unit testing. In his brilliant book the “Art of Unit Testing” Roy Osherove starts clearly by explaining the difference between integration testing and unit testing. It is a difference that I can say I think is often not understood;

Unit testing the is testing of a single unit of code where a unit is defined as a function or method. Integration testing is the testing of two or more dependent units together.

When we are discussing most tests in Salesforce we mean unit tests, testing a single method in a class. When we pull many methods together to move an SObject or piece of data through its lifecycle then we are performing integration testing. Unit testing is there so that when another developer goes and makes a change to the functionality of the system’s code or object behaviour the tests will fail (which is good news) so the system can be refactored properly to allow the existing functionality (if required to occur as well as the new behaviour). These points are key to the discussions.

Creating Data Inline

This is the situation as shown below

   1:  static testMethod void testSomeSituation()
   2:  {
   3:      //Create some object for our test and assign a value
   4:      MyObject testObject = new MyObject();
   5:      testObject.someField1 = "some value";
   6:      
   7:      //Not always necessary but for general case
   8:      insert testObject;
   9:   
  10:      //Perform some assertions on the object
  11:  }

The method creates its test data in lines 4 and 5 before inserting it into the database on line 8 where a trigger or validation rule will perform an action we wish to assert upon. The benefit of this way of performing test data creation is that it is quick and easy, we know any data created by code called during a test method gets automatically destroyed so it is safe to create data like this. However, as soon as we have another test method on this object or in this class using that object, we are likely to have duplicate code. This is evidently bad for when we update methods or objects in the future. This will be exacerbated in the situation where we have to create multiple objects (either related objects or for use in lists etc.) and become unwieldy.

Extracting to a Method

In this situation we extract the code on lines 3-8 to a method for reuse in the test class multiple times (see below):

   1:  private static MyObject createTestObject()
   2:  {
   3:      //Create some object for our test and assign a value
   4:      MyObject testObject = new MyObject();
   5:      testObject.someField1 = "some value";
   6:   
   7:      //Not always necessary but for general case
   8:      insert testObject;
   9:   
  10:      return testObject;
  11:  }
  12:   
  13:  static testMethod void testSomeSituation() 
  14:  {
  15:      //Create an object for use
  16:      MyObject testObject = createTestObject();
  17:      
  18:      //Update the SObject for this test
  19:      doSomething(testObject);
  20:   
  21:      //Perform some assertions on the SObject
  22:      System.assertEquals(aValue,testObject.Field1);
  23:  }
  24:   
  25:  static testMethod void testAnotherSituation() 
  26:  {
  27:      //Create an object for use
  28:      MyObject testObject = createTestObject();
  29:      
  30:      //Update the SObject for this test
  31:      doSomethingElse(testObject);
  32:   
  33:      //Perform some assertions on the SObject
  34:      System.assertEquals(anotherValue,testObject.Field2);
  35:  }

Here we have extracted the creation of the object for testing out to a separate method that is still within our test class. If we wish, we can create many other similar methods for other objects needing to be setup in this test class which will again give us more controlled and useful code.

I believe this to be the ideal situation for unit testing. The data required for any units of code under test is visible near to the code. It is clear as to what the actual test is doing and if the system is edited to alter the behaviour such that the tests fail, then the data is in a central place for updating this area of the codebase to get it working. It also allows any developers that are adding or updating code to the class under test to add new tests quickly and easily with the object needed. You are also adding the minimum amount of required data at all times which is important for speed.

Many will argue that having a centralised set of classes that handles all data creation is better (for integration testing I agree). Let’s discuss this.

Test Data Factory

In this situation we will have a test data factory class that we can call to create SObject instances for use in the tests. This system is the one described by Alex on his blog post.

On its positive side, this means that we have a single class (or set of classes) that we call in order to create some test data. If the system changes then we merely change the data once and this should update every test method where the data is used. It means that the same data is being used consistently across the entire test system as well which is helpful, and if written in a correct way, the data creation methods can be called to provide demo data for salespeople by calling the methods in the system.

The problems arise when we consider the following. Firstly, what happens when someone has two test cases where they needs the data slightly differently in each situation? We could setup the classes so the factory methods take in a series of parameters to create a personalised object, but this removes the power of having consistent data and also leaves us with hard to read code. This data must now also be closely regulated by the development team as any changes to it could have repercussions throughout the system’s unit tests. As the system grows in size and complexity, the factory can get very entangled and difficult to maintain for a series of small tests and can also lead to an increase in the time it takes to run tests. For example, we are writing a unit test that asserts whether a particular field value has been set properly. We do not need any related objects or other data created to perform this test, but it is more than likely that our test data creation methods will create surrounding data by default as it is being used throughout the system. For anyone wanting to go into the system and quickly create a test or update/add some functionality, they must then check the test factory is updated correctly and that this does not impact upon other areas of unit tests – developer flexibility is hampered as the data creation class becomes locked down and protected. In such large systems as well, and breaking of the test data class can cause all the unit tests to fail whether they are related or not as background data that is not needed fails to get created.

Having used this method of doing testing as well, you can find it leads to people writing tests without really understanding what they are doing and why they need it. It is good for a developer to write a unit test where they must set their data up for the test. That way they can know for definite what they have tested and be sure they are happy it works.

I personally employ this method, but use it for integration testing. If a change to the data can cause more that just the unit tests associated to that object to fail, you are not doing unit testing. Unit testing is about creating small piece of data to test small pieces of functionality so that if a change is made to a method, we can check it still works and acts as we expect it to. Having the test data being created in the test class (albeit in neatly extracted methods) allows us to know exactly what we are testing (and why). Having a full data creation factory is much more useful for integration testing as it can create a single set of data for use in testing the system or for use in demonstrations, but without interlinking the system to tightly.


I would love to hear what people think. As I have said, these are personal preferences based upon many hours of writing and fixing tests and also having done testing in more mature languages such as C#.

An aside:

I had a friend who told me the biggest risk Salesforce had was that it is so accessible that non-developers often start writing code and it reminded him of the MS Access boom when many poorly written systems started to fall over as they had been written by people that were not thinking far enough ahead. I am not suggesting that anybody reading this post is like that or that Salesforce should become less accessible. I do however wonder whether we would have a Billion Lines of Apex still if had all been written by people who were pure developers. For another post however.

Coming up on paulbattisson.com….

So it has been a while since I have written anything on here. I feel terrible about this and really want to be writing more regularly and sharing some of the cool things that are going on with people.

So what have I been doing all this time? My last post was in February and revolved around some of the Force.com features that I had found most useful in team based development. I made a short presentation to the Agile Yorkshire user group based upon this post that was fairly well received.  In one of those interesting moments of hindsight I am getting now, I honestly don’t feel the presentation was really that good and if I were to do it again I would completely rewrite it, but the presentation did encourage a few people to look into Salesforce and that is good enough for me.

At work I have moved onto doing some iPad and mobile development which has been exciting, culminating in the recent release of DATASHELTER Mobile for Salesforce. I am now working on other exciting pieces and look forward to releases and launches of these for you guys to see.

There has been some slow emergence of some open source projects I am founding and co-founding for Salesforce developers and users. One of these will be based around the premise of improving the ease of learning Salesforce development for both non-developers and migrating developers. We saw recently
with the hiring of Matsumoto-san that Salesforce is very keen to drive developers to its platforms and is aware that the strength of any platform offering comes in no small part from the way it interacts with and aids developers on it. A large reason that Microsoft were so dominant in the past 20 years is the way in which they looked after the developer community they had. We all remember Ballmer’s developer chant. It is evident that Apple and Android are destroying RIM and Nokia because their development platforms are easy to use. I think Salesforce realise this (and if they don’t they should soon) and as such want to try and help developers utilise the technologies they have in the best way possible. The hope is my little project can help this aim on its way.

Again, revolving around the world of work, we have started using the fantastic GitHub system and I have been given the enviable job of leading the roll out of this. I can honestly say I have never used a more consistently brilliant and quick system. [On an aside, I did try out the GitHub for Mac offering and its nice. It just din't do everything I wanted exactly as I wanted it to though and I did find myself grumbling at its speed and feedback occasionally. It will remain installed and updated, but only get used sporadically. The command line is much more fun anyway.] I have been coming up with a branching pattern and testing it to ensure it fits in with our development systems in the smoothest way possible and hope to start linking Git and Chatter together for our own internal reporting needs.

So I do plan on keeping this more up to date. I haven’t even mentioned the fact I have been playing with Ruby, looking into UX and Human Interface, getting back into some graphic design work and reading a lot into Agile development and complexity theory, Core Animation and re-reading the brilliant Pragmatic Programmer, Refactoring, Design Patterns and slowly working through The Art of Computer Programming. I have started looking at obtaining my DEV 501 status as well and whether I should renew my CSM, obtain a CSP or quit the Scrum Alliance all together.

So expect some hopefully exciting writings soon!

Agile Development on the force.com platform–Some features

For the past year I have been working on the Salesforce.com Force.com platform as a service (paas) and thought I would give an overview as to how it has held up in my experience as a platform for agile development methodologies (most notably Scrum). This will be mostly from a developer and scrum master’s perspective, but I will try to include views from other roles where possible.

rapid application development

To start developing on the Force.com platform, you simply signup for a free development org (which is an instance of their software in the cloud) and you are good to go. I generally attach Eclipse to my org using the plugin that Salesforce provide (you can download this bundled and redistributed as a standalone IDE but I play with other languages so like to be able to use one tool for the many tasks) but through the web interface there is a built in code editor.

Firstly, as you can imagine, this is an extremely quick and easy system to get setup and started on; I can have this all setup and be creating my first objects (analogous to tables in an RDBMS) for use in under 10 minutes – something that I think you will find hard to better elsewhere. This is the first plus point for Salesforce in terms of agile – it is extremely quick and easy so you can get started right away. Often teams tend to have a series of other admin tasks that they have to perform in order to get working, but with Salesforce, your effective “admin” time is zero. If you fancy seeing something amusing for 4 minutes look here. It sums the speed of Salesforce better than I ever could.

Testing, testing, 1, 2…

As a developer who likes to use agile practices, I try to work in a test (or sometimes behaviour) driven way to ensure that I am testing my code as I go. Another benefit of the platform is that in order to publish/package or use some code in production, it must have at least 1% test coverage and the entire code base must average at least 75% coverage! I have worked with a lot of developers before that seem to think (incorrectly) that testing is not an integral part of development, but on the Force.com platform you must do some unit testing. I have sadly seen cases where people have merely “exercised” their code by ensuring it is called in a test method, but as a general principal it serves to try and enforce the correct practices. (At the end of the day my 2 pence is that if you are going to have to write some test methods to cover the code, why not get it to do something useful and add an assert or two? Go on, you will thank me for it later. If you haven’t got proper unit tests you can never do any refactoring, only go changing code blindly.)

Continuous integration

In a previous life doing .Net development I had the pleasure of setting up a continuous integration system. Now I am actually not being sarcastic when I call it a “pleasure” because it was both a great learning exercise and also a magical tool. We could work on a copy of some work in .Net, ensure all our tests and code worked properly locally, then push them to our source control system where it would compile the entire system, run all the unit tests and other tests we had built around it (selenium etc.) and tell us either that everything was all good or that we had messed up somewhere and needed to fix it. This was all done really quickly and speedily and gave great instant feedback on what your code was doing to your overall code base and whether or not your product was always ready for deploying out to a customer (from a purely “it compiles and the code in there works” point of view, some functionality may not have been fully linked together just yet).

When working with the Force.com platform, if you are working on your own the “local copy” you are working on is actually just a copy of the files that are on and running on the cloud somewhere. If developing solo, this is fine as you can have your own source control system where you can deploy your changes from to a fresh org if you want to tests it is all okay. When working in a team it starts to become a little more tricky. Firstly you can’t always work in a single development org (I have worked in groups of 5 or so in a single org and you can nearly guarantee that you will either blow the request limit for a 24 hour period or that someone will be waiting relying upon changes from someone else etc.). The maximum number of developers that can sensibly work in an org is about 3 or 4 if they are working on mutually exclusive tasks, otherwise it becomes a bit more complicated. Often it is easier to work in separate development environments, then merge your changes into a single source control system together. My preferred method is to have the developers agree to deploy the package with the latest code after having committed code to the system. They just simply take a build token to signify nobody should make changes and the job is easy. It is also work setting up a nightly build where the latest code is deployed and tested (through both unit testing and selenium testing). Salesforce provide a great metadata tool to do the deployment and some simple ant scripting gets it all going nicely.

release early, release often

One of the basic principals of any agile development setup is that at the end of an iteration a release with as few a number of bugs as possible (see testing above!) should be available. Again Salesforce have got this covered by allowing you to create packages and now change sets that allow you to make releases available after each iteration. The ideal situation for a team developing a project on the Force.com platform would be to create a beta managed package at the end of each iteration which can be used for user testing, demos and also as a snapshot of where the system is. I have worked with teams and seen situations where development is still on-going on the last day of an iteration, and there is no visible release made internally (or even made at all) in the code base. By having the pressure (for want of a better word) or creating a managed package (75% code coverage and all) you focus on finishing stories/tasks/work and make sure that it is properly done. If you fail to make the cut you have failed to do the work properly. It is a very hard lesson to have to enforce (“but we were so close, honestly it is only an hour or so away from being finished…..”) but if enforced properly you will find your team getting more done of higher quality because the right system is in place. Continuous integration (as discussed above) helps to make this happen. This way you can also ensure that when you tell someone that a release is going to be on a certain date, you can make sure it is.

Logical separation

Salesforce enforces an MVC architecture when using Visualforce (its page mark-up language) and Apex in a controller. There are also triggers which handle work done on or with an object before and after update/insert/delete (validation, creation of related objects etc.) There are also components that can be created by a developer in order to reuse pieces of work. More recently as the Salesforce governor limits have started to be relaxed further and further, more traditional design patterns (such as those by the GOF or Martin Fowler) can be implemented alongside the newer patterns that have been developed for working on the platform. These combine to make it very easy and logical to separate out your code into correctly structured layers and provide yourself with patterns for use in the future. There is even dynamic apex to help further this extensibility in providing correct layer structure for your code. Add onto this you don’t have to do anything with a database (as it is already there and provides you with a large portion of your object structures) then correct layering and code practices are hard not to do.

Summary

Hopefully this somewhat brief and not fully comprehensive post has helped you to see some of the awesome features that Salesforce have setup in order to help you become a better developer and help you develop in an agile manner. Please feel free to post comments or suggestions for additions and I may either add them or create an entire new post to entail all those things I forgot.

Force.com Certified Developer – Experiences and Thoughts

Today I became an official Certified Salesforce Force.com Developer after passing their 401 exam. I have been involved in a lot of discussions about the controversial “Certified Scrum Master” certification and thought I would post a few thoughts about the Dev-401 examination to draw a few parallels and comment on how I found the exam. Also to pass on any hints or tips I would have to those thinking of taking it.

Background

For the past 12 months I have been working for one of the leading ISVs on the Force.com platform, being privileged  enough to have spent my first 12 months on the cloud learning from some of the best guys out there. I have recently decided to move onto pastures new and one of the requirements of my new role was that I become certified in order to provide a certain level of comfort not only to my new employer, but also to their clients.

I was chatting to one of the guys I used to work (who is now enjoying life contracting on the platform) about the certifications and we were questioning the usefulness of the certifications (we had both written some code on the platform that was pushing the boundaries when it came to what Salesforce expected, working for one of the biggest ISVs. Why did need to pay $200 to show how good we were?) We had both previously seen things like the Microsoft certification, and I myself had gone through the Scrum Alliance CSM process (I found it very useful for me, although I would never dream to say it made me an expert by any stretch of the imagination). Was the Salesforce certification really as they had suggested, a good way to sharpen your skills and keep the quality of work done on the platform high? Or was it a nice license to print money?

The Exam

The exam is a series of 60 multiple choice questions for which you are given 90 minutes. I managed it in 30 minutes without breaking a real sweat – I am not bragging, but I am trying to say for anybody with a strong level of understanding of the platform, you will not be pushed for time.

Please take note though – you will need to work at the material for this exam. I learnt an awful lot in preparing for it (perhaps that was why I managed to get it done fairly quickly?) which adds some brownie points to the certification. It makes you really understand the roles and sharing model, object access levels as well as have a meaningful understanding of how different object relationships work and the workings of reporting and dashboards.

I expect there are a large number of developers out there who, like myself have spent and invested a large portion of their time in honing apex and visual force knowledge, but have partly missed one of the key points of the Force.com platform – you don’t have to write lots of code lots of the time.

It was a really challenging and enjoyable exam which I would recommend to people. You will be mentally taxed and highlighted if you don’t know your stuff, but you will be better for it. I am now looking forward to investigating the 501 classes and exams in the New Year.

sf_cert_dev_rgb

Recommended Materials

Force Prepare A brilliant resource I have now bookmarked just for reference with a fantastic mock exam.

Force Certified Another must read for those serious about the exam.

Salesforce Made Easy A really useful website with some nice quick tips.

The entire Dev-401 class videos on iTunes. Watch them, make notes.

The Study Guide for the exam.

A good mock exam from ProProfs.com.

Think About Something Different

Apple famously stated we should “Think Different”. I think they were close but were missing the words “About Something” in the middle.

We should try to constantly challenge ourselves, look at new problems that we haven’t considered before, and in doing so we can find new ways of solving existing problems. The wider your set of experiences, the better equipped you will be to deal with new situations as well as deal with existing situations in a new and possibly more innovative way.

Just go out, learn new things and improve the way you are doing current things.

Here’s to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They’re not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them. About the only thing you can’t do is ignore them. Because they change things. They push the human race forward. And while some may see them as the crazy ones, we see genius. Because the people who are crazy enough to think they can change the world, are the ones who do.

Thinking of Your Software Project as an Investment Portfolio

Ward Cunningham in 1992 coined the term “Technical Debt” to describe something done (or not done) during the software development process which will require to be worked on in future, possibly at a higher cost. For example, I write a nice new class but do not do any refactoring or unit testing. In 6 months I do not touch this class before then having to use it in a new piece of functionality. Changing this class can then cause a myriad of problems for the system, and so I am paying a lot more for the work than if I had invested some time before hand.

I recently read a blog post Steve Freeman wrote entitled “Bad Code isn’t Technical Debt, it’s an unhedged Call Option”. I really liked this idea for a number of reasons. Firstly, it is a bit nicer to play around with mathematically (more on this later) and secondly, as his brilliant post describes, it is a far better analogy for what we are really talking about. I also like this viewpoint however because it counteracts the way we consider debt in western society. We see debt as something that is acceptable as long as it is managed, and we consider it fixed and managed. We can pay the debt of incrementally when we wish and there is a pretty (generally) small interest rate and linear growth pattern. This as anybody who has worked on a piece of software for more than one version will tell you is certainly not true of “Technical Debt”.

Whilst at university I studied a couple of semesters worth of lectures on financial mathematics and I remember learning about call and put options as well as their involvement in a portfolio (and stochastic processes in some situations). As is natural then, Steve’s post got me thinking, if technical debt is a call option, then what analogously is a put option and can we consider our software development project to be somewhat similar to an investment portfolio? (Here we begin to stray into some wonderful theoretical musings on software development as a complex non-linear dynamical adaptive process. But we shall save that for another day.)

Firstly, let us clarify a few things. The underlying asset I am describing here for our call or put option is effort, which we can measure in hours, story points, bananas or any unit of work that it takes to develop a piece of software. Obviously this itself is a loose concept, as the effort on a piece of work varies through the project lifecycle, but we will use it as it is a concept we can understand.

Taking a call option out on this is then a management process:

“Management will pay a premium up front (in terms of hours of testing for stability or extra documentation/customer support) to take out a call option on a piece of code, hoping or betting that the price of effort to work in that area has not risen too high if the option is exercised (they wish to work in that area with new functionality again).”

If such an analogy is true then we can use the notion of a put option to be the following:

“We pay a premium up front (in terms of effort spent refactoring, unit testing etc.) to take out a put option on a piece of code, expecting that the price of effort to work in that area will rise to make the premium paid worthwhile (effectively negated).”

If this is a correct viewpoint (which I believe is logically sound) then we can consider our project or work on a piece of code to be somewhat similar to managing an investment portfolio by buying a series of different put and call options to achieve the maximum return on investment with the minimum risk available. We will want to do as much work as possible in making the software stable and extensible later on (put options) yet we understand that there is always some risk taken when having any software.

I would love to be able to determine some sort of price for code smells (or use a rough story points estimate based upon some team values) to see how best a portfolio could be managed. I have spent some time already on paper messing about with this, and will hopefully sometime be able to jot something up here. I was also looking into modelling agile as a crude non-linear dynamical system, so don’t expect anything too soon ;-)

How The Agile Coach Can Learn From The Special One

I am a big football (soccer for Americans) fan. I regularly attend matches for not only my team but others as well as watching any football I can find on TV. I love the game, and the thing I love most about the game is the managers. I am often asked by my girlfriend why it is that when a team is having a run of poor form, instead of replacing the 11 men on the field they fire and replace the one man off the field? Simple, he is there to facilitate them achieving all they can, removing any impediments that stand in their way, similar to an agile coach.

For example, any person who has made it to the rank of professional footballer has a good level of skill at the game. We can assume they are able to kick a ball in a straight line and know what they are doing. It is the manager however that coaches them at putting their requisite skills together in the right way, of freeing the team’s mind of anything else than how they can effortlessly do what they do best. By setting the team up in a way where they feel they are as prepared as possible and can use their skills in the fullest manner possible, things can be achieved (Blackpool and Holloway I am looking at you).

The “best” football possibly ever played was by The Ajax team from around 1970 – called Total Football. This tactical system can be stated as follows:

“Total Football” is the label for an influential theory of tactical association football in which any player can take over the role of any other player in the team.

Now to me that sounds like a team that is cross-functional! No specialisations, everybody able to pitch in where needed at any time and all working cohesively together towards a common “goal” (sorry for the pun!)

So why should I have mentioned this quite evidently obvious fact? Playing the best most attractive football won’t necessary win you matches. You have to work hard improving as a team before you can get there, you will not just become a team going from playing route one (hit it up field and hope) football to suddenly being a team that is playing such glorious football. You have to train the players in the right way, alter their thinking and work hard at it. More importantly perhaps, you have to get them into the habit of winning.

Winning is a habit, and this is the same for an agile team, winning is habitual. Winning in football means scoring more than your opposition and taking home 3 points. Sometimes however, a victory can mean getting a draw, and sometimes it can just mean survival. In an agile team often people focus too much on “becoming agile”, “being an agile team” etc. You need to understand where you are starting from, and get the technical skills being improved upon, working on the process of development (your tactics and strategy) and accepting your victories as they come on the journey. For a team with no unit test coverage,  adopting TDD and achieving 75% on all new code will be a major achievement,  for a more experienced agile team, anything less than having obtained 100% coverage and completed all signed upto stories (being the ideal team we read about) will be classed as a failure.

The job of the agile coach is to put the team on the right track, helping them to start passing the ball more fluidly and moving in a more co-ordinated manner. It is not a job that is the coach’s alone, everyone in the organisation needs to prepare and practice for success, but it is the coach who will have to bear the brunt of this.

I want to finish this article by talking about Jose Mourinho, the Special One. As a Man Utd fan, he is a man I have loathed greatly, but he is someone who I look to as an inspirational coach, and as a brilliant agile coach. He diverts all attention from his team by being loud and brash removing the impediment of the media and allowing the players to focus on football. He consistently reiterates his philosophy of winning, of training right and playing in the most effective way against his next opponent (and it isn’t often/always pretty football). Most importantly is the moniker he has given himself, “The Special One”, which he truly believes he is, and after his successes, so now does every manager and player on the planet. He has garnered a respect and aura amongst his team that they are instantly uplifted by his presence and believe they are champions. A good coach knows how to inspire their team. You don’t have to do it in the same way, but you have to be able to get that belief instilled in the team members that they can do this. Remember it is about helping the team to do the best they can, and a person who has belief in their system and skills will always perform to the best of their abilities, and write some damn good software.

Be Champions!