Go Down

Topic: [SOLVED] Arduino language (Read 4296 times) previous topic - next topic

curious48

Jul 18, 2016, 03:38 am Last Edit: Jul 29, 2016, 06:39 am by curious48
EDIT: To anyone coming here from a search engine, etc, I've now summarized everything I learned in this and a few related threads in the article "35-second Arduino language reference for expert programmers".


The below is just preserved for historical reasons.


--

[original title was "Nomenclature: is Arduino a language?".  Original post:]


I am reviewing edits I might make to an article I wrote, based on feedback I received in our thread here.  Someone suggested:

"There is no Arduino language! This is part of why some people hate Arduino, because they never took the time to actually understand what Arduino is and is not. If there really was an Arduino language that would be a good reason to hate it but instead we're using real, professional, programming languages. Sure, the IDE takes care of a bit of the less beginner friendly stuff but you can override any of that if you want."

I've reviewed (meaning read through) the linked post, "Embed with Elliot: there is no Arduino 'language'."

To give you my qualifications for talking about programming languages: in purely chronological terms, i.e. if you measure the time that I first wrote a single line of any programming language, I've been programming since I was a young teenager.  This extends from basic scripting languages to compiled languages to things running on a browser.

The author of the "Embed with Elliot" piece writes:
>There is no "Arduino language" and your ".ino" files are three lines away from being standard C++

In my opinion, something can be called a language even if even three lines are not involved.  For example, on Windows you can rename a .docx word file to .zip, and open it with an archive program.  You can see images in there and other assets.  Does this mean that there is no such thing as a Word document, since inside it is actually a zip file?  Surely not.

Three lines is quite a transition. It means that someone who has spent a whole year writing Arduino code cannot write a C++ program without looking up the C++ language.  Since they have been writing in Arduino.  How should they figure out "#include" lines?  By definition then it's not the same language: only almost the same language.  The Arduino language is very close to C/C++.  I don't see the mistake in calling it a language.  Further .ino files are not the same as .c[pp] files.

So, I would say that it is fair to say "the Arduino language is almost exactly the same as/very close to C/C++".

Therefore, I would like to reject the edit suggestion to remove the phrasing that Arduino "is a language".  In my article I want to continue to use this phrasing.  Would I be technically correct?  (In light of my arguments above.)  Bear in mind that Arduino has a language reference page.  After reading it, you can begin to write in the Arduino language, without having to look up references that don't refer to that.

If in light of what I've written above, you judge that I am still confused, I would like your additional information.  I do find the Elliot post to be interesting, and I would say it means that those who happen to know C or C++ can easily add it to Arduino projects, since the Arduino IDE can use them easily.  Is this a fair way to rephrase the Elliot post?

Thanks for your information about these exact differences and your advice regarding my edit choice.
Are you curious about the intersection of Arduino/Electronics/Raspberry Pi/Orange Pi/Beaglebone/niche manufacturing/starting from 0 and scaling?  Try: http://curious.boards.net

Power_Broker

No, no, no.

Arduino is not a language. Here's why: Your .ino file is not what is uploaded to the board. The .ino file is converted to C++ via the compiler and sends the C++ code to the board. In a sense, the IDE serves similar to an autocoder, taking a more primitive version of the code and converts it to what the C++ code should be.

Arduino is not a language, its just that the IDE is more of an autocode generator.


P.S. I wish I started coding as young as you, sir  :) !
"The desire that guides me in all I do is the desire to harness the forces of nature to the service of mankind."
   - Nikola Tesla

OldSteve

#2
Jul 18, 2016, 03:58 am Last Edit: Jul 18, 2016, 03:59 am by OldSteve
The .ino file is converted to C++ via the compiler and sends the C++ code to the board. In a sense, the IDE serves similar to an autocoder, taking a more primitive version of the code and converts it to what the C++ code should be.
No, C++ code is not sent to the board at all. Machine code is uploaded to the chip.
This will clarify:-
Build Process

Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

Nick_Pyner

No, it's simply a brand name for a development system made up of hardware and a compiler. I believe the user language is a subset of C++, not that it matters, as the IDE sends machine code to the chip.

ChrisTenone

Arduino is not a language, but when people speak of the "Arduino language', I believe they mean C++ with Arduino specific extensions loaded from the arduino.h library.
What, I need to say something else too?

curious48

