Programming By Intention
- When we program by intention
- We reflect on what we intend to do
- We write the simple method first
- We simply say that we're going to create the array of strings by first creating an ArrayList
- Further that we intend to copy it into an array of Strings
- We write the short version of the method
- Then we write the two sub-methods
Key Concepts
Clarity is key in Programming by Intention -- a central idea in XP.
- It means making your intent clear when you write code.
- Have you ever had to work on a piece of code and found that it was hard to understand?
- Maybe the logic was convoluted, the identifiers meaningless, or worse, misleading.
- You say there was documentation?
- Was it readable?
- Did it make sense?
- Was it up to date with the code?
- Are you sure?
- How do you know?
Advantages
- We don't have to remember so much. As soon as we know what we intend to do, we write it down.
- We just refine it until the code is there.
- The Code Emerges Well Factored? without not needing as much refactoring as by other methods.
- We get better code in less time!"