Arduino IDE - OOP versus procedural coding

Hello,

Apologies if the question has already been asked. I am just starting with Arduino and I see that the IDE language is C++. I am puzzled by this choice. Considering the limited amount of memory available in the micro controller, wouldn't it more memory efficient to use a procedural language like C or even a mix between a procedural language and machine language?

Kind Regards Luca

C is a subset of C++ so the arduino is quite happy to be programmed in C.

Fortunately, the avr-gcc compiler used by the Arduino IDE will compile C as well as C++. There is also a provision for inline ASM.

If you look at the examples you will see a mix of C and C++.

Strong OOPers tend to turn a little green when they first realize how much RAM is available here…

-br

OO C++ code can become quite bloated if “overdesigned”. OTOH OO style is quite useful even on a small Arduino. Look at the libraries out there… they’re all implemented as classes.

In case of memory and time efficiency which approach is suitable. OOPS or Procedural like C?

I’ve seen people piss away a lot more in plain procedural then in OOP. Yes, higher level can be less efficient in terms of speed and size compared to assembly but it’s advantages outweighs the disadvantages. And compilers have become quite good so the overhead, if any, is limited and in my opinion more then worth it in terms of scalability and reusability.

Kumar_arun: In case of memory and time efficiency which approach is suitable. OOPS or Procedural like C?

I don't think it matters. Using either approach you can write efficient or inefficient code.

By the time the compiler has produced HEX code for uploading to the Arduino all vestiges of style will have disappeared.

...R