A computer program is a recipe for a computer. It looks something like...
THIS! (Scary Stuff).
The computer reads the recipe and you get a GAME like Angry Birds, or a COMPUTER SOFTWARE like Microsoft Office, or a WEBSITE like Youtube.
Recipes have various ingredients and various directions for using the ingredients. The various ingredients of a computer program are called VARIABLES. The various directions are called STATEMENTS.
Variables are named like NOUNS. Your recipe might require an APPLE and some SUGAR and a BLENDER. These would be variables in your program.
However, computers are not naturally smart. If i told a computer to CUT an APPLE I'd have to tell it how step by step. To save time in the future 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 blends and you get a STRAWBERRY SMOOTHIE. So in the future I could type BLEND, and the computer would know what to do.
Let's see an example:
My variables are: SALT, WATER, BOWL, POT, and TEMPERATURE. Even though a bowl and a pot and temperature are not food items, they are variables because they are nouns.
My Functions are: MEASURE, POUR, BOIL, STIR, and SET TEMPERATURE. Remember that functions DO SOMETHING to variables, and that they are named like VERBS.
The MEASURE FUNCTION measures something. Looking at our ingredients/variables, we might measure WATER. We could measure TEMPERATURE also (but you don't measure temperature with a measuring cup).
The POUR FUNCTION would pour something. We could pour WATER. And we might 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 might also BOIL MILK.
The STIR FUNCTION stirs something. We could stir WATER in a BOWL.
The SET TEMPERATURE FUNCTION would set a temperature. If we had a STOVE VARIABLE, then 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 programing, the things that can be substituted in and out of a function are called ARGUMENTS. They work just like the arguments in High School Trigonometry. Remember f(x)?
Let's say you want 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 animation would play and start moving the character, or whatever else you might want to happen when you say JUMP.
Or you might create a FUNCTION called RUN, which would move the Character and start playing an ANIMATION.
Perhaps Apple uses functions named SHUTDOWN and STARTUP and OPENAPPLESTORE 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 the supplies first, and then you tell it to do stuff. 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 can't cut and butter bread it has eaten, so you get an ERROR.
Although a bad algorithm might not give you an error, it might 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!
So, say you finished up your game or app and run it and NOTHING WORKS!!! That means somewhere there is a mistake in your code. The process of correcting little errors in your code is called DEBUGGING.
In computer 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 languages you can write a program in, and each language has it's own grammar rules. The grammar rules of computer programming is called the SYNTAX.
If your syntax is not correct, the computer will not understand what you are saying. In some languages they use a SEMICOLON to end a statement, just like we use the PERIOD to end a sentence.
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's an environment that you develop in! Develop what? Develop programs-- those super tasty code recipe masterpieces! XCODE is Apple's IDE. You make iPhone apps in XCODE. 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 info is stored is in ROM (READ-ONLY MEMORY). I am no neurosurgeon so I will stop there. Hehe.
All you need to know is that you shouldn't put more on the computer than it can take. You can't overload it with instructions if it can only remember so much. Poor computer :(.
I wrote a program that made my computer calculate the current Year Month Day Hour Minute and Second 20,000 times really quickly. My computer fan started humming. Haha.
No one writes a recipe that says: "Do this, do this, do this, do this, done!" If you just write instructions back to back like that, you aren't 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 it cool. Then 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 homey!! haha
The way you create FLOW in computer programming is by using CONDITIONAL STATEMENTS.
A conditional statement is a statement 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 "if". The way you say OTHERWISE is "else if". The way you say IF ANYTHING ELSE is "else".
Here is a program written in the PYTHON language that actually works. In Python, DEF means DEFINE A FUNCTION. Temperature is the variable.
A loop is how you make a computer REPEAT an instruction. You could make it repeat a whole function or you can make it repeat a single statement.
There are two main types of loop statements. There is the WHILE LOOP and the FOR LOOP.
A WHILE LOOP is like saying, ''As long as..." Short for ''as long as'' is WHILE.
If you have a TEMPERATURE variable, temperature can change. So you might say, ''While the temperature is 90 degrees, keep it in the oven.'' As long as the temperature is 90 we keep it in the oven.
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 can stop baking.
An apple is a TYPE of fruit. A pecan is a TYPE of nut. A male is a TYPE of person. When you give a variable a TYPE in computer programing, you are giving it a DATA TYPE.
The basic TYPES of variables in computer program are the STRING, INTERGER, FLOAT, BOOLEAN, and ARRAY data types.
A STRING is a STRING OF CHARACTERS. Strings are like WORDS in English.
Strings are usually put in quotes. "This is a string" The spaces in between the words actually count as a character too!
An integer is a NUMBER.
A FLOAT is a NUMBER also, but it is a number with decimals.
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.
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.
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 CLASS 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.
A WOMAN is a 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 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 FruitClass is?
Functions that are in a class are called METHODS.
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, MULTIPLY. Of course you would have INTEGER & FLOAT VARIABLES in it.
Once you have given a variable characteristics it then becomes an OBJECT.
Now your human variable can either walk, talk, speak, or think when you want it to. You might type: "human.Speak()" and then your human variable could do the SPEAK function.
Programming that uses OBJECTS is called OBJECT ORIENTED PROGRAMMING (OOP)
Why bake bread from scratch when you can buy a loaf? Collections of classes, functions, and variables made by other people that you can use in your own program recipe are called MODULES/LIBRARIES.
Interactivity is a way for users like you and me to interact with and change the code 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 variable in the code. Lets say the name of that variable is TIMER.
When you tap START you are starting a function (remember that functions DO SOMETHING to variables) . And if I had to guess, the start function counts down from the timer number.
All you had to do was scroll and tap to manipulate 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 that is an event. When you SWIPE or PINCH on your iPad, that is an event.
The EVENT LISTENER detects the event, and the EVENT HANDLER links that event to a function or class in your program.
Events are what connect our physical actions to the digital 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 others' programs, 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. And 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. And twitter allows you to use them to program for THEIR program.
This keeps people from stealing the secret Twitter recipe or from hacking Twitter.
Okay! I have written a PDF with more information on programming. It is still a work in progress though. Copy the link below and paste it into a browser. (Link will be up for a limited time.)
That's it for now (You might be getting memory overload. )
To check your comprehension, look up a computer program on google and see how much of it you can recognize. See any variables? Functions? Classes?
If you want to program on your iPad, try out CODEA. Price: 9.99
If you want to practice ALGORITHMS, CONDITIONAL STATEMENTS, and LOOPS, check out the game CARGO-BOT. It was made with CODEA.
You can program in the PYTHON programming language on your iPad!!
CODECADEMY is my favorite website for learning computer programming.
Making levels in LITTLE BIG PLANET for the PS3 will help you learn about LOGIC and CIRCUITS.
You can make a game on your ipad!!! Also, if it is good, you could get it release on the App Store. Or you could win a ps4!
Do Puppies Exist?
This is the Code... (The lines with the # sign in front of them are called COMMENTS. They have no effect on the code. They help explain the code.)
This is the result.
This is written in the PYTHON programming language.
Count & Down:
This code is written in the LUA programming language, notice the difference in its syntax from Python. The double dashes are how you make comments in Lua. I used the CODEA app for this example.
Turn on the Lights!:
This code is heavily commented to clarify everything about the code. Most of the time comments are not so lengthy.
A list of names (Python):
This small script uses for-loops and lists(arrays). I am using the Pythonista app.
A text version of this guide can be viewed here: http://markdownshare.com/view/eb975811-188e-4a9f-ab34-7a231dbfb4ee
The creator of this guide has not included tools