
How to write a great Arduino library - apple4ever
https://www.sparkfun.com/news/3245
======
news_to_me
Does anyone have recommendations for writing Arduino code without the
Processing-based Arduino IDE? I'm sure there must be a not-too-difficult
makefile-based compile/upload configuration, but I'm not aware of any (nor do
I trust myself to write one from scratch).

At this point, the Arduino IDE is my least favorite part of the whole
ecosystem.

~~~
jpindar
Atmel Studio. It was very easy to set up, and can call AVRdude for uploading.
It has the ability to import typical Arduino projects, so you can either keep
using the Arduino libraries or convert the project to pure C/C++.

~~~
craftinator
I really wanted to use Atmel Studio, but couldn't get it working correctly on
Arch Linux + wine. Can't imagine why such a major company wouldn't support
Linux native.

------
franky47
One thing I've learned from maintaining an Arduino library [1] for the last
10+ years: make the API as simple as possible. Lots of people discover
programming with Arduino, making the experience enjoyable for them requires
abstracting a lot of things away.

Things can be as complex as reasonable in the implementation, but providing
helpers, macros & shortcuts (as well as good documentation and examples as
stated in the blog post) makes the learning curve less steep.

[1]
[https://github.com/FortySevenEffects/arduino_midi_library](https://github.com/FortySevenEffects/arduino_midi_library)

------
pjmlp
> Efficiency is not paramount; readability is

How I wish that this would drive C++ design decisions of lately.

------
smcameron
How about write in C, rather than C++, so you don't force C++ on your users. I
mean, if you're going to go so far as to recommend avoiding pointers in your
api because your users can't understand them, why in the hell would you then
go write a library in C++?

~~~
jcelerier
Using values everywhere has less gotchas in c++ - return value optimization is
applied much more consistently for instance.

Also you can make c++ look not far from python in terms of cognitive overhead
for beginners. C ? Not so much

~~~
eska
In C return value optimization is not a problem to begin with. There are many
more side effects in C++ that could inhibit (have inhibited) return value
optimization, by e.g. overloading operators. The standard actually changes the
behavior of side effects to allow for return value optimization, i.e. code
acts differently depending on whether it's return value optimized or not. I
don't feel like any of this is consistent or simpler than C.

~~~
jcelerier
> In C return value optimization is not a problem to begin with

of course it is -
[https://gcc.godbolt.org/z/welWvd](https://gcc.godbolt.org/z/welWvd)

C gives you O(N) memcpy, C++ gives you O(1) do-stuff-in-place for the exact
same code

> overloading operators

has exactly zero things to do with RVO

> I don't feel like any of this is consistent or simpler than C.

it produces vastly simpler user code. In years and years of programming in C++
never has "code acts differently depending on whether it's return value
optimized or not" been an issue for anyone I know.

