I work for an international company that operates mainly in the maritime and offshore industry. Recently, I got involved in multiple projects that had something to do with data analysis. While the projects were initiated by different research departments, they had one important thing in common. The data was ‘dirty’ and stored in thousands of text files and excel files. With ‘dirty’ I mean, that sometimes the files were ‘corrected’ by hand, sometimes they were completely created by humans, and worse of all, they had many slightly different templates.

When data and layout are mixed, it can get really hard to program an algorithm that interprets the data automatically. The scripts that were available, were programmed in a procedural way. Because of the irregularities in the layout, the engineers had to change the code over and over again, to deal with each new exception. I probably don’t need to tell you, that each time you do this, your previous code is likely to break.

So this is were the idea for the macro-command originated from. Off course, it’s nothing new. It is the good old command pattern, which is widely used in all kinds of software. But to implement it in nodejs, was quite a challenge. (for me at least) I’m quite sure that similar and even better solutions  must exist already, somewhere…, but I just couldn’t find them. So I decided to give it a shot, and the macro-command module does the job for me.  I can now split the code into small reusable parts. Those parts are called commands and are chain-able. I can specify configurable macros for each different template,  and reuse my code over and over again. Whenever any adjustment is needed, I have several options to choose from:

  • change the configuration for each single command
  • change the order in which the commands are executed
  • add or remove commands from the command sequence

But the best thing is that I never have to mess with the original code anymore!

In the next few weeks, I will write some more posts on this topic. To explain the module in more detail and to provide you with more examples. I hope I can save someone else from the headaches I’d suffered while coding this module. Please, leave a reply and let me know if this module helped you in some way. Also, if you know better ways to solve the problem described in this post, or have suggestions for optimizing my module, please let me know. That’s why I published it in the first place. Any feedback is more than welcome…

More information on the command pattern:

  1. http://ima.udg.edu/~sellares/EINF-ES1/CommandToni.pdf
  2. PHP Objects, Patterns, and Practice (chapter 12 has helped me a lot)

See the macro command in action on Youtube: