Scott Penrose

Mini Cathedral mini Bazaar

Scott is an expert software developer with over 30 years experience, specialising in education, automation and remote data.

There are a number of principles in software development that are true for a reason. One of them: it take 3 times as long to make code reusable.

This is one I don't always believe. If I make a perl module, wrap a test, even if it is a simple function, I can now reuse it and it is tested. Generally this idea has saved me time, not cost me.

However this seems also to be often true ! Curse rules.

Building embedded hardware this seems to be very true. I think one of the reasons this is more true in Embedded is that we are resource tight. Writing a little library to automatically manage web connections is easy enough, but soon it takes up quite a lot of program and memory space. So we tend to simplify our API/Library/Code, which then makes it less reusable without changes.

When writing my house controller in 1999 I wrote it in Perl and it was pretty simple. in 2010 I was rewriting it in C++ for an Arduino and I wrote lots of code to allow button and device configurations. Works ok, but uses lots of Program space and ram. We generally have lots of program space on an Arduino but not ram.

The code was taking some time to write, and no real time. Plus my system from 1999 was still running fine.

In 2012 my old system failed, and I didn't have another backup machine. It was just a hard disk failure, but I knew it would take me longer to reapir/replace hard disk (reinstall etc) than to replace the system with my planned Arduino. Only thing is that my code was not ready.

So I wrote the code from scratch that just did the minimum - turn on/off lights, with a few simple business rules (e.g. max time, and all off in 30 seconds). By using a simple switch statement I was able to capture the input button, and by writing a couple of helper routines (off, on, swap, all_off, all_off_30) I was able to combine configuration and code and write the entire system in a couple of hours.

Library still has its place. For example the Keyboard library I used (I had written my own, but now I use an open source one). And I could move some of my code to a parallel port library. But the business rules and mappings end up being simpler hard coded.

Of course if I wanted to make the system more sophisticated - e.g. allow programming button mappings via Ethernet, then it may be worth while.

Just reminds me that sometimes it is easier to code monolithic programs than trying to break up all the code into reusable and testable components. Interesting...

Thanks to Eric S Raymond for