Discover this podcast and so much more

Podcasts are free to enjoy without a subscription. We also offer ebooks, audiobooks, and so much more for just $11.99/month.

Syntax; the spelling and grammar of programming

Syntax; the spelling and grammar of programming

FromLearn Programming and Electronics with Arduino


Syntax; the spelling and grammar of programming

FromLearn Programming and Electronics with Arduino

ratings:
Length:
12 minutes
Released:
Mar 25, 2017
Format:
Podcast episode

Description

You Will Need: The Arduino IDE installed and an Arduino connected to your computer. Discussion: In this lesson, we're going to be talking about programming syntax.  We'll be introducing some of the basic programming syntax that you'll be using every time you write a sketch. Specifically, we'll be talking about: what programming syntax is comments the semicolon keywords function syntax layout & indentation Programming Syntax What is programming syntax? I like to use this analogy.  You can think of programming syntax like the punctuation and grammar of computer programming. If you've ever read a book, then you're probably really familiar with written punctuation and grammar.  For example, in the written word, we use things such as periods, commas, dashes, or semicolons. Languages also have verbs, nouns, diphthongs, and all types of crazy grammar that goes with them.  The punctuation and grammar that you're familiar with are tools that help us communicate effectively with one another in the written word. Commas convey a pause.  Periods let us know a sentence has ended.  Italics and bold text let us know if a word is emphasized.  When we're communicating to another person, these are tools that help us do so. Just as written sentences require correct grammar and punctuation to be correct, the same is true for programming languages. However, with programming, in most cases we're communicating with the compiler - the compiler being the program that looks at our code and creates machine language for us. The programming syntax that we use is meant to communicate our intent to the compiler program.  For this reason, the programming syntax MUST be correct. You can get away with messing up some grammar and punctuation when you're writing to a friend or an audience.  They'll probably understand what your intent is. On the other hand, if you make an error in your programming syntax, there's almost assuredly going to be an issue.  You’ll have either a compiler error when you go to compile the code or a subtle and hard to find bug in the actual operation of your sketch. When you start out, you'll likely find that getting all the program syntax correct is a major hassle.  It just doesn't feel natural, and the compiler is far more exacting than most “red pen crazy” elementary school teachers. The good news is that as you get more comfortable in the programming language, the syntax will come more naturally to you.  It will become second nature as you write your code. Comments Let's start with one of the most important tools in programming - the comment.  Comments are descriptive statements that a programmer writes to help explain the code. They are syntax and punctuation that really have nothing to do with the compiler.  In fact, the whole purpose of a comment is so that you can hide these words from the compiler. There are two ways to create a comment.  The first is the single line comment, which uses a double forward slash. It looks like this: Notice that all the text after the double forward slash is grayed out. If you have a lot to say, then you can use a multi-line comment.  To start a multi-line comment, you type a forward slash followed by an asterisk.  Now you can type multiple lines of comments. You'll notice that they're all grayed out.  Also, when you press the enter key after that first line, the Arduino IDE actually auto closes the comment for you.  It is closed with an asterisk and another forward slash. These additional asterisks on the lines in between are not required, but they are added by the Arduino IDE.  These help the multi-line comment stand out from the rest of the code. As I said, comments are hidden from the compiler.  They are words specifically for any other person reading your code - not the computer. I won't go into the substance of comments right now.  You'll learn more about what comments should say as you work through the course, but I will say that comments should be descriptive statements explaining what
Released:
Mar 25, 2017
Format:
Podcast episode

Titles in the series (61)

Video lessons on learning programming and electronics with Arduino. This is part of our Arduino Crash Course and Arduino Course for Absolute Beginners. It's designed to take someone with little or no experience in programming and electronics and get them fast-tracked to learning the skills to prototype using Arduino. We'll include some lessons from the first edition and the second edition of our training course.