agile

Agile is Clean Code

22 Jun 2010
Posted by Federico Zuppa

But ... Isn't this a requirement for all approaches? Why do I have the impression that in Agile, the technical aspect is more important? When I was at University, I remember vividly having heard (and unfortunately later repeated) that the programmer had one of the less important tasks in the chain of producing software. The most important, more senior and smarter people are the architects/designers that analyse and design the application, giving the programmers some diagrams that they 'just' have to translate into code. That seemed like an easy task!!

What means Clean Code?

Ron Jeffries says that we should write "clean code that works". Uncle Bob then made an entire book of Clean Code. What is clean code? Following uncle Bob's explanation, at the high level, it is code that is well structured and which follows SOLID design principles. At a lower level, it's code that has meaningful names, good and useful comments, elegant functions and formatted code. It's code that expresses the intent of the developer in a clear way. It's code that contains no duplication. And is code that is easy to understand.
And how do you know it works? You don't know because you code it and you are a great programmer :-). You know it because there are automated tests that certify it. Agile development relies on test automation to know that features work and to know thay they do all the time. Beck says "Software features that can't be demonstrated by automated tests simply don't exist". Test automation is one of the pillars of clean code because it allows to continually refactor, it allows to redesign and ultimately it allows to deliver a continuous flow of value.

Why is so important in Agile?

These are a few reasons to justify the 'pain' of writing better code:

  1. Cost of Change is lowered: Agile welcomes change, even late in the development process. However, to be able to change, it should be cheap to change. Code that is well designed, easy to read and thoroughfully tested is easy to change and can be changed without fear of introducing new bugs. On the contrary, code that is hard to understand, is not well modularized and has no automated tests is difficult to change and the risks of introducing bugs while modifying it are many.

  2. Iterative & Incremental Development means more time coding: In sequential development, there are big phases of analysis and design before the coding phase starts. When the code phase starts, most of the design decisions should have been taken, so development proceeds fast. In Agile, development starts earlier so this phase takes more time. As the code base needs to be manipulated for a longer time, it pays to have it clean. Reading Clean Code, one of the a-ha moments that I had was in the chapter where Martin explains that in the life of a system, the majority of the time is spent reading code, not writing it. I started thinking about my experience, and that was entirely true. I have worked in many systems that already have a lot of features in it. In those systems, each time that I needed to add a new feature, I spent most of my time finding where to put the feature and how to accomodate it to the existing features than actually coding it.

  3. Iterative & Incremental Development means the code is changed frequently: Design is performed incrementally in Agile. Every iteration, new features are included in the code base. The design of the system should be one that cares about all features included until that moment. Therefore, this means that a lot of times the existing design needs to be modified. If the code is not maintained clean, understanding and modifying it may become difficult in a short period of time.

  4. Working software is more important than Comprehensive Documentation: This is what the Agile Manifesto says. But having the code base in good state, with good comments, good names, well modularized and with a comprehensive set of automated tests is the best documentation that a developer may have. Been able to understand a piece of code easily because it's simple and it expresses its purpose with clarity is much better than going through UML design documents. Being able to run and debug a set of unit tests for certain functionality provides the best tool to understand that functionality. After all, what really happens is what is in the code, not what is in the documentation. Code is always up to date while documentation is hard to maintain.

Why don't we do it then?

Lack of skill? Sometimes... This is a craft. A difficult one and we need to spend a lot of time getting better on it. Commitments.. Yes. Our own commitments and the commitments of our managers. Being under pressure and with the deadlines on sight, make it 'work' takes another meaning (I mean, you just want to throw some code that at least compiles and shows something on the screen). I won't follow. There are always plenty of reasons to do things worse!!

Humm.... but Scrum doesn't include a topic on technical practices

