Long Method

25 08 2011

The longer a procedure is, the more difficult it is to understand. Lots of long methods often lead to code duplication. By breaking these down into smaller methods you can find ways for logic to be shared. Older languages carried an overhead in subroutine calls, which deterred people from small methods. Modern OO languages have pretty much eliminated that overhead for in-process calls. The real key to making it easy to understand small methods is good naming. If you have a good name for a method you don’t need to look at the body.

You should be much more aggressive about decomposing methods. A guide to follow is that whenever you feel the need to comment something, write a method
instead. Such a method contains the code that was commented but is named after the intention of the code rather than how it does it. You can do this on a group of lines or on as little as a single line of code.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: