I’ve recently gotten used to the idea that extreme ideas are an important part of learning. It seems that when trying to understand an idea, it helps to consider the idea in its most extreme form.
For example, consider the idea of coding in C# with Short Methods. I think most developers would agree with the statement “I like to keep my functions from getting too long.” We came across a function that was 1000 lines long, and were pretty scared of that one. I know many devs who use a screenful as a maximum – if you can see the whole function at once, that goes a long way to helping you understand it.
When I say “I like my functionst to be really short,” I think people assume I mean like 10 lines long. 10-line methods should be easy to handle, right?
What about 5 lines? At this point, most traditional developers are sure that I can’t write anything interesting.
What about 1 line? I’m serious. I have to say “I’m serious” because most people think the idea is crazy. They are sure that you can’t write software that actually does anything if you only get one line per method. But I challenge you to take the idea seriously. Explore what it would be like to write mostly single-line methods.
Even if you don’t write this way in the future, you will have learned something important. When you’re working on an n-line method, you will know how to answer the questions:
- How could I could make this method shorter?
- Should I make this method shorter?
That is, it’s important to fuly explore the extreme case if you want to make the right decision about the normal case.
So, when I propose No Private Methods, that’s because it’s the most extreme thing I could think of. I want to know what that looks like, so that I know when I’ve got the right set of private methods.
Kent Beck talks about this a bit in the first XP book. We know that Code Reviews are a good thing, so why not do them all the time? That’s Pair Programming. Similar statements can be made about most of the rest of XP.
Can you make most classes have only a single field? Or a single ctor? Or a single method besides the ctor? What happens when you do? Do you learn anything interesting along the way?