I've seen great debates last year over the lack of technical practices in Scrum. Some people believe it is a shortcoming of Scrum while others say Scrum is a product development framework and therefore it is out of scope to include a technical section. Without entering into this debate, something that I've seen a number of times is software development teams starting 'just' with Scrum, leaving the introduction of some XP practices like TDD for the future (if you take a look the popularity of XP and Scrum, I guess many people observed the same!). This may be justified by an approach where changes are introduced gradually (after all, Scrum per se represents a major change at the organizational and process level).
But what happens if you start with 'just' Scrum?. Basically, I believe Scrum alone is not sustainable. At least, in software development it is not. As iterations go by and the code base grows, there is more and more work to finish each feature. By consequence, teams cannot keep their commitments, the business people get mad and you hit the Scrum Wall (ouch, hit it many times)
This is still a topic I think about often. Scrum, per se, is not sustainable in software development. However, it is the most succesful process in the Agile world. It seems that leaving technical aspects out of it is both something that has help Scrum become more popular and the reason of many of its failures in the development world.

Conclusion

Clean Code is one of the pillars of Agile. Being able to deliver clean code that works greatly enhances the chances of deliver value sustainably and it makes our life as programmers better. Clean code provides the best ROI and the best documentation. Of course it is difficult to do it and it certainly takes a lot more time than writing crappy code. However, by not doing it, we lose a lot of the advantages that Agile claims.

Posted by Jorge Silva

Nowadays, more applications are RIA oriented solutions. RIA (Rich Internet Applications) is a new kind of application with more advantages than traditional applications. It emerges as a combination of features offered by web applications and desktop applications. Even multimedia capabilities are covered because these environments have internal players.

RIA is a new concept that is growing with the advent of Adobe’s product Flex, Flash, OpenLaszlo and the Ajax platform.

The goal of this presentation is to show by example the way to integrate a pure Smalltalk back-end with a flexible front-end made it with Flex, using web services. In this way we:

  • Obtain Smalltalk capabilities to model my business domain

  • Give my application a rich and appealing interface in short time, with many problems already solved.

With this integration we look for best domain modeling techniques with Smalltalk, as reflective capabilities, dynamic typing and, in the other hand, to get the best communicative interface as RIA.

Finally, integrating in this manner is a perfect complement when developing applications not only web but desktop too, because you give the final product a unique dynamism thank to Smalltalk and a rich, friendly and interactive interface as Flex (o more generally RIA).

This presentation was presented at ESUG 2009. You can see the handouts here:

View more presentations from 10Pines.
Posted by Emilio Gutter

Incremental deployment: minimize time-to-market
Since agile processes deliver working software at the end of each iteration (typically around 1-4 weeks) and requirements are prioritized by business value, the organization might choose to release a version of the product as soon as a Minimum Marketable Feature (MMF) has been completed. This way the organization may start to perceive real benefits from the new product far before the development is completed.

Adapt to change
Agile processes are designed to accept and respond to business changes, such as actions done by competing organizations. By means of the dramatic reduction in the feedback cycle length, it possible to incorporate internal customers (i.e. product management; marketing and sales; etc.) and end users feedback into the development plan rapidly and without significant change in cost. Having an agile software development process in place usually represents a strong competitive advantage with respect to other companies using more traditional development methods.

Building quality in
The key of an incremental deployment strategy is to build an automated regression test harness and the discipline to follow best engineering practices such as: continuous integration; test driven development; code refactoring; coding standards; evolutionary design among others. Through the use of these practices the team is able to produce better code, easier to maintain and with less defects. On the other side, permanent collaboration with business representatives helps the team to deliver software that is aligned to the business needs.

Eliminate waste
Agile is a lightweight development process based in a just in time strategy. By eliminating extra processes and extra inventory, the product is developed faster and the cost of adapt to change is minimized. Through a continuous improvement process, the team is encourage to constantly evaluate and adapt the process and the product in order to maximize the value delivered to the customer.

Posted by Emilio Gutter

One of the first steps a new agile team has to undertake is to choose their iteration length. My general advice is to start with 2 weeks iterations, although I let teams choose the length they feel comfortable with. I believe it is better if the team make their own decisions and learn with the experience. I'm gladly surprised when a team chooses a short iteration length, but sadly that doesn't happen very frequently. Usually the main argument I've heard in favor of longer iterations is that shorter iterations are stressful and there is not enough time to finish all the work.

