bblanchon / cpp4arduino

Samples files for cpp4arduino.com
https://cpp4arduino.com
48 stars 6 forks source link

Improving Arduino #1

Open rmerriam opened 5 years ago

rmerriam commented 5 years ago

Hi, Wasn't sure how else to contact you about Arduino and C++ so using this venue.

First, you might be interested in some articles I did for Hackaday on C++ and embedded systems. They used the Aruduino Uno and Due but also the Pi. There's a list here.

I keep wondering how to improve the Arduino software ecosystem and the best I can come up with is a massive open source project reworking the original code base. I shudder at how much effort it would take. I did a project recently using I2C sensors. Some libraries were great. Others were bad. The latter was not terribly surprising because the class had member functions written as xyz(void).

Anyway, wanted to reach out to you since we've got similar thoughts.

ristomatti commented 5 years ago

@rmerriam Your articles were great, and inspired me to learn C++. I only use it in the context of Arduino and therefore I'm only interested in the parts of "modern C++" that I can make use of in the context. There is very little information available on the topic so I first read through one C++ learning site and then started looking at the source code of libraries that used template based syntax in the examples.

ArduinoJson was one of them. The code was fascinating but I didn't understand anything what's going on. I was very lucky that about that time @bblanchon released his book on it. I was one of the readers hoping to see a follow up book for the C++ specific chapter. I assume this article series is the "book" until proven otherwise.

It was such a strange coincidence for me to find this issue here. It would be great if this would lead into some kind of a collaboration between you!

I am a big fan of TypeScript (typed JavaScript), and currently it's the language I use the most (I also use it at work). When starting to learn C++, I began to notice a lot in common with TypeScript. It has helped a lot in the learning process. I now like to think C++ is for C what TypeScript is for JavaScript. As a developer with a long background in Java, I found the lack of types (or the obscurity of it) in JavaScript and C frustrating to say the least.

ristomatti commented 5 years ago

On talking about improving Arduino, I'd like to bring up the single most frustrating problem I've encountered during my odd quest to learn how to write more elegant Arduino code without spending all my available into gaining a deep understanding of C++.

It is the fact that most C++ books/references quickly move on to STL. It is available for some Arduino cores/platforms like the ESP8266/ESP32 but it quickly became obvious to me for most parts it is not suitable for microcontroller programming due to memory handling if I've understood correctly. But still some of its concepts seemed very useful. I found some articles on writing custom allocators to be able to control the memory usage but to be honest, I could not understand any of it.

Then one day I ran across Embedded Template Library (https://www.etlcpp.com/) when searching for some library from the PlatformIO library index. It looked exactly like something I had been looking for quite some time. And it even was flagged to support Arduino! But unfortunately It turned out to be too good to be true, I could not get it to compile.

As a stubborn person I proceeded to spend countless hours of searching for some tutorial or something to help getting it to work. My only findings were a thread on the Arduino forum where the developer had announced the library but that did not lead anywhere, and a mention on the ETL site that support for Arduino has been dropped at some point, blaming restrictions with the directory layout IIRC.

I noticed some clever tricks being done with the ArduinoJson directory structure. I've been wondering if something like that could have solved the issues the ETL developer ran across?

Anyhow it would be love to hear thoughts from either of you if this ETL even would make sense if it would compile? As someone who has spent most of my developer life with higher level languages, I'd find it useful to have some ready made, embedded friendly containers / data structures in the form of a library.