Wednesday, March 14, 2012

Ritchieduino, What it is and why

Hello, this is my first post about the library i have created exclusively in C99 for the Arduino board, even though it might work with other AVR chips also and outside the Arduino board. I had already made a post on Arduino Forums, where a brief explanation can be found.
The Ritchieduino comprises much of the Arduino-0022 library functionality (pin compatibility), just completely written in C99 (not K&R C) and with some re-arrangement to make the code more modular. Also all the C++ code was mostly stripped off and the more important parts were partially re-written, namely the Serial, the SPI and Ethernet (w5100) libraries. Because of this re-writing the API changed significantly and i admit it is aimed at a more savvy audience than the original Arduino.

On the other hand as the including headers have been streamlined and the namespace cleaned some room for extra optimization control was gained. A clearer example is that mostly only the wiring library remained, which was already C. There were also some functions which were, in my opinion superfluous, that were cleaned out, namely re-naming of standard C functions, like the ones in WCharacter.h and WMath.h. I do reckon renaming is mostly inlined and doesn't bloat the code by itself but makes the analysis and deeper understanding of what is going on behind scenes mores obscure.

Still on the line of modularilization is the fact that in my opinion, Class Inheritance has been abused as to make Matroska doll code, where you have to go deeper and deeper to inspect what is happening under the hood, becoming even harder for newbies to start progressing to Intermediate level. An example of this is the print inheritance on pretty much every class, which sometimes calls code that is less than desirable, namely floating point code, which increases the size of the programs by some orders of magnitude.

As a final personal note i would like to notice that in no way i am diminishing C++, on the contrary. I think it is a much more powerful language with some concepts that, if not well understood and disciplined, can lead to quite obfuscated code. That and the fact that there doesn't seem to be any discipline regarding coding style as simple as a variable naming convention. A good example is in the socket.c file, where the socket descriptor variable can be called s, _s, sock or socket. The convention followed by Ritchieduino and its libraries attempts to follow as closely the Google Coding Style Guide as possible, even though there are exceptions(not the C++ ones) in the name of compatibility with the original Arduino library. I also advise a look into the guide even if you are not interested in Ritchieduino because for me it was really useful. It is even for C++!

There will be more posts on how to start and use the libraries, as it doesn't use the Arduino IDE, which in my opinion is terrible. I will make a post on how to set everything up in Eclipse IDE with some hints that may help the transition to Ritchieduino and even normal Arduino programming a bit faster and satisfying. In the meantime if you can take care of using the library you can try the WebServer examples which is functionally equal to the one provided in the original Ethernet library.

In the meantime i leave here the github repository with library available to anyone who so desires. It is also important to note that the library is LGPL, because the previous Arduino work upon which Ritchieduino is derived, is also LGPL, so you can use it in proprietary applications.

Hope enjoy it.
Paulo Neves

1 comment:

  1. Anonymous7:08 AM

    This is nothing short of excellent!
    I've started this work myself, but never finished. I too find the arduino IDE very restricive and the API though convenient for simple tasks, not powerful enough for me to do what I want. This will come very handy! Thanks again!