Title: "Computer Programming Made **Actually** Simple"
A computer program is a recipe for a computer. It looks something like...
from StringIO import StringIO
theme = editor.get_theme()
workflow.set_variable('CSS', workflow.get_variable('CSS Dark' if theme == 'Dark' else 'CSS Light'))
p = editor.get_path()
term = workflow.get_variable('Search Term')
pattern = re.compile(re.escape(term), flags=re.IGNORECASE)
from urllib import quote
dir = os.path.split(p)
valid_extensions = set(['.txt', '.md', '.markd', '.text', '.mdown', '.taskpaper'])
html = StringIO()
match_count = 0
for w in os.walk(dir):
dir_path = w
filenames = w
for name in filenames:
full_path = os.path.join(dir_path, name)
ext = os.path.splitext(full_path)
if ext.lower() not in valid_extensions:
found_snippets = 
i = 0
with codecs.open(full_path, 'r', 'utf-8') as f:
for line in f:
for match in re.finditer(pattern, line):
start = max(0, match.start(0) - 100)
end = min(len(line)-1, match.end(0) + 100)
snippet = (line[start:match.start(0)],
match.start(0) + i,
match.end(0) + i)
i += len(line)
except UnicodeDecodeError, e:
if len(found_snippets) > 0:
match_count += 1
root, rel_path = editor.to_relative_path(full_path)
ed_url = 'editorial://open/' + quote(rel_path.encode('utf-8')) + '?root=' + root
html.write('<h2><a href="' + ed_url + '">' + name + '</a></h2>')
for snippet in found_snippets:
start = snippet
end = snippet
select_url = 'editorial://open/' + quote(rel_path.encode('utf-8')) + '?root=' + root
select_url += '&selection=' + str(start) + '-' + str(end)
html.write('<a class="result-box" href="' + select_url + '">' + snippet + '<span class="highlight">' + snippet + '</span>' + snippet + '</a>')
if match_count == 0:
html.write('<p>No matches found.</p>')
The computer reads the recipe and you get a game like **Angry Birds**, computer software like **Microsoft Office**, or a website like **Youtube**.
A person who uses a program is called a **user**.
A person who creates a program is called a **developer**.
Recipes have various ingredents and various directions for using the ingedients. The various ingredients of a computer program are called **variables**.
Variables are names like **nouns**. Your recipe might require an *apple* and some *sugar* and a *blender*. These would be variables in your program.
The various directions are called **statements**.
Computer are not naturally smart. If I told a computer to cut an apple, I would have to tell it how, step-by-step. To save time, I would create something called a *function*.
A **function** is a **group of statements**. Some people see them as machines, because functions do something to variables. They are usually named like **verbs**.
For instance, if I put a strawberry into a blender function, the blender would blend and return a strawberry smoothie. So, I could type Blend() and the computer would know what to do.
Let's see an example
some statements here
some statements here
some statements here
some statements here
some statements here
My variables are:
Even though a bowl and temperature are not food items, they are variables, because they are nouns.
My functions are:
The Measure() function measures something. Looking at our ingredients/variables, we might measure water. We could measure temperature also (although you don't measure temperature with a measuring cup).
The Pour() function would pour something. We could pour water. We could pour water into a pot or into a bowl.
The Boil() function would boil something. If we put water into a boil function, it would be boiled. We could also boil milk.
The Stir() function stirs something. We could stir water in a bowl.
The SetTemperature() function would set a temperature. If we had a stove variable, we could set the temperature of the stove.
As you can see, some functions can be used on many variables. I can bake a cake, or I can bake a pie. I can boil water or milk.
In computer programming, the things that can be **substituted** in and out of a function are called **arguments/parameters**. They work just like the arguments in Algebra:
f(x) = 2x + 1
f(1) = 2*1 + 1
f(2) = 2*2 + 1
Let's say you wanted to make a game. First you would create all of your characters and game objects as variables. Next you would create some functions for your characters and game objects.
You might create a function called Jump(), so that when you type Jump(), an animatioin would play and start moving the character in the up direction.
Or, you might create a function called Run() which would move the character to the left or right while playing an animation.
Perhaps Apple inc. uses functions names Shutdown() and Startup() and OpenAppStore() in their coding of IOS. Perhaps!
When people write recipes, there is a **certain order** in which you are supposed to cook or prepare the food or supplies. In computer programming, it is called an **algorithm**.
For instance, you might tell the computer to gather all of the supplies first, and then you tell it to do stuff with those supplies. One main reason games or apps lag is because they have bad algorithms.
For example, I might tell the computer to Cut() and Butter() the bread after I tell it to Eat() the bread. The computer cannot cut and butter bread that it has already eaten, so you get an **error**.
Although a bad algorithm might not give you an error, it could take too much time, when there is an easier way.
I once saw a computer program that was a page long, and all it did was make an object follow the mouse cursor. I did the same thing with one line of code, and it was faster!
Say that you finish your game or app and run it, and nothing works! That means that somewhere, there is a mistake in your code. The process of **correcting errors** in your code is called **debugging**.
# SOURCE CODE
In compter programming, your **entire recipe** with its ingredients and instructions is called your **source code**.
A lot of programmers keep their source code a secret, like a secret recipe. Programs that are not secret are called **Open Source** programs.
There are different types of langauges you can write in, and each language has its own grammar rules. The **grammar rules** of computer programming is called the **syntax** of the language.
If your syntax is not correct, the computer will not understand what you are saying. In some languages they use a simicolon to end a statement, just like we use a period to end a sentence. Different syntax.
# PROGRAMMING STYLE
Your programming style is the way in which the developer **styles their source code**, usually according to a set of rules or standards.
Just as there are various styles for writing poems , there are different styles to writing programs.
Some rules a style might follow are:
- Indent all function code
- capitalize the first letter in a function name
- white-space between statements.
By default, the Python programming language forces you to indent function code (for style purposes). Styles are sometimes chosen for readability (by other developers).
If you want to write a computer program, you need something to **write it in**. You use a word processor to write essays, and you write programs in an IDE (**Integrated Development Environment**).
It is an environment that you develop in! Develop what? Develope programs -- those super tasty code recipe masterpieces! **XCODE** is Apple's IDE. You make iPhone apps in XCODE and Android apps in **Eclipse**.
Computers, much like humans, can only remember so much at one time. Anything stored in the memory of the computer can be accessed quicker than something that isn't.
Most data/directions go into the **RAM** (Random Access Memory) part of the computer brain. Another place information is stored is in the **ROM** (Read-only memory). I am no nerosurgeon so I will stop there. All you need to know is that you shouldn't overload the computer with instructions when it can only remember so much.
I wrote a program that made my computer calculate the ccurrent Year, Month, Day, Hour, Minute, and Second 20,000 times fast. My computer fan started humming
# FLOW CONTROL
No one wries a recipe that says:
*" Do this, do this, do this, do this, do that, done!" If you write intructions back to back like that, you are not being specific, and things could go wrong."*
For example, You tell the computer to bake the cake, then you tell it to stop baking, then you tell it to take the cake out of the oven, then you tell it to let the cake cook. Finally you tell it to eat.
However, how long is it supposed to bake? And how can you tell when it is ready? How long to let it cool? What temperature should it be when it is cool?
Your recipe has to have a flow. It has to have control flow.
# CONDITIONAL STATMENTS
The way you **create flow** in computer programming is by using **conditional statments**.
A conditional statement is a statment like:
*"If the temperature is 100 degrees, take the cake out of the oven." Otherwise, if it is 90 degrees, leave it in the oven. If it is anything else.."*
The way you say **if** in computer programming is with the "if" keyword. the way you say *otherwise* is **else if**." The way you say *if anything else* is **else**.
Here is an example program in the Python language that aturally works. In Python, "def" means "define a functiion." Temperature is the variable:
print "Baking the cake Sire..."
print "Taking the cake out of the oven Sire..."
print "Leaving the cake in the oven Sire..."
print "Eating his delcious scrumptious cake..."
print "WOOF! WOOF! WOOF!!"
temperature = 0
raw_input("Press Enter to leave this terrible place...")
A **loop** is how you make a computer **repeat** an instruction. You could make it repeat a whole function or just a single statement.
There are two main types of loop statements. There is the **while loop** and the **for loop**.
## While Loop
A while loop is like saying, "**As long as**.." Short for "as long is" is *while.*
If you have a temperature variable, temperature can chance. You might say, "While the temperature is 90 degrees, keep the cake in the oven." As long as the temperature is 90 we will keep it in the oven.
## For Loop
A for loop is like saying, "**Until**..." The computer will do something until something else happens. If we have a cake variable and a temperature variable, we could Bake() the cake until the temperature is 100 degrees. Once the cake is 100 degrees, we stop baking it.
# DATA TYPES
An apple is a type of fruit. A pecan is type of nut. A male is a type of person. When you give a **variable** a **type** in computer programming, you are giving it a **data type**.
The basic types of variables in a computer program are the:
A string is a string of characters. Strings are like **words** in English.
Strings are usually put in double or single quotes:
- "This is a string"
- 'This is a string also'
The spaces between words count as a character too!
An **Integer** is a **number**
A **Float** is a number also, but it is a **number with decimals**
A **character** is a **single letter number symbol**:
A Boolean is like a **switch**. You can turn a variable ON or you can turn a variable OFF. ON = TRUE in computer programming. OFF = FALSE. If you had a variable named *switch*, you could turn it OFF/FALSE.
The on/off switches in your settings make use of Boolean variables, I would suppose.
- light_on = True
- door_open = False
An **array** is a **list** of items. If you had a variable called *basketOfFruit*, inside of it you could put an array of fruit. An array is a variable that can contain other variables or data types.
A **tuple** is a list that cannot be changed (it is **immutable**).
## Dictionary/Associative Array
A **dictionary** is an **array** that pairs each **variable with a key**. The only way you can access each variable is by using the appropriate key. They can be used to store properties of values.
What if you wanted to make your own data types? **Custom data types** are made using classes. Classes are used to classify variables.
Classes allow you to give your variables **characteristics**. For example, all humans share certain characteristics. So, you could create a human calss and put some male and female variables in it.
You can also create some functions for your human class like, Walk(), Run(), Speak(), Think(), etc.
# SUPERCLASSES AND SUBCLASSES
Sometimes classes can be part of other classes
- Female Class
- Woman Class
A woman is part of the female class, and a female is part of the human class. If I had an object named *Sarah*, she would be a part of the woman class and inherit traits from the female and human classes.
The female is the superclass of the woman class, and the woman class is the subclass of the female class.
An apple is a type of fruit. A grannysmith is a type of apple. The superclass of the apple class is? the subclass of the fruit class is?
A **function** that is **in a class** is called a method.
Classes should be named like types of things. An apple is a type of fruit, so it would be in a fruit class.
Another way to name a class is as a subject. In math class you learn math. Methods in a math class might be Add() Subtract() Divide(), and Multiply(). Of course, you would have integer and float variables in it.
Once you have given a variable characteristics it then becomes an object. They call an object an **instance** of a class because it contains all of the properties or characteristics of the class.
Now your human variable(object) can either Walk(), Talk(), Speak(), or Think() when you want it to. You might type:
Now your human variable can do the Speak() function.
Programing that uses objects is called Object Oriented Programming (OOP).
# Instance/Member Variable
A **variable** defined **inside of a class** is called an **instance variable**. Also called a **member variable**
An apple is part of the fruit class, in which there are variables like taste, color, type etc. Taste, color, and type are instance variables. They are variables that belong to the fruit class.
Why bake bread from scratch when you can buy a loaf? **Collections of classes, functions and variables** made by other peope that you can use in your own program recipe are called modules/libraries.
Interativity is a way for **users** like you and me to **interact with** and change the vode of a **program** without having to open the code in an IDE and change variables or functions.
For example, when you select a number in the timer section of the clock app on your iPhone, you are actually changing the value of a ariable in the code. Let's say the name of that variable is *timer*.
When you tap the "Start" button, you are starting a function (remember that functions do something to variables). If I had to guess, the start function counts down from the timer number.
All you had to do was scroll and tap to manipulte the code. You *interacted* with the program.
# EVENTS, EVENT LISTENERS, EVENT HANDLERS
When you **press a key** on your keyboard, that is an event. When you **click a button** on your mouse or **swipe or pinch** on your ipad, that is an **event**.
The **event listener** is a function that **detects the event**, and the **event handler** is a function that **links that event** to a function or class in your program.
Events are what connect our physical actions to the didgital actions of the computer, making it interactive.
# API (Application Programming Interface)
An **API** is a bunch of **access points** that allow your own program to **communicate with anothers' program**, without having direct access to their secret recipe.
In other words, if you want to make your own twitter app that can post to twitter, you have to use Twitter's API. Twitter has to give you a **key** to access certain parts of their API.
An API is a bunch of custom variables and functions that make up Twitter. Twitter allows you to use them to program for their program.
This keeps people from stealing the secret Twitter recipe of from hacking Twitter.
After you write your program you have to translate it back into something the computer actually understands (into machine language). This process is called **compiling**. A **compiler** is a program that compiles programs.
When you finally run your program, the computer executes it. In other words the instructions in the recipe are carried out by the computer.
# PROGRAMMING LANGUAGES
## HIGH-LEVEL LANGUAGES
The easier the language you program in is to understand by humans, the higher its level is (most of the time).
A programming language like LUA is a high-level language. They say it is more "**human-readable**".
## LOW-LEVEL LANGUAGES
Computers cannot understand high-level programming languages. Computers understand what is called "**machine language**." Machine language is the lowest level language. **Assembly** is the second lowest low-level programming language.
Assembly is the middleman language between machine code and human-readable code.
## COMPILED LANGUAGES
A compiled programming language is a program that gets compiled (into machine language) and thereafter, read by the computer.
- Objective C
## INTERPRETED LANGUAGES
An interpreted programming language is one that is not translated, but interpreted, by means of an **interpreter**. The interpreter executes the program directly, without having to translate it to machine code.
# ADDITIONAL INFO
## Operating System
- An **Operating System** is a **big program** that **runs other programs** like:
- Mac OSx
- There are even mobile operating systems:
- Windows RT
- A **Virus** is a **program that corrupts** other programs.
- A **Hacker** is a **person** who **uses unconventional means** to access something.
- There are three types of hackers
- White Hat hackers
- Grey Hat a hackers
- Black Hat hackers
- Pseudocode-- false(fake) code, is the steps of a program written in plain English. No syntax is required. It's more of an outline.
- A fork is when a person modifies your secret recipe(source-code), making it distinctly different) and creates a separate program. This usually creates a schism between users.
- Forks usually happen when users or developers