Method names should explain your intentions

(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com, or follow me on Twitter.

One part of the “agile” philosophy that I really agree with is that methods should have names that reveal their intent. I like this anecdote:

Martin Fowler has a great test to see if his code is clear. He will write code using intention revealing names and straightforward logic but without comments and then give it to his wife to read. Martin Fowler’s wife is not a programmer but if she can get the gist of what’s going on by reading the names and seeing the basic layout he considers the code understandable. If she can’t figure out generally what’s going on in the code he will go back and rewrite it until it is clear.

That’s a good goal to aim for, that a non-programmer can roughly figure out what is going on, because if a non-programmer can roughly figure out what is going, then the programmer who needs to adjust your code in 6 months will have a much easier time.

Post external references

  1. 1
    http://www.agilecooperative.com/2009/08/code-comments-good-or-bad/
Source