Showing posts with label Extreme Programming. Show all posts
Showing posts with label Extreme Programming. Show all posts

Code Unit Test First

This practise is also known by many other jargons like Test Driven Development, Test Driven Programming, Test First Design etc.

What is the underlying objective is to let you know that you need to avoid writing a single line of code till you have not written to test it. It is nothing but saying in a broader term that if the requirements are not clear the project will go down the drain. Now take this saying from your QA and apply to coding process. If you doesn't know how to test what you are coding it is actually same as saying I doesn't know what I am coding.

So if you know what you are coding you will be able to write a brief test first. And that will make your coding requirement clear which will enable you to focus on writing only what is needed.

Follow these basic steps

1) Find out what you have to do.
2) Write a UnitTest for the desired new capability. Pick the smallest increment of new capability you can think of.
3) Execute the UnitTest. If it succeeds, you're done; go back to step 1, or if you are completely finished, deliver the project.
4) Fix the immediate problem: maybe it's the fact that you didn't write the new method yet. Maybe the method doesn't quite work. Fix whatever it is. Go back to step 3.

A key aspect of this process: don't try to implement two things at a time, don't try to fix two things at a time. Just do one.

When you get this right, development turns into a very pleasant cycle of testing, seeing a simple thing to fix, fixing it, testing, getting positive feedback all the way.

Guaranteed flow. And you go so fast!

Try it, you'll like it.

Extreme Programming Core Practices

The 12 “XP Xtudes” (Xtude is XP means ‘Attitude’) of Extreme Programming (XP) grouped into four categories

1. Fine Scale feedback

XP thrives on providing feedback at smaller intervals with higher frequency. This allows controlling deviation at the right time, since in software or any othe industry for that matter, once deviation starts happening it is dificult to control at the later stages.

  • Test Driven Development via Programmer Tests (Unit Tests) and Customer Tests (Acceptance Tests/Automation Tests)
  • Planning Game (Definition Iteration Objectives and playfield etc)
  • Whole Team (Onsite Customer + Programmer + Quality Team + Customer Team + Scrum Master + Product Owner)
  • Pair Programming ( two engineers participate in one development effort at one workstation)

2. Continuous Process rather than Batch

3. Shared understanding

4. Programmer welfare

YAGNI

YAGNI perfectly sums up XP (Xtreme Programming). Here is why and how.

"You Arent Gonna Need It" (often abbreviated YAGNI) is an Extreme Programming (XP)practice which states:

"Always implement things when you actually need them, never when you just foresee that you need them."
Even if you're totally, totally, totally sure that you'll need a feature later on, don't implement it now. Usually, it'll turn out either
  1. You don't need it after all, or
  2. What you actually need is quite different from what you foresaw needing earlier.

This doesn't mean you should avoid building flexibility into your code. It means you shouldn't overengineer something based on what you think you might need later on. There are two main reasons to practise YagNi:

  • You save time, because you avoid writing code that you turn out not to need.
  • Your code is better, because you avoid polluting it with 'guesses' that turn out to be more or less wrong but stick around anyway.

A scenario that explains the practices:




You're working on some class. You have just added some functionality that you need. You realize that you are going to need some other bit of functionality. If you don't need it now, don't add it now. Why not?

"OK, Mohan, why do you want to add it now?"
"Well, Rahul, it will save time later."
But unless your universe is very different from mine, you can't 'save' time by doing the work now, unless it will take more time to do it later than it will to do now. So you are saying:

"We will be able to do less work overall, at the cost of doing more work now."
But unless your project is very different from mine, you already have too much to do right now. Doing more now is a very bad thing when you already have too much to do.

And unless your mind is very different from mine, there is a high chance that you won't need it after all, or that you'll need to rewrite or fix it once you do need it. If either of these happens, not only will you waste time overall, you will prevent yourself from adding things that you do need right now.

"But Rahul, I know how to do it right now, and later I might not."
"So, Mohan, you're telling me that this class you're writing is so complex that even you won't be able to maintain it?"
Keep it simple. If you need it, you can put it in later. If you don't need it, you won't have to do the work at all. Take that day off.

YAGNI in the context of the other Extreme Programming practices

You have a Release Plan: each User Story has been assigned to an Iteration where it will be done. Under the current Iteration Plan, you are working on an Engineering Task that you signed up for, in support of one of the Iteration's User Stories. As always, you have signed up for as much Ideal Programming Time as your Load Factor indicates you can accomplish.

You are evolving the system to have the new functionality required by the User Story, defined in the Engineering Task. You add capability to any class we need to, directly growing from the requirement. If you find yourself writing duplicate code, you refactor to eliminate it, even (perhaps) adding an abstract class, or making a subclass, etc. You and your co-programmers always keep the code clean.

You're building a class, and suddenly you get an idea for a feature you could add to it. You don't need it right now, but "Someday we're gonna need ...", you say to yourself.

Keep in mind that you are employing other Extreme Programming practices that allow you to deal with the future when it happens. Collective Code Ownership allows you to change anybody else's code to give it the functionality you want. Refactor Mercilessly and Once And Only Once make it easier to understand the best way to add your functionality. Unit Tests help ensure that your added functionality won't break any past functionality. So if you do need to implement this feature in the future, it probably won't be much harder than it would be to implement now.

At this moment, you have a choice: continue working on what you signed up to do, or begin working on something you didn't sign up to do, and that isn't needed in this Iteration.

Therefore, tell yourself YAGNI. Set aside your thoughts and fears about tomorrow and get back to work on today. Without a clear use for the feature, you don't know enough about what is really needed. Spending time on it is speculative at best.