30 Jan 2012

Order Your Methods to Add Clarity to Your Code

No Comments Programming / Web Development

Recently I’ve been reading Clean Code by Robert C Martin and come across this wonderful piece of programming advice from Chapter 5:

In general we want function call dependencies to point in the downward direction. That is, a function that is called should be below a function that does the calling.2This creates a nice flow down the source code module from high level to low level.

As in newspaper articles, we expect the most important concepts to come first, and we expect them to be expressed with the least amount of polluting detail. We expect the low-level details to come last. This allows us to skim source files, getting the gist from the first few functions, without having to immerse ourselves in the details.

Read more