Object oriented or not?

I know C++ is definately object oriented, but can I say that the Arduion language is definately so? This may seem a bit pedantic but is actually quite important to me at the moment as it affects what I do or don't have to do as part of a college course.

I'm a bit new to programming but catching on fast.

All comments gratefully received.

Kit

I know C++ is definately object oriented, but can I say that the Arduion language is definately so?

The Arduino language is C++ so the answer is yes.

Thanks for that prompt reply. I wanted someone else to confirm this as it means I can use one project for two parts of the course I'm doing.

Kit

but can I say that the Arduion language is definately so

There is no arduino language, it is all C / C++
You can get things to work by just using the C bits but if you want to you can use the objects in C++

Kitwn:
I know C++ is definately object oriented, but can I say that the Arduion language is definately so? This may seem a bit pedantic ...

To be pedantic ... it's Arduino. Not Arduion.

But as Grumpy_Mike and Coding Badly say, it's C++. Which is object oriented.

... it means I can use one project for two parts of the course I'm doing.

Whatever that means, sure.

Umm. I would be very hesitant to turn in a typical Arduino sketch for an "Object Oriented Programming" class. C++ may be an "object oriented language", but that just means that it has features that HELP a programmer write object-oriented code; it doesn't automatically make your program object-oriented. ("I can write a C program in C++, Java, or Perl...") Especially given that many things stressed in OOP (inheritance, dynamic allocation, I dunno) rarely appear in the user portions of an Arduino sketch...

Hi,
I thought I would wait for someone else to put their head above the trench first, but yes I would agree with westfw that Arduino is probably not the best environment to showcase your OO skills.

Duane B

rcarduino.blogspot.com

but yes I would agree with westfw that Arduino is probably not the best environment to showcase your OO skills.

Actually, I think that it could be a good place to do just that. A OO program does not NEED to gobble lots of memory and produce reams of output to demonstrate inheritance, polymorphism, etc.

Serial, Stream, and Print, for instance, demonstrate those capabilities, and we take them for granted, and use them every day.

Hi,
All of which are already provided, I have no idea whats expected of students these days, but presumably more than just using some existing libraries or writing a single standalone class and calling it OO.

Duane B

rcarduino.blogspot.com

All of which are already provided,

Sure. But my point wasn't that OP should use them, but to illustrate that OO is not only possible on the Arduino, but, in fact, already in common use, even if we tend to forget that.

Hi,
Lets wait and see what the OP comes up with ...

Duane B

rcarduino.blogspot.com

Lets wait and see what the OP comes up with ...

Why? PaulS is clearly right.

Hi,
Based on the examples within this branch of the forum, most people that attempt to write OO for Arduino tend end up to writting the problem to fit the solution. Maybe you can write great OO for Arduino but OO requires more than a collection of standalone libraries created as classes.

If I was taking a test as part of a job interview and the test was - 'write something that makes elegant use of OO to solve a problem' and I was offered a PC or an Arduino, I would take the PC.

As the OP is looking for confirmation on an approach for a college project he is in a similar situation and my advice to him/her is the same I would give myself.

Duane B

rcarduino.blogspot.com

If I was taking a test as part of a job interview and the test was - 'write something that makes elegant use of OO to solve a problem' and I was offered a PC or an Arduino, I would take the PC.

Fine. But, if the job was to develop code for embedded processors, and your app consumed 4 GB of ram, that would not then scale to the intended job target.

The Serial/Stream/Print classes prove that OO on Arduino works, elegantly.

Hi,

Fine. But, if the job was to develop code for embedded processors, and your app consumed 4 GB of ram, that would not then scale to the intended job target.

Quite right, I am always open to changing my mind, so would anyone like to offer some great examples of OO being used to build projects by forum members, thats OO, not here is a class in a library.

Duane B

rcarduino.blogspot.com

[quote so would anyone like to offer some great examples of OO being used to build projects by forum members, thats OO, not here is a class in a library.[/quote]

OO will come into play in case of Algorithm implication for example in cases of PID controller deployment or else for some simpler usages of Arduino ,clever coding will work, However you can deply it anytime but then there should be a need for it.

Well I am writing a clone of the Robotron 2084 arcade game using an Arduini Uno and a Gameduino shield and it is pretty much entirely object orientated. All the moving objects are instances of classes derived from a common base class. All the bullets, the score, the stuff for managing the sound, just about everything are all instances of classes. I even have a Game class from which I derived this particular game.

When I first started using object orientation I was a little hesitant and tended to stick to the tried and tested principles of structured programming and encapsulation but nowadays I wouldn't dream of writing anything other than a trivial program without using object orientation. If you're using something like Visual Studio you don't have much choice these days, but that's another story.

There are one or two caveats:

  1. I now have an Arduino 1.0. As I understand it earlier versions did not support the new and delete operators with classes which means it is hard to get polymorphism to work since virtual methods only really work properly when you are using a pointer to a common base class and object pointers are normally created using new. Not sure I explained that very well but you get the idea.

  2. It is good programming practice to put every class you define in a source file which has the same name as the class (I think Java enforces this). So class Wombat would be declared in Wombat.cpp and Wombat.h. This tends to end up with lots and lots of files and the Arduino IDE isn't ideal for this. It works, but its just not that convenient. This isn't a criticism of the language of course.

  3. If you are only interested in learning object orientation then it would probably be easier to start with something like C# or Java on a PC. They are much easier to use than C++ and you are less likely to suffer from the dreaded memory leaks. Visual C# Express is free and perfectly usable (for non-commercial purposes I think).

So yes, Arduino projects can be written in an object orientated manner but it is probably not the first choice if all you want to do is lean object orientation.