This thread is not really helping.  :D :D :D

Let me ask this way.  (A) If I write .ino with vim, can I then rename it to .cpp, send it to gcc, and upload the results?

In what way will this differ from (B) pasting the same thing I wrote into vim, into the Arduino IDE and uploading it that way?

I assume under the first hypothetical (A), gcc does the compilation; under the second hypothetical (B), the Arduino IDE has a built-in compiler.

Is all this correct?  Does this comparison break down anywhere?  (Specifically in sending an .ino file to gcc)?

Are .ino files ANSI standard C89?  If not, what standard do they follow?  Does Arduino know any C++ or only just C?

Finally, can you use the arduino IDE from the commandline like gcc?  Any other differences?

Please tell me the comparison of (A) and (B) and the results.  Thanks so much.
Are you curious about the intersection of Arduino/Electronics/Raspberry Pi/Orange Pi/Beaglebone/niche manufacturing/starting from 0 and scaling?  Try: http://curious.boards.net

bperrybap

curious48,
My view is that "Arduino" is definitely not a language. Not anywhere close.

The Arduino IDE provides a development/build environment and defines and provides a runtime operating environment that can be extended further using C++ code, but it sure isn't a language. The actual language being used is C++

I believe that things in Aduino-world are confusing because the founders call everything "Arduino".
The board, the IDE, the tools, the libraries, and even claim to use a language called "Arduino".
This makes it very difficult to refer to the individual components/pieces.
At one point several years ago, after one of them said that Arduino was actually more of a lifestyle, I responded with something like:

"I have an Arduino that I program in Arduino using Arduino" just to demonstrate the ludicrousness of it all.

But in terms of "Arduino" being an actual language, it seems like a pretty weak argument since the code (and sketches) are all using C++. All the IDE does is massage the users "sketch" into being valid C++ if it isn't already and then compile it.
That doesn't qualify it as a language since the "Arduino language" is not defining any grammar or syntax which is what any real language must do.

The IDE does comes with some code to provide some functionality for the supported boards as well some "libraries". While the IDE calls things "Arduino libraries" they are not really libraries but simply a collection of code that kind of sort of act like libraries in "normal" development systems.
The only code in the Arduino IDE system  that is a real library is the core code. That code is compiled and archived into a real library and linked against at link time.







OldSteve

I forgot to say earlier, but I'm with the others. "Arduino" is most definitely not a language. The language is C++.
Dig into any Arduino function that you might call a part of the "Arduino" language, and the source files are C or C++.
"Arduino" is a just a brand name, a registered trademark. There's an Arduino IDE, Arduino boards, Arduino accessories but no Arduino language.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

PaulMurrayCbr

#8
Jul 18, 2016, 05:41 am Last Edit: Jul 18, 2016, 06:15 am by PaulMurrayCbr
Arduino is not a language. It is a hardware platform and a programming environment. The language is simply C++. The main thing that the arduino gestalt has is a Hardware Abstraction Layer. That is, you can write digitalRead(3) without having to worry about the details of where the ports are memory-mapped to. If anything, that's the core of what makes it useful. But that would be nothing without hardware that's rugged enough to manage being handled and poked at by hobbyists. Let's also not forget the importance of shields and modules.

So:

* rugged(ish) hobbyist hardware
* open source makes it possible to make and sell 3rd-party plugins
* hardware abstraction layer - an API
* IDE that makes it easy to upload the machine code (a lot happens in the background)
* the community

But it certainly isn't "a language". Perl is a language. Lisp is a language. The IDE uses C++, but it could use anything else that could be compiled down to run on the AVR.

Quote
Let me ask this way.  (A) If I write .ino with vim, can I then rename it to .cpp, send it to gcc, and upload the results?
Yes. This is exactly what ordinarily happens when you git the 'go' button in the IDE. The code is sent to gcc, then it is linked with a runtime library same as any other C program - most notably it is linked with libc which is the standard C library that pretty much every C program uses. Then it is uploaded over the USB.

You could do all this with command-line tools if you wanted, and I think that that's how the IDE actually does do it: it issues java System.shell() commands.

If you replaced the arduino libraries with your own stuff implementing main() and the abstraction layer (digitalRead(), etc) - it would just be a regular C++ program.




http://paulmurraycbr.github.io/ArduinoTheOOWay.html

bperrybap

