Pages

Labels

Tuesday 18 February 2014

Coding the Arduino in C++ - The reasons behind my decision.

By default most people will code their Arduino boards using the Arduino Studio, which means writing code in a variation of C. Personally I don't have a problem with that, for most developers using this board it's perfectly fine, it's just that I want to do so much more than I can easily achieve with C. Therefore I'll be developing in C++, and will starting with this post describe the decisions, options and then steps I am taking to achieve this.

Firstly I feel I must explain what it is that I want to achieve that the variation of C that is used in Arduino Studio, either doesn't provide me with, or is not as straight forward as I feel it ought to be.

Firstly I am working in a truly agile development environment, and a key to agile development is Test Driven Development (TDD). Now I am aware that there are TDD boiler plates out there that can be used in Arduino Studio, the arduino_c_scaffold git repository created by the throwtheswitch.org guys looks a really good place to start, however I am looking for something with a little more support behind it, and Google Test (gtest) feels a better solution.

Going hand in hand with the unit testing framework, is object mocking, important because if you aren't mocking, faking, or otherwise separating code that you are testing from any dependencies that code is using, you are not doing unit testing, which in itself breaks a core part of TDD. The throwtheswitch guys do have this covered too in their product cmock, and I would fully recommend checking what these guys are up to, as for most this really can be seen as a solution to the TDD problem, but again what I am looking for is a framework that is more widely used and gtest sister product Google Mock (gmock) is the framework that I prefer to use.

Beyond TDD, there are other reasons for choosing to go down the C++ route, not least because we are anticipating having to incorporate hardware that is not currently available in pre-built Arduino shields. If you are building new hardware, or providing libraries of code that other developers will use on Arduino, these are typically written as C++ libraries, so the fact that we are expecting to be writing C++ for these libraries, and the unit tests, it seems sensible to write all the code in C++.

So those are the reasons behind my decision to code in C++, next I will select the development environment, and describe setting up the automated build system we use, Teamcity, to build, test, and deploy these projects.




No comments:

Post a Comment

 
 
Blogger Templates ReadABlog.com