tag:blogger.com,1999:blog-15929719.post9073343026243982291..comments2023-10-21T01:56:53.775-07:00Comments on Van Couvering Is Not a Verb: Why make methods small and do one thing?Anonymoushttp://www.blogger.com/profile/04898259486137280102noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-15929719.post-62611745193039590602009-09-30T09:22:20.937-07:002009-09-30T09:22:20.937-07:00Good to hear from you, Andrei! :)
I'm not sur...Good to hear from you, Andrei! :)<br /><br />I'm not sure if the article is a good example, and yes, you can't apply any rule like a dumb machine. But in general I have found the principle very helpful. If you read a method and its behavior is not clear by reading it, then it needs work. One approach is to refactor out methods that explain what they're doing. The less clear the behavior of a method is, the more likely one is to break it when you change it, or not use it correctly.Anonymoushttps://www.blogger.com/profile/04898259486137280102noreply@blogger.comtag:blogger.com,1999:blog-15929719.post-87520936414900163012009-09-30T04:03:58.966-07:002009-09-30T04:03:58.966-07:00Personally I didn't buy into this "do one...Personally I didn't buy into this "do one thing" advice. <a href="http://java.dzone.com/articles/clean-code-functions" rel="nofollow">This article</a> shows how bad it can get. The problem with the myriad of small functions is that they hide code patterns. The equals() method in the article above is quite readable to me, because it does more or less what any equals() would do: return -1, 0, or 1 in corner cases, otherwise compare the values. In the refactored version there are so many methods that I find it quite hard to tell how they work together.Andrei Badeanoreply@blogger.comtag:blogger.com,1999:blog-15929719.post-44401206266288066692009-09-25T10:23:56.512-07:002009-09-25T10:23:56.512-07:00If you really do have a large method it is helpful...If you really do have a large method it is helpful to extract smaller ones from it, but I think if the extracted ones start being just a few lines and only used by the ex-big method, it's worth considering whether there's really any value.<br /><br />Many little methods can add complexity, if they're not *really* necessary.Jani Hartikainenhttp://codeutopia.net/noreply@blogger.com