top | item 31666942

(no title)

jdcarter | 3 years ago

> why do you say setup and loop are the worst imaginable way to write embedded software?

Because there's neither abstraction nor ways to combine things. Say you have a device that needs to do two things, and you look up some examples of how to do each thing. Each example is going to have its own loop() function--but how do you combine them? There's no notion of tasks or threads. There's no abstraction for device drivers. Arduino is a system that paints you straight into a corner.

[edit to add] Any reasonable software environment needs to provide three things, quoting "Structure and Interpretation of Computer Programs" here [1]:

* primitive expressions, which represent the simplest entities the language is concerned with,

* means of combination, by which compound elements are built from simpler ones, and

* means of abstraction, by which compound elements can be named and manipulated as units.

Arduino only provides the first.

[1]: https://mitpress.mit.edu/sites/default/files/sicp/full-text/...

discuss

order

turbinerneiter|3 years ago

You don't have to use `setup` and `loop` tough. We use Arduino as a library in C++ using PlatformIO as tooling. Best of both worlds.

The thing you are hating on is pretty much this file: https://github.com/arduino/ArduinoCore-avr/blob/master/cores...

Arduino is C++ with some boilerplate and a library.

a2800276|3 years ago

But these `setup`, `loop` and `delay`, as well as the terrible "IDE" are central to the "simple" user experience of Arduino and are, imo, false friends. Teaching people busy loops and blocking behavior from day 1 is counterproductive because you'll have to unteach them later and jump through hoops to avoid them. Arduino libs are strongly optimized for "easy", not efficiency and flexibility.