1 of 16

Coding - Practical Tools

2 of 16

What is an IDE:

In any computer Coding language, an IDE is the Integrated Development Environment, which is a software application that helps programmers develop code. The “Sandbox” found on the CodeHS website, the many “Studios” found on the Code.org website, the Arduino app on the computers (or online), MakeCode Arcade, MakeCode for Micro:bit, and Scratch Coding are all examples of IDEs.

Some features of IDEs include:

  • Helping the coder find and correct syntax errors
  • Suggesting or providing code commands or code blocks
  • Running simulations to de-bug

3 of 16

What are “Docs” and an API?

In any computer Coding language, the creators of the language create extensive files called “Documentation” or “Docs” that provide coders with information about that coding language. An API is an Application Programming Interface, it is usually part of the “Docs” or documentation that allows coders, novice or experienced, to investigate each command or codeblock and get an explanation and even an example of how that command or block is used in a project for that coding language.

Some features of Docs and APIs include:

  • Breaks down the code into sections
  • Helps the coder understand the syntax, logical structures, and proper sequence of commands

Link to Arcade API - “Docs”. Links to CodeHS PythonTurtle & Python3 Docs Link to Scratch Docs

4 of 16

Important Coding Concepts

Regardless of the Coding Language

5 of 16

Pro and Experienced Coders Write Elegant, Efficient code

This means:

Coders use the fewest number of lines of code to accomplish a task

Instead of typing “forward 10” 100 times in a row, they might write “forward 10, repeat 100 times” (or they might write “forward 1000”. Because in coding, there’s almost always more than a couple ways to do stuff!)

Coders “comment” or “annotate” their code to let others know what their code does, or “comment out” a line of actual code so they can troubleshoot without deleting it.

# This code makes a square or // This code makes a square

Coders test their code often to discover and fix errors. They don’t wait until it is all written and THEN test it.

6 of 16

Pro and Experienced Coders Write Elegant, Efficient code (continued…)

This also means:

Coders look for patterns and code sequences that are repeated often - because they might be able to use specific coding tools to eliminate redundancies (repetitions)

Coders don’t “reinvent the wheel” - they use (borrow) code sequences from others when it is appropriate

Coders work with other coders to share and get ideas, troubleshoot problems, and brainstorm to find solutions

Coders use the Design Thinking Process to guide them while they invent and create

7 of 16

Once you find a pattern, you can use Loops!

Example:

To make a square drawing I move the sprite forward, turn right 90 degrees, then forward, turn right 90 degrees then forward, turn right 90 degrees then forward, turn right 90 degrees. That is 8 lines of code (4 forwards, 4 turns) I could use 3 lines of code: move, turn, repeat those two lines of code 4 times.

I could even use a ‘nested’ loop - a loop within a loop.

Example:

I could make a cool design by having the code make a square, then turn 36 degrees, and repeat that 10 times. So inside my repeat loop of 10, I will have my code for the square, which is a loop that repeats 4 times.

I could also use a repeat loop to make an alarm sound play 10 times to signify the beginning of a new level in my game.

8 of 16

Once you find some code that you use often, but at different times in the code, you can use “FUNCTIONS” to store the code and then get it every time you need it.

Example:

I could create a “Function” out of my 3 lines of code to make a square (move, turn, repeat 4 times). Then I could name the function “Make a Square”. It would be its own separate code that just hangs out waiting to be “called” by the main code.

I could create a function to make my character in my game do a happy dance each time the player scores.

I could create a function to make my rover back up several inches, beep, flash the red light, turn right 25 degrees and resume forward every time it senses an obstacle in front of it.

9 of 16

FUNCTIONS

PROCESS:

First I must DEFINE a function - that means, similar to a variable, I have to give it a name. A name that is reasonable, that let’s others looking at my code know likely what this function will do.

For instance, using PythonTurtle, if I name, or define (def) my function square(): I can assume that the code will probably make a square. If I define it purple_oval(): well, you get the idea. If I define it bob(): it will work, but later, I might not remember what the function defined as “bob” does. If the function is only 3 or 4 lines of code, no problem, but imagine if my function is 100+ lines of code!

2nd: The code of the function MUST be indented under the defined name. (similar to the repeat) We use the Tab key to ensure the indent is precise. Using the spacebar, we might add too many or too few spaces and the code will be confused, and in error.

10 of 16

FUNCTIONS

PROCESS:

NOTE: in most coding IDEs, the code for my Function usually will be near the beginning of my entire code project.

Third - now that I have created code and made it into (defined it as) a FUNCTION, somewhere in my main code commands, I can now CALL that function as many times as I want!

For instance (in Python Turtle…)

Can you imagine what this might look like?

11 of 16

Sometimes, we have code that uses number, letter or word values, and those values might change at different times while code is running. Coders use “VARIABLES” to keep track of these values.

Example: Keeping score

The score starts at 0, but the player gets a point. We have to create a “space” for the score to be saved. The space is a variable. We name the variable “Score”. At the start of the code, we set the variable “score” to a value of zero. �“Score = 0”. When the player gets a point, the code changes the value “Score = 1” and so on.

Example: User/Player Input

The code asks the user/player how many sides they want their polygon to have, and the user/player enters 3. The coder creates a variable called “Sides”. When the user/player enters the #3, the code changes the variable to: “Sides = 3”

12 of 16

And finally, Coders have to tell the code WHEN to begin

Whether the section of code is on a computer, a device or a robot… it still needs to know when to begin.

These are called “EVENTS” and are often based on whether a condition exists. (so it is asking a question… aka CONDITIONAL) Examples:

  • When electricity begins flowing? (turn it on)
  • When a condition is present (or a question is answered):
    • Is it close or far?, Is it bright or dark? Is it blocked or clear? Is it loud or soft?
    • Is the value < (less than) or > (greater than) or = (equal to) a specific value?
    • Is it a specific color? A specific level of sound or light? A specific distance away?

These lines or blocks of code may start with:

If…Then… If…Then…Else… While…Do… When…Do…

13 of 16

Click HERE to view & run the code.

14 of 16

Click HERE to view & run the code.

15 of 16

16 of 16

User Input - Makecode Arcade, Scratch, CodeHS Python or if you use another online Python editor/compiler IDE:

Process:

Ask the user for input. Either will be a numeric value (number) or a text value (“string”)

User input is then stored/saved for later use - generally saved to a variable that you have created.

User input is then used by other code. It might be compared, or it might be repeated. For example: if you ask the users name, then you might have the game use their name to talk to them during the game. What would be a good variable name for this type of data collected?

Example 2: You might have asked a quiz question so then you will need to compare it to the correct answer to see if the user got it correct.