Suggestion and request for help for beginners

To the imp support folks…

As a beginner trying to learn squirrel I would like to request (suggest) that what would help ALOT would be for someone experienced in squirrel code to do a couple of videos (youtube).

Just a detailed walk through of a couple of imp examples explaining what each part of the code does. It would be especially helpful to explain and describe each item in the code…

What does this "<-" symbol do?

When do you use {} vs () vs [] ?
What does the semicolon “;” do and when is it required?
What is a class?
When do you need to precede a variable name with “local” ?
Are they even called “viariables” in squirrel ?
Where do I go to find out what these mean…
==, ++, &&, += ?
Etc, etc

Is code that is between {} just the same as being on one line? And is it only formatted on separate lines for readability?

What does “object oriented” mean

What parts of the IMP code are caseSensitive and which are not CasEsensITive

The above questions are ones I have been jotting down as they come up. I realize some of them could be answered by studying “c” or other programming manuals, but if you want the beginner to have success and purchase more of these imp’s then any assistance you can give us would help GREATLY!!

I have written a fair amount of BASIC code for the Microchip PIC but I am finding the jump to squirrel a real challenge.
A little bit of explanation from an experienced squirrel coder would really help to clear the fog.
pretty please :slight_smile: and thanks

dwight

lots of questions :slight_smile:

I’m not an expert nor part of electric imp but I’ll give a try just to hopefully get you started. others, please correct me if I get something a bit wrong. I tried to regroup the questions to separate squirrel related and general.

Squirrel related
What does this “<-” symbol do?

- this is used to assign a global variable. use this the first time the variable is encountered in the program

myglobalvariable <- 1.0;

myglobalvariable = myglobalvariable + 1;

When do you need to precede a variable name with “local” ?
Do this inside of a function for variables that are not needed outside of a function.
Are they even called “viariables” in squirrel ?
Yes, they are called "variables"

When do you use {} vs () vs [] ?

For this I suggested looking at documentation for JSON. {} is used to hold a table and [] is used to hold elements of an array. This is the most complicated question on your list.

General

What does the semicolon “;” do and when is it required?
Where do I go to find out what these mean…
==, ++, &&, += ?
Etc, etc

For the specific questions above, I suggest referencing the Arduino documentation. It is nicely organized and explains those operators better than I can.
http://arduino.cc/en/Reference/HomePage

Is code that is between {} just the same as being on one line? And is it only formatted on separate lines for readability?

Yes

What does “object oriented” mean
What is a class?

You can ignore object oriented design at first. A class is a model from which you can make an object. You can make many objects from the same class. it is a big topic and a powerful tool for writing well organized and portable code. I don't think the code is complicated but it takes some experience or a good reference book to use object oriented design properly.

What parts of the IMP code are caseSensitive and which are not CasEsensITive

I think it is all case sensitive - that is how I treat it

The squirrel language reference is here:

https://electricimp.com/docs/squirrel/

@impulsepower - Our Tech Writer @smittytone has been working on a wonderful Squirrel Cheat Sheet, which I think covers just about every question you asked :slight_smile: We’ll make sure to post about the new cheat sheet on the forums when it’s available :slight_smile:

Along with the language reference @mjkuwp94 pointed out, Tony also wrote a Squirrel Programming Guide, which can be found here:

https://electricimp.com/docs/squirrel/squirrelcrib/

@mjkuwp94
thank you for your reply, I appreciate your comments/clarification and those links and guides are helpful.

I look forward to the upcomming cheat sheet!

My request still stands… I really think a knowledgeable squirrel coder could do wonders to help us newbies understand the overall flow of a typical imp program.

Just a walk through of how/why things are organized in a well written squirrel/imp program. What various parts are doing and some guidance for the inexperienced.

A video tutorial with explanation of the various parts/bits/sections of imp code, I believe, would do a lot of good.

thanks
dwight

impulsepower - it seems like a really good point. the tough part is that I am not sure there is a typical imp program. Another tough spot is that in the anonymity of the internet it is really tough to know the audience and so it is hard to know where to begin and end.

First thing that comes to mind is to think of the imp as event-based. Typical events that I have seen on the device are a timer expiring, a pin changing state or serial data coming in. Typical events on the agent are timer expiring, data coming from the device or http requests coming from a web browser.

imp.wakeup is what I use to drive my device code. However, every project is different so my general advice may be useless for your project.

Perhaps you could explain the project you would like to do?

@impulsepower, I’d suggest you look at the Developer Guides, particularly those in the For All Users section. These were written specifically to address the key functional areas found in most (but, as @mjkuwp94 implies, not all) imp programs.

I’m working on an article ‘Anatomy of an imp Model’ which should help further.

Going over code line-by-line works in a one-on-one or one-on-few environment, because it works best with interactivity: the ‘what does this symbol do?’ questions. It can be hard to anticipate all of them in a written piece or a video. But the video idea is worth looking into.

As a self-taught programmer, I know that there are many times when you’ll see a line of code and not know what it does. I see this a lot looking at Arduino code. It’s not the basic syntax that’s in question, but the ‘shorthand’, eg

buf |= buf ~(1 << 3);

A video or article can’t cover all of these cases; you’re always going to see something in a program that doesn’t line up with examples you’ve seen. So it’s best (IMHO) to devise a process for figuring each one out: look up operators (|= , ~ and <<) and then try and pick out what’s going on yourself. Really tricky cases, post the line and ask here. Swot up on binary notation too, I’d say.

@impulsepower - I’m hoping to start a video tutorial series soon, but I’m bad at video stuff, so it is taking a long time to get things done :slight_smile:

I’ll see about writing some blog posts, tutorials, etc about common structures for imp code.

Here you go, @impulsepower: click on the following link for an early draft of the Squirrel Cheat Sheet

The Cheat Sheet is super helpful!!! Thanks for putting this together!