I should write better code

Apr 29th 2018

I do contract work for various companies and people. I was recently involved with a project where I was asked to review some code. I found that the code had used malloc (regularly and often) but never freed the memory. Hence it created a memory leak where the product would run out of heap space in a few months..

So with every problem there are two things that needed fixed, one is the problem and second is why the problem was not caught earlier. Fixing the malloc was easy. To prevent it I realized that I could use static analysis check (lint for example). Additionally I was shocked to find the project did not monitor heap and stack usage!  

It shocked me to realize that the project had no memory checking, how could some one consider releasing a product without stack and heap checking?  It was around this point I realized that my smart stepper code did not have memory checking...   

Now I just created myself another problem, which needs the two solutions...   So why would I think it is important for this other project to monitor memory usage but not my own projects like the Smart Stepper? 

So looking the other way, if I would use Arduino for the smart stepper, why not for a commercial product?  Would I try and make anti-lock brake controller or other safety critical system using Arduino IDE and libraries? 

Of course not!    

So why did I use Arduino? 

Well it does offer fast prototyping, and easy for others to compile and modify code.  After all open source is all about leveraging the community help fix bugs and improve product, hence it is easier for others if I use Arduino to compile and modify the code.  

So has that "open source dream" happened with the smart steppers? 

Well not really, I have had one maybe two people who offered code improvements or bug fixes.  So basically open source might be great for end user to feel better, but it really has not helped improve product for others.  

So basically the "open source dream" is appears to be a myth.  That is very few actually contribute to open source projects.  It has not made the smart stepper better for the community.  It might have helped an individual as they could modify the firmware to fit their specific needs, but as a whole it is a dream. 

Well Arduino is open source and really I should work on fixing it by the same reasoning.  Well if I did could I then use it for commercial products, like say an anti lock brake controller?  

No the licensing of most of the Arduino code would prevent a lot of this.

Should I spend my time writing my own framework instead, if I did should it be open source or not? 

Right now I know I need something better than Arduino, more specific to my needs and processors. Something rock solid, designed for low power and the Cortex processors. Something that I would use to control the brakes on my family car, but could also be used for things like the smart steppers. 

Should I release as open source, maybe MIT or BSD licensed? 

I am thinking that others have this problem and this might be the best way to go.