#9
Jul 18, 2016, 05:53 am Last Edit: Jul 18, 2016, 06:09 am by bperrybap
curious48,
You seem to be confusing several different things and trying to lump several together operations, from a lack of understanding how programs are converted from source code into executable machine code.

There are many different tools involved in building and uploading an Arduino sketch and none of them are a "language".
The Arduino IDE is simply a GUI wrapper tool that runs many commandline tools under the hood.

Much of what is in the IDE is a re-inventing of the wheel for what is in the tool 'make' to control the build process.
None of the actual compiling, linking, or uploading is done by the IDE itself.
i.e. the IDE simply decides what needs to be done/built and runs the appropriate commandline tool to do what needs to be done.

And yes the newer IDE versions can be run directly from the command line as well rather than interacting with as an actual GUI program.

The IDE first acts as a pre-processor that runs before the other tools to massage the .ino into a .cpp file to be a valid C++ code and to also insert the arduino header to pull in the Arduino environment defines/macros and classes.
That is pretty much the only thing that IDE actually does itself. Everything else, is done by commandline tools since it all involves using C++.

But it is possible to write your sketch such that it is already valid C++ code and contains everything needed to use the Arduino compile and runtime environment.

What is being called a "Hardware Abstraction Layer", is really a runtime environment, provided by the Arduino core code. But that environment is simply a collection of C & C++ code that provides a consistent API across multiple hardware platforms.

After the IDE pre-processes your .ino file to create the .cpp C++ file, it then runs a series of command line tools to compile the sketch (which is now valid C++) as well as all the other needed sources and link them together to create the .elf object file. It then runs additional command line tools to convert that to a .hex file and eventually runs an upload tool like avrdude to do the actual upload.
Again, the IDE is not actually doing this but simply calling other command line tools to do the actual work.
This is all possible because the "Arduino language" is actually C++ and so the IDE can use standard C/C++ embedded tools to do the actual compile, link, and upload.


--- bill



curious48

#10
Jul 18, 2016, 06:52 am Last Edit: Jul 26, 2016, 04:44 am by curious48
"I have an Arduino that I program in Arduino using Arduino" seems fine to me?

I read this as:
"I have an Arduino-compatible board, that I program in the Arduino [redacted], using the Arduino IDE".


In the word "redacted" is what this thread is about - obviously some people disagree that this word should be "language".

Let me ask this.  Many people in this thread are saying that the Arduino "language" is C++.

But in C++ this is how you change the size of an array:

c++ changing the size of an array]c++ changing the size of an array

There are two helpful answers:

Quote
Quote
n C++ you can do:

int *array; // declare a pointer of type int.
array = new int[someSize]; // dynamically allocate memory using new
and once you are done using the memory..de-allocate it using delete as:

delete[]array;



This is correct and insightful, but really, one should encourage the use of std::vector


and:

you want to use std::vector in most cases.

Quote
std::vector<int> array;

array.resize(someSize);
But if you insist on using new, then you have do to a bit more work than you do in Java.

int *array;
array = new int[someSize];

// then, later when you're done with array

delete [] array;
No c++ runtimes come with garbage collection by default, so the delete[] is required to avoid leaking memory. You can get the best of both worlds using a smart pointer type, but really, just use std::vector.




So, this is C++.  Will this work?  Is this appropriate usage?

If we look at the Arduino language reference, under array it says:


Quote
Arrays in the C programming language, on which Arduino is based, can be complicated, but using simple arrays is relatively straightforward.

Creating (Declaring) an Array

All of the methods below are valid ways to create (declare) an array.

Quote
int myInts[6];
  int myPins[] = {2, 4, 8, 3, 6};
  int mySensVals[6] = {2, 4, -8, 3, 2};
  char message[6] = "hello";




So, at a minimum, this seems to mean that Arduino is only based on C, not C++.

Since this whole thread is kind of pedantic, it makes it really really weird that not one but two of the commentors wrote "C++" and the linked article also says "C++".

In what sense is Arduino possibly C++ as opposed to C?


People are writing "Arduino is not a language, but when people speak of the "Arduino language', I believe they mean C++ with Arduino specific extensions loaded from the arduino.h library."  <---- this should read "I believe they mean C with Arduino specific extensions", right?


bperrybap writes:

>The Arduino IDE provides a development/build environment and defines and provides a runtime operating environment that can be extended further using C++ code, but it sure isn't a language. The actual language being used is C++