Opposed to this general belief, my own experience taught me that longer iterations are generally more stressful than shorter ones. I believe the main reason behind such experience is related with the complexity in providing accurate estimations. I don't believe there is such thing as a perfect estimation and I'm convinced that high level estimates such as story points are more helpful to forecast than detail estimates such as ideal hours. It is very hard to convince people who come from traditional management about this idea, but as I said before, experience is the best teacher.

Let me give you some examples. Team A works with 4 weeks iterations. The first week they have a promising start and their burndown curve is aligned with the ideal trend or maybe even a bit under it. By the end of the first week the burndown curve starts moving up until it reach the ideal trend. By the second week, it is over the ideal trend and the gap keeps expanding. Inevitably questions comes from everywhere. Why are we getting delay? The Product Owner starts getting anxious and he transmit his anxiety to the rest of the team. The next 3 weeks, the team will struggle to improve their burndown curve. Finally at the last week they decide they won't be able to finish with everything, so they just remove some scope from the iteration and try to do their best to finish with the ongoing work. With a bit of luck, they were disciplined and they started working with the most valuable stories, so they cut off from the iteration the less important stuff. At the end of the iteration the result is clear. They've just passed a very stressing month and they are probably blaming the new methodology which was put in place. Worst thing is probably next iteration won't change much. They have work delayed from last iteration and more pressure to deliver new stuff. Besides there are a lot of hours to fill for a whole month. It is very hard to identify and estimate all the tasks required to complete several stories, specially when they are big enough to fit in a one month iteration. Without much doubts, next iteration the same scenario will repeat: "old habits die hard"

Now let's think in a team which is working with 2 weeks iterations. Team B also starts really well and in the first week the burndown curve is a bit under the ideal trend. The second week the burndown curve have already reached the ideal trend. Although, as the team has planned small stories which can fit in a 2 week iteration and there aren't a lot of hours to fill in only two weeks, the gap between the burndown curve and the ideal trend is insignificant. Besides the second week is also the last week of the iteration. At this point there is not much value in looking at the burndown chart. The team has only one week to finish all the remaining work, therefore it is quite easy to recognize if everything can be finished or not. Working with 2 weeks iteration provides the team higher visibility, reducing the probability of having to adjust the iteration scope. If there was a big mistake in the estimations it will probably be caught very soon and the team will be able to adapt the iteration's plan without having to struggle for another 2 or 3 weeks. Also the team has discovered an important lesson. If they work with 1 or 2 weeks iterations, the burndown chart is not really valuable. By the time you can see some trend in the chart, the end is so close there is no need of the burndown to know how things are going to end up. Little by little they will also discover estimating tasks in ideal hours is not really necessary. High level story points give them all the information they need.

There are many other reasons to work with 1 or 2 weeks iterations. First all the meetings such as planning, reviews, retrospectives, are much more shorter and less exhausting. With shorter iterations there are more frequents chances to re-plan and adapt to change. This is very important, specially for teams who are starting with Agile and need to learn and try new things fast. Finally some good practices turn to be mandatory. For example it is not possible to deliver working software every 2-weeks without a reasonable automated test harness. I found out frequently when teams reject short iterations, they are just hiding other problems (e.g. communication problems between team members; lack of an automated test harness; Product Owner doesn't participate enough; too big user stories; etc.)

Shorter iterations are not stressful; it is just another Agile Myth!

Posted by Emilio Gutter

Distributed Agile - Software for the new world order! is the name of the presentation Matt Gelbwaks and I gave last year at Agiles 2008.

In this presentation we demonstrate through The Maths of Agile why not only small collocated teams can be Agile and we review our experience coaching distributed teams around South America, USA and Europe.

Download the presentation here or watch the videos!

Part 1 of 5

Part 2 of 5

Part 3 of 5

Part 4 of 5

Part 5 of 5