Latest upate:
link to postTest the language: http://webcloudtools.com/sprk/lang-test/#hello-worldProject on
GitHub:
https://github.com/YemSalat/spark-langHi everyone, I've been away from the forum for a while, but recently I have been lurking around, reading the forum posts, being amazed at how often some of the beginner questions come up. And I started thinking:
What would a language designed specifically for Arduino beginners look like?I think many would agree that even though Arduino provides a lot of helpful materials (libraries, examples, etc.) - the language that it is based on, C++ - can still be a pretty big obstacle in getting beginner projects done.
Here is a short list of things that in my opinion could be improved if there was a language designed specifically for Arduino beginners:
Simplify syntax, remove the 'cruft'C++ has a pretty complex syntax, which is full of semicolons, star symbols, parenthesis, etc.
By removing most of this stuff the language would look much more approachable (think Python/Ruby).
For example start by making semicolons optional and allowing for simpler code structures.
E.g. what a for loop variation could look like:
a = 25
repeat 10 times { a += 5 }Inferred types instead of explicit declarationDon't get me wrong - I am all for strictly typed languages, especially when there is almost no other way around it on embedded systems. But having to declare types, while very important in terms of programming techniques - has very little to do with what the beginner is trying to achieve, mainly finishing their project.
Better error messagesFor example instead of saying something like
".. expected ')' before '{' token or .. at line at line .."It could say -
"You are missing a ')', make sure all your opening and closing parenthesis match on line .."And overall all the errors could be more beginner friendly.
Tailored to the environmentHow many times did you have to tell people that they should not use C++ Strings when programming for Arduino? Wouldn't it be nice if things like that were handled on the language level.
Apart from that, I think it would be very helpful to have some entities from the Arduino and micro controllers realm be present in the language. For example, it could have
interrupts 'built-in' as a language structure, etc.
For example setting up an interrupt like this:
-------------------------
interrupt when pin 12 is RISING {
// do stuff..
}
-------------------------Convention over flexibilityA 'predefined path' can be very helpful to beginners. Languages that allow less flexibility and more conventional approaches to solving common problems tend to be easier to learn as they allow to focus on the primary goal without thinking too much about the implementation itself.
Taking care of performance issues and errorsHaving a language that follows strict conventions - allows for better optimizing code and also preventing errors.
For example - the compiler can check if a variable is ever used inside an interrupt - and make it
volatile if the user forgot to do so.
Handy stuffSome things in Arduino are harder to do then they should be. Things like concatenating strings, checking if one string is contained in another one, etc.
Wouldn't it be great if you could just write:
foo = "Hello"
foo + " World" // "Hello World"
Different approachesPerhaps it would be good to try different approaches to programming. A semi-declarative way of programming could be easier for beginners to grasp.
Set up everything, then assign what happens when (e.g. when sensor reading is higher then X - turn on the pump)
Here is a quick 'sketch' of what it could look like.
A program where an LED light blinks when a button is pressed:
-------------------------
device LedLight {
write: pinLed // pin number
action: blink {
pinLed = HIGH
wait 5s // does not prevent other code execution
pinLed = LOW
}
}
device Button ( LedLight led ) {
read: pinButton
// no need for multiple IF statements
when pinButton is HIGH {
led -> blink()
}
}
led1 = create LedLight on pin 9
button1 = create Button on pin 1
-------------------------
What do you think? Do you reckon any of these ideas are worth considering?
What in your opinion should a beginner-oriented Arduino language look like? Is such a language even needed?
I am gonna try and come up with more uses cases where such approach can be useful, and who knows maybe one day I'll even make it happen
[ADDED]Here is how I see it working:
device is the main entity in the language (think Class)
Every device follows this structure:
device DeviceName ( constructor parameters ) {
write: pin1, pin2, pin3 // pins that the device can write to
read: pin1, pin2, pin3 // pins that the device can read from
// Here go predefined blocks that are built into the class
init { ... } // basically constructor
actions { ... } // all object 'methods'
always { ... } // this code is executed all the time
....
// then goes a list of all 'events' - code that executes when a condition is satisfied
// they all start with keyword 'when'
when pin1 is HIGH { ... }
when pin2 is < 512 and pin3 > 128 { ... }
when pin4 is RISING { ... }
...
}So there isn't much code outside the
devices. (There can be other entities though, like
timers for example, with their own set of "actions" and "events")
PS I do appreciate any criticism though, as it is entirely possible that I am missing some huge flaws in this.