Wednesday, October 31, 2012

Improve Your Progamming Efficiency by Routine

For those new programmers, including me, it is very fascinating and exciting if we can create new things and make them work. After solving some struggle or tricky problems regarding to the codes and finally get what has been expected, we attempted to be satisfied enough that there is no need to fix or change since it just works fine.

The book called 'Code Complete' suggests us that if we already know how to program, then the next thing we need to know would be how to program efficiently. In order to become efficient, the book specifically suggests us to make use of routine.

What is Routine?

As the book 'Code Complete' states,

A routine is an individual method or procedure invocable for a single purpose.
The book also mentions that we can evaluate routines we create as 'high-quality' or 'low-quality', and programmers can create efficient, faster programs in an efficient way by focusing on this notion of routine.

This is because the main purpose or the focus of making use of routine is to reduce unnecessary parts from your program and so create very readable, less complex, and faster program.

Hints to Create Useful Routine

Here are some points I personally think are especially important from the book:

  1. Name properly; Easily understandable, yet tells you what a routine does.
  2. One purpose per routine; Keep simple. Just like each method in Java is supposed to have only one functionality
  3. Try to shorten each routine; The book suggests less than 200 lines is appropriate.

Having mentioned some of the ways to create and make use of useful and efficient routine, let us not just satisfy ourselves by knowing how to create things; let us satisfy ourselves by knowing how to create efficient programs efficiently.


  1. Did the book really say less than 200 lines? :-) In the agile RoR world less than 20 is recommended - ideally less than 10. Code complete has great tips on coding, but it's slightly back to front from the modern BDD, TDD agile approach, which says that you want to write your tests first, and then fill in your code in your method (or routine or function). In Rails if your controller method is exceeding 10 lines of code that's a warning that you might want to think about pulling that code out into the model, or a supporting library ...

    1. Oh I see.. I might mixed some thoughts and concepts somehow...
      Ideally less than 10 lines of code is recommended in the agile cycle.. I see..! :)