Smaller

It should be common knowledge by now that smaller functions are generally better functions.  It may well take the same amount of code to get the job done, but by subdividing the functionality into small functions, you have more opportunity to reuse the code.  Additionally, it usually makes it easier to modify the code as well.

This past week, I was adding some functionality to the IDE that I’ve been developing for uCLinux development on Windows (it’s called Fusion – see http://www.fl-eng.com/products/fusion/).  The current version supported application development in the form of one executable or library at a time.  We wanted to support the concept of a solution, so that you could have several libraries or executables in the IDE at the same time.  After looking at all of the locations in that code that would be affected, I guessed that it would take me a couple of weeks to add this and make the other modifications to the existing functionality.

Fortunately, I’m a big fan of small functions and C#.  The small functions let me make some quick modifications to the application-development specific code in Fusion so that it could accommodate solutions.  Adding new functionality allowed me to reuse the small functions that I already had and I created some new task-specific functions to help with the job.  Finally, C# helped me by providing some awesome XML import export functionality.

I can’t speak highly enough about C# and Java in their inclusion of UI and base functionality that just lets developers write the new code without having to reinvent the wheel.  By the same token, every time you write a small, self-contained function that does a particular job, you do the same thing to your own code base.