Key Elements of Programming

  1. Human Language
  2. Programming Language
  3. Machine Language
  4. Pseudocode
  5. Functions
  6. Loops
  7. Conditionals
  8. Variables
  9. Constants
  10. Syntax
  11. Style
  12. Camel-case
  13. Boolean

Human Language

Human language is your native tongue. If English is the first language you learned, then English is your native language.


Machine Language

Machine language is the language of computers. Essentially all computers use the binary number system as their language. Programs, pictures, books, music, and data are stored as a series of ones (1) and zeros (o). Ones (1) signify ON or TRUE while zeros (0) signify OFF or FALSE.

In the binary number system, a single 1 or 0 is called a bit. Bits are usually organized into groups of 8 called bytes.

Example byte: 1100 0011

  • 1 kilobit is 1000 bits.
  • 1 kilobyte is 1000 bytes.
  • 1 kilobyte is 8000 bits or 8 kilobits.
Here is a picture with 1-bit of color. Each pixel is stored as a single bit and can therefore represent two colors black or white (1 or 0).
2-bits of color give you 4 color options 00, 01, 10, and 11. Black, dark grey, light grey, white.

Programming Language

A programming language is used to bridge the language of humans with the language of machines. C++, Java, Perl, Python, Swift, Scratch, PHP, BASIC, and JavaScript are all examples of programming languages. Some programming languages more closely resemble the language of humans. Other programming languages are close to the binary language of computers. Regardless of the language used, it must be translated to machine language before the CPU can execute any code.


Pseudocode

Pseudocode is organized much like a programming language, but is intended for human reading rather than machine reading. It is used for designing and outlining programs in an easy to read/understand manner. Because pseudocode is organized like a programming language, it is relatively easy to move from pseudocode to a proper programming language. The rules for pseudocode are determined by whoever is doing the programming (or perhaps their boss), but these rules frequently resemble rules for a common language like C, Python, or BASIC.


Functions

Functions are named sections of a program. There are used in the process of breaking down a complex program into simpler pieces. These smaller pieces are variously called functions, methods, subprograms, routines, and subroutines. Breaking down a complex problem allows for better planning, organization, and easier results. A program which has been broken into logical pieces is also easier to read, fix, modify, and extend.

You can read all about breaking down problems here.


Syntax

The syntax of a computer language is the set of rules that defines how a working program must be written in order for the computer to execute it. A syntax error will result in a program which does not function at all.


Style

Style is the set of rules or guidelines for appearance and neatness used when writing the source code for a computer program. The style of a computer language is the set of best practices used to make a program easily readable by humans. A program with style errors may still function correctly, but it will be hard for people to read. Examples of such errors include non-descriptive names for functions and variables, lack of whitespace, poor use of functions (decomposition), and lack of comments.


camelCase

camelCase is a naming convention used in many languages to ensure good style. A name written in camelCase will start with a lower case letter. Each consecutive word will start with an uppercase letter. The result is a name that looks like myFavoriteFood or cleanKitchen. In the STEAM Lab, all variables and functions must be named using camelCase.


Variables

Variables are named pieces of data. They can come in many shapes and sizes, but their purpose is to hold data which may change in value. For example, the temperature outside is changeable and might be stored in a variable called tempOutside.

  1. tempOutside = 32.14 degrees Farenheit (the temperature is always changing)
  2. numberOfStudents = 31 (every class in the STEAM Lab has a different number of students)
  3. currentScore = 12 (hopefully you’ll keep scoring more points)

Constant

Constants are named pieces of data. They can come in many shapes and sizes, but their purpose is to hold data which can never change in value. For example, the speed of light is a value which never varies and might be stored in a constant called speedOfLight.

  1. absoluteZero = -273.15 degrees Celsius (Nothing can be colder than this. This is constant)
  2. speedOfLight = 299,792,458 meters per second (Nothing travels faster than this.)
  3. pi = 3.1415… (missing a few decimal places, but Pi never changes)

Loops

Loops are a sequence of instructions that are continually repeated until a certain condition is reached.  The code (sequence of instructions) may be repeated a specific or infinite number of times. In Scratch, there are forever, repeat until, and do x times loops. Code inside the block of a loop, will be repeated dependent on the type of loop and conditions used.

play the drum 10 times
This loop will play a drum sound 10 times.
This code asks a question once and then loops the question until the user answers it correctly. If the user answers the question correctly the first time, then the loop never runs!
This code asks a question once and then loops the question until the user answers it correctly. If the user answers the question correctly the first time, then the loop never runs! In this example, apple, banana, and orange were selected as the only acceptable responses. This code is a form of exception handling.

Conditionals

Conditionals are a critical feature in a programming languages which allow code to be executed under only some circumstances. Code inside the block of a conditional will only execute if the condition is TRUE.

In this code example, when "tempOutside > 72" is TRUE, the air conditioning will turn on. Otherwise, the heater is on.

In this code example, when “tempOutside > 72” is TRUE, the air conditioning will turn on. Otherwise, the heater is on.

If-Then-Else-diagram


Boolean

Boolean is the name for an expression which can only be TRUE or FALSE.

Boolean Expression: 17 is not greater than 32, so this expression is FALSE.
Boolean Expression:
17 is not greater than 32, so this expression is FALSE.

Boolean Expression: 4 does equal 4, so this expression is TRUE.
Boolean Expression:
4 does equal 4, so this expression is TRUE.

Boolean Expression: 3 is less than 4, so this expression is TRUE.
Boolean Expression:
3 is less than 4, so this expression is TRUE.

Boolean Expression: 3 does not equal 7, so this expression is FALSE.
Boolean Expression:
3 does not equal 7, so this expression is FALSE.