Hardware Reference
In-Depth Information
work, and the examples included. This gives the user a good idea about what
your library does without having to look at the source code.
Coding Style
To make it easier to both use and to distribute libraries, certain coding styles
should be followed. These general rules make everything simpler and to make
sure that everyone has a great time when programming Arduino. You can
i nd the ofi cial API style guide here at http://arduino.cc/en/Reference/
APIStyleGuide .
Use CamelCase
Sooner or later, you will need to write a function that is two or three words
long. To put several words into a single compound phrase, there are several
techniques possible. Programming languages are full of examples; using under-
scores results in functions like this_function() , and some languages even
went as far as to put the i rst word in uppercase and the second in lowercase,
but THESEfunctions() isn't easy to read.
The Arduino style uses CamelCase: each word starts with a capital with the
exception of the i rst letter. Functions are easier to read that way; functions such
as readFile() or openImage() are immediately clear and remain perfectly read-
able. CamelCase is even used for multiple everyday objects; the i rst known use
of CamelCase is in a 1950s technology called CinemaScope. Some readers might
be reading this topic on an eReader, another example of CamelCase.
CamelCase does have one disadvantage; it can be difi cult to read functions
that contain several uppercase letters: ReadID() for example. Of course, the
function can read an ID, but functions such as GetTCPIPSocketID() become
complicated. Should you write GetTCPIPSocketID() or GetTcpIpSocketId() ?
Generally, you should avoid abbreviations, but when they are inevitable, it is
often better to write them as capitals.
Use English Words
Don't shorten words for your functions. If you can't explain it in three words,
look for another way. Always use complete words: deleteFile() is always clearer
than delFile() , and oFile() doesn't mean anything, where openFile() does.
Again, it is better to avoid abbreviations because only some abbreviations are
clear to most people. You have probably heard of HTML, and writing “Hyper
Text Markup Language” is going to make some ridiculously long function
names. You can i nd a perfect example in the Arduino libraries; they don't talk
about PWM, they called the function analogWrite() .
 
Search WWH ::




Custom Search