Coding in the Train

Since the start of this year, I travel to work using the train, which gives me about 30 minutes of programming time (more or less). I use this time to advance my PhD project, the Object-Process programming language. The short time span creates new “constraints” on my work:

  1. I have found that have to tackle very small problems to be productive
  2. Context switch is very strong. I need to enter into the code fast, otherwise the whole trip is wasted

To my greatest surprise, I have found that I’m writing much better code now because of this!

First of all, my functions have become very short, because I try to solve one and only one problem at a time. The names of my functions have also improved a lot (from my humble point of view), again, because I don’t have time to go to the function and understand what the function does – all the information I need must be provided by the function name and its parameters. For example, if I previously named a function findEventProcesses, now I call it findProcessesToInvokeAfterObjectHasChanged. If before I had one big function (say 20 lines) called createFollowingWaitinginstancesFromEventLinks, this function is now 4 lines and calls using another function called findFollowingProcessesFromEventLinks (8 lines), which in turn calls findProcessesToInvokeAfterObjectHasChanged (8 lines). Each function solves only one problem, using other helper functions.

Code duplication in my codebase has also been reduced impressively, I guess because of the short length of the functions, which makes them more generic therefore more easy to reuse them.

Just sharing my experience.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.