Do you mean C?  "The actual language being used is C"?  (Not "C++").

Oldsteve writes:

>"Arduino" is most definitely not a language. The language is C++.

Again, does he mean C?

Paulmurray writes:

>Arduino is not a language. It is a hardware platform and a programming environment. The language is simply C++.

Again, does he mean C?


It seems incredibly odd that every single commentor would make this mistake in this pedantic thread.  Please explain why they are using the term C++ and not using the term C?

I am more confused than ever.  Note: I've programmed in both C and C++.  In general, C++ is a superset of C and you can use C constructs.  But not the other way around - I've never heard anyone refer to C code as C++ code, unless they're being incredibly casual (like "C/C++").  In this sense, sure, Arduino is "like C++ code".

But now that we're being very technically precise, shouldn't all of the above references to C++  be renamed as references to C?


[EDIT: this was all mistaken.  Arduino is not a "subset" of C++.  It is the Project's name for C++, which for marketing reasons it does not use.  The IDE also does some light translation before using a standard C++ compiler.]
Are you curious about the intersection of Arduino/Electronics/Raspberry Pi/Orange Pi/Beaglebone/niche manufacturing/starting from 0 and scaling?  Try: http://curious.boards.net

BulldogLowell

I am more confused than ever.  Note: I've programmed in both C and C++.
Maybe think of it as a patois.

 ;)


OldSteve

#12
Jul 18, 2016, 07:13 am Last Edit: Jul 18, 2016, 07:17 am by OldSteve
Oldsteve writes:

>"Arduino" is most definitely not a language. The language is C++.

Again, does he mean C?
No. I meant what I wrote - C++.

C++ is backwards compatible.

There are errors in the documentation, but Arduino primarily uses C++, as we've all indicated.
Try this:-
Code: [Select]
void setup()
{
    Serial.begin(115200);
    int *pVal = new int[10];
    pVal[0] = 123;
    Serial.println(pVal[0]);
    delete[] pVal;
}

void loop() {}

'new' and 'delete' are only valid in C++, not in C. If Arduino used C, this would not compile.

You could also use 'malloc()' and 'free()', because of the backward compatibility, but in C the 'new' and 'delete' method of handling dynamic memory allocation would not work.

Disclaimer: I'm not in any way saying that dynamic memory allocation in embedded microcontrollers is a good thing, this is just an example. Easier than writing a 'class' example. :)

Quote
But now that we're being very technically precise, shouldn't all of the above references to C++  be renamed as references to C?
Definitely not. As we've all stated, it's C++, not C.

At some point you need to stop arguing and accept facts. :)
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

curious48

Disclaimer: I'm not in any way saying that dynamic memory allocation in embedded microcontrollers is a good thing, this is just an example. Easier than writing a 'class' example. :)
Definitely not. As we've all stated, it's C++, not C.

I didn't see as many examples like this.  Most examples just use the Arduino language reference things.  You just wrote that dynamic memory allocation isn't good in embedded microcontrollers.  What about classes and objects generally?

I am now confused regarding why / to what extent, then, Arduino (patois + culture + habits and what is encouraged) is different from C++.  Why not use C++ concepts such as classes extensively?  There is little overhead, it's more about how you think about things.
Are you curious about the intersection of Arduino/Electronics/Raspberry Pi/Orange Pi/Beaglebone/niche manufacturing/starting from 0 and scaling?  Try: http://curious.boards.net

OldSteve

#14
Jul 18, 2016, 07:59 am Last Edit: Jul 18, 2016, 08:05 am by OldSteve
I didn't see as many examples like this.  Most examples just use the Arduino language reference things.  You just wrote that dynamic memory allocation isn't good in embedded microcontrollers.  What about classes and objects generally?
Classes are fine, much of the Arduino code and libraries are written using classes.

Quote
Why not use C++ concepts such as classes extensively?  There is little overhead, it's more about how you think about things.
See my line above. :)

Take a bit of a look around in the source code. For instance, "Serial", which itself inherits from the "Stream" class:-
Code: [Select]
class HardwareSerial : public Stream
.
.
.
extern HardwareSerial Serial;


Edit: And "Print" is a class, with 'print()', 'println()' etc member functions, "Servo" is a class, "File" is a class, "Wire" is a class, ("TwoWire"), etc etc
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

Go Up