Kent Beck`s Two Hats : there are two hats namely refactoring hat and adding new function hat when you wear the adding new function hat, don`t change existing code and think of refactoring. you are just adding new capabilities. You can measure your progress by adding tests and getting the tests to work
When you wear refactor hat, you make a point of not adding function; you only restructure the code. You don't add any tests (unless you find a case you missed earlier), you only change tests when you absolutely need to in order to cope with a change in an interface.
As you develop software, you probably find yourself swapping hats frequently. You start by trying to add a new function, and you realize this would be much easier if the code were structured differently. So you swap hats and refactor for a while. Once the code is better structured, you swap hats and add the new function. Once you get the new function working, you realize you coded it in a way that's awkward to understand, so you swap hats again and refactor. All this might take only ten minutes, but during this time you should always be aware of which hat you're wearing.
Bottom line is that don`t wear the these two hats at the same time
Martin Fowler :Any fool can write code that a computer can understand. Good programmers write
code that humans can understand. :Programming is in many ways a conversation with a computer. You write code that tells the computer what to do, and it responds by doing exactly what you tell it. In time you close the gap between what you want it to do and what you tell it to do. Programming in this mode is all about saying exactly what you want. But there is another user of your source code. Someone will try to read your code in a few months'time to make some changes. We easily forget that extra user of the code, yet that user is actually the most important. Who cares if the computer takes a few more cycles to compile something? It does matter if it takes a programmer a week to make a change that would have taken only an hour if she had understood your code.
When you wear refactor hat, you make a point of not adding function; you only restructure the code. You don't add any tests (unless you find a case you missed earlier), you only change tests when you absolutely need to in order to cope with a change in an interface.
As you develop software, you probably find yourself swapping hats frequently. You start by trying to add a new function, and you realize this would be much easier if the code were structured differently. So you swap hats and refactor for a while. Once the code is better structured, you swap hats and add the new function. Once you get the new function working, you realize you coded it in a way that's awkward to understand, so you swap hats again and refactor. All this might take only ten minutes, but during this time you should always be aware of which hat you're wearing.
Bottom line is that don`t wear the these two hats at the same time
Martin Fowler :Any fool can write code that a computer can understand. Good programmers write
code that humans can understand. :Programming is in many ways a conversation with a computer. You write code that tells the computer what to do, and it responds by doing exactly what you tell it. In time you close the gap between what you want it to do and what you tell it to do. Programming in this mode is all about saying exactly what you want. But there is another user of your source code. Someone will try to read your code in a few months'time to make some changes. We easily forget that extra user of the code, yet that user is actually the most important. Who cares if the computer takes a few more cycles to compile something? It does matter if it takes a programmer a week to make a change that would have taken only an hour if she had understood your code.
No comments:
Post a Comment