Arduino, Processing and p5.js similarities

Hi all,

I’m wondering if someone has any insight on why, when Arduino is a C+ library (is it a library?), Processing a Java library, and p5 a JavaScript library, the three are so similar in terms of syntax? It strikes me that when you know one it’s pretty straight forward to pick up the other two. How is this possible if they belong to three languages that I’ve heard people describe as being extremely different from each other?

Thanks!

2 Likes

Processing is indeed a library (and also a programing environment).

The similarity is simply due to p5.js being the JavaScript version of Processing and Arduino being intentionally built to resemble Processing.

In other words, first came Processing, then they built a version of Processing (Java) for JavaScript(p5.js).

As for Arduino, as far as i know, the developers of Arduino liked Processing a lot and made their library similar to it because of this.

Edit : I assumed, that with syntax you meant things like names of methods, classes and such (since these are the similarities between the libraries).

If you were refering to actual syntax, then they aren‘t similar, as @jeremydouglass described. :sweat_smile:

3 Likes

Thanks for the backstory. I didn’t know it was possible to make the syntax of the library of one language resemble the syntax of a completely different one!

1 Like

Often the similarity isn’t the syntax, except to the extent that the languages are already related (eg in the C family of languages) – instead the similarity is the keywords-function/method names, and their arguments: the API.

So, for example

void draw() {
  background(0);
}
def draw():
  background(0)

These don’t have the same syntax – : { ; whitespace, keywords are all different, and only the use of () is the same – but they do have the same API (“draw” and “background”)

3 Likes

This is very interesting! Thanks for helping to complete the picture for me Jeremy :slight_smile: What kind of code is the second example that you gave?

Python Mode: Py.Processing.org :snake:

Although there’s a slightly error there: def draw:def draw(): :bug:

3 Likes

Yes, sorry for the typo – () is the same.

In addition to Java and Python, here is Ruby (JRubyArt):

def draw
  background 0
end

…and here is p5.js:

function draw() {
  background(0)
}

…and here is R mode:

draw <- function() {
    background(0)
}
2 Likes