Make your methods stupid

May 13, 2006

Gems of wisdom from Alex Sharp’s Smalltalk By Example (free download!)

“A stupid method is one that is so obvious that it doesn’t need any documentation. The problem with documentation is that it makes a method longer, so if you have a method that is long enough to need some serious documentation, you compound the problem by making it longer and less able to fit on a screen. Not fitting on a screen, it is less readily grasped by a programmer. The ultimate compliment of a method is ‘that method is really stupid.’ ”

and

“It’s not always easy to come up with a great method name when you are looking at the method itself. It’s when the method is being invoked, when you are doing the message send, that you’ll get the best idea of how good the name is. If it makes sense in the context where it is sent, then you’ve probably got a good name. So, while it’s okay to name the method when you are writing it, be prepared to go back and change the name after you use it in other methods.”

So much of this book applies to Ruby as well, even if Smalltalk is coming back… again. Just gsub!(/Smalltalk/,’Ruby’).

Leave a Comment