Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

It seems like the majority of Arduino applications are written without using classes / objects. Is there a reason for this? Does is slow down the Arduino or somehow present undesirable behavior?

share|improve this question
1  
Please note that "functional programming" is not what you think it is, I guess you wanted to say "procedural programming". – jfpoilpret yesterday
    
Functional programming usually involves the use of closures, in languages that support them. C++ doesn't, and you would probably use functors instead. – Edgar Bonet yesterday
1  
Check out this article. It explains the neglegable performance effect of using classes. – Gerben yesterday

Your assumption is quite wrong:

  • The majority of libraries use OOP.
  • The majority of in-built device drivers use OOP.
  • The core is filled with many OOP helper objects and classes.
  • 99.99% of all sketches use those OOP objects.

The sketches themselves may not be written as a class or set of classes for a number of reasons:

  1. There is no point
  2. The programmer doesn't know how

When a sketch is just stitching together calls to objects defined through libraries and making a few decisions there is little point in making the sketch itself an object. It's just a waste of time. In general if the sketch gets too complex to manage it gets broken down into smaller units - i.e., libraries - which are very often written as classes.

The moment you do Serial.begin(9600); you are using OOP.

share|improve this answer
    
Is there more than one Serial object? If not, what's the difference between Serial.begin and (hypothetically) Serial_begin? – immibis yesterday
1  
On some boards yes there are multiple Serial objects. – Majenko yesterday
    
If OOP is using C++ classes for implementation then this answer is fine. A more detailed answer may be found by first reading Peter Wegner's paper; cse.msu.edu/~stire/cse891/wegner.pdf. Arduino would be OOP if interfaces/classes would be more encapsulated, reused and extended. – Mikael Patel 3 hours ago
    
You mean like Cosa? ;) – Majenko 3 hours ago
    
Hard to miss :) – Mikael Patel 3 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.