On Mon, 14 Jan 2002 06:12:18 GMT, Holden Glova <dsafari / xtra.co.nz> wrote: >I wish one of you XP book writers would put an example like this actually in >your books when something like small methods is mentioned :) Thanks for the >example Ron - I had no idea when you said small, you meant that small, but I >like it. We meant that small. I think the Test-First code in XP Installed uses methods about that small, though I don't have it here in front of me. > >Part of the problem I have is, while I'm writing code I'm not exactly >sure what I can call every small section of the code. To me that is very >hard. The trick is intention. The full title of that chapter is "Test-First, by Intention". You're about to write a patch of code. You have some intention for that patch, e.g. "I'm going to restore all the files. Cool, the method name is "restoreAllFiles. And so on. >This isn't to say that I don't want to write small methods, it just >takes me longer to do it. And of course with people like management saying >'go faster!' I definately don't make my methods as small as you have shown >above. I do find it very readable though. Over any period of time I go faster with short methods. However, it takes two passes, sometimes three. Chet and I refactored that code a bit more today, after (a) writing it test first and (b) refactoring it a few days ago. We fixed some other duplication. After you get it into small methods, further development goes faster because you don't have to find all the places where the same kind of change needs to be made: there's only one. That's the Once And Only Once rule, or as Dave Thomas calls his related rule, DRY. (Don't Repeat Yourself). >Same goes for splitting code out >into a new class. Can you show some granularity for your classes? Not yet, for this app there's just the one. I expect to pull one out pretty soon ... > >I wonder if it is also readable because the code doesn't have excess clutter >that I call 'helper' code. Code that is required to assist in your job but >isn't actually the code doing the job. I find there is lots of this sort of >code in Java. There sure is. But I don't call it "helper" code because it doesn't help me. ;-> Ronald E Jeffries http://www.XProgramming.com http://www.objectmentor.com I'm giving the best advice I have. You get to decide whether it's true for you.