The Arduino IDE has a bit of a split personality. On the one hand, it is a simple environment where you can just pick and choose a few libraries, write a few lines of code, and make lots of interesting things. On the other hand, it is also an ecosystem in which many different boards and libraries can be supported. Writing a great library that everyone can easily use takes a little forethought. There is an official style guide, but a recent post by [Nate] from Sparkfun points out lessons learned from writing more libraries than most people.
Of course, as you might expect, some of this is a matter of opinion, and [Nate] admits that. For example, they always use the serial port at 115,200 baud, but they do note that 9,600 baud is also popular. They also suggest making code as readable as possible, which is usually good advice. In the old days, writing terse code might lead to higher efficiency, but with modern compilers, you ought to get a tight final result even when doing things in a pretty verbose fashion.
However, a lot of the advice is very subtle but important. For example, the use of default parameters and the order of parameters. If you add their advice to the official style guide, you should be well on your way to creating really great Arduino libraries.
Of course, you also need a great idea for a library or an improved library that doesn’t already exist. That may be your most difficult task. Sometimes it makes sense to port something over instead of starting from scratch.
from Hackaday https://ift.tt/3cfHEp1
Comments
Post a Comment