Introduction to Programming Concepts (for True Beginners!)
Thanks to our sponsor:
Thanks to our sponsor:
A few quick announcements
Upcoming Events
Introduction to Javascript & jQuery
Saturday, July 26, 2014
Simple Energy
Welcome!
Girl Develop It is here to provide affordable and accessible programs to learn software through mentorship and hands-on instruction.
Some "rules"
- We are here for you!
- Every question is important
- Help each other
- Have fun
Your instructors
- Teri Charles
- Jen Skiendzielewski
Computer Programs
- Computer programs are everywhere. They:
- Run parts of your car.
- Let you check your email.
- Underlie that favorite app on your smartphone.
- But what are they, really?
What is a Computer Program?
- At its core, a computer program is a way of getting something done.
- One of the ways to accomplish "getting something done" is a list of instructions that tells the computer exactly what to do and allows interaction with human beings.
- Those instructions have to be written in a "language" that the computer can understand.
Programming Languages (1/2)
- A programming language is basically a set of strings (letters, numbers, commands) that is changed into machine code that the computer can understand.
- The language you use for a program depends on a number of things:
- How the program will be used.
- What you want the program to do.
- What languages you know.
Programming Languages (2/2)
- Computers don’t exactly understand programming languages (such as Java or Python). They need to be transformed into the computer language that they can understand.
- That computer language is strings of 1’s and 0’s-- binary numbers that most people can’t read easily-- to be able to do anything with them.
- For example, the letter 'A' in a computer has the binary representation: 01000001.
- Despite being able to decipher those unintelligible strings of 1’s and 0’s, computers are actually pretty dumb.
Programming Languages
- To develop websites, you might use HTML, JavaScript, Python, Java, PHP.
- To create databases and move information in and out of them, you might use MySQL, SQL, Dbase.
- To write applications like Microsoft Word or Adobe Acrobat, you might use C++, Java, Visual Basic
Important to Remember
- One of the most important things to remember is that when programming, you are doing something for people, and that the computer and the program mediate that. ~Michael Bolton (Software Tester extraordinaire)
Computers are dumb
- Computers can only do what they have instructions for-- and they take those instructions VERY literally.
- As a result, you have to tell them every single thing you want them to do and every single thing to take into consideration.
- If you leave any instructions out (or put them in the “wrong” order), the results might not be what you expect.
Demonstration
- One person is the "program", and one person is the "computer".
- The "computer" has to do literally what the "program" says to do!
- We did one person (program) telling the other person (computer) what to do verbatim (answering the phone)
Memory
- A computer doesn’t have a memory like we do. Sure, a computer has “memory”-- In fact it has a couple of kinds...
Kinds of Memory - ROM
- ROM or Read-only memory is the more permanent kind.
- ROM is used in the computer so that the processor does not have to look for important pieces of data when switched on, like the operating system.
- For the most part, you cannot edit files in ROM and data on it cannot be erased by turning off your computer.
Kinds of Memory - Storage
- More permanent, more long term memory.
- This memory is what the computer uses to store programs and files that you create.
- Examples would be the hard drive on the computer, thumb drive, or external hard drive.
Kinds of Memory - RAM
- RAM or Random-access memory is less permanent.
- RAM is the memory that the computer uses to do its "thinking" (such as when you're working on a Word document, the changes you make before you hit Save, are stored in RAM).
- When computer is turned off, data in RAM is gone and cannot be recovered unless it has been saved.
Programming structures
- No matter what programming language you use, the structures that are available are fairly similar.
- Variables
- Logical structures:
Variables
- A variable is essentially a storage container for information.
- Examples:
- There are different kinds of variables based on the information that you want to store.
Integer Variables
- Integer variables are used to store positive or negative whole numbers.
- Examples:
- Amazon: number of books you can order is an integer (also the number in 'cart').
- More than likely, Amazon stores this field as an integer because they’ll want to do calculations with it. If you order 2 copies of a book, the program multiplies the price by 2 to get the total cost.
- Another example is in eBay. When you select something to order, the quantity is an integer. See what happens when you put in the letter 'a' or a special character like '@'.
String Variables
- String variables are used to store text.
- Examples:
- Staying with Amazon, if you went into your profile, fields like name, address, state, and city are strings.
- Usually when a string is created in the program, it's surrounded by quotation marks.
Numbers as strings
- You can store a number as a string variable.
- If you store a number as a string variable, you can’t use it in any math calculations.
- For example, credit card numbers are integers but you would never use them in a mathematical calculation.
- Another example would be postal codes. Even though the USA uses only numbers, not all countries do. So if you make your zip code field an integer, no other country can use it except the USA.
Boolean Variables
- Boolean variables are used to store the value TRUE or FALSE (yes or no).
- You define a condition, then use a Boolean to tell the computer whether that condition is true or false.
- Example:
- Amazon: If the login equals true, your name shows up, your cart is populated, etc.
Logical structures
- Now that you can store data, you probably want to do something with it.
- Logical structures provide the framework for using that data to "get stuff done".
- If you understand the concepts, you can learn how to represent them in most programming languages.
Operators
- Operators are words or symbols that let you compare, combine, or evaulate something to produce an output.
- A few xamples:
- = (equal to)
- > (greater than)
- < (less than)
- >= (greater than or equal to)
- < = (less than or equal to)
- != (not equal)
- and
- or
If/Then/Else
- If/Then/Else statements evaluate a condition and take actions based on the result:
- If the condition is true, the computer does the action or actions that are listed after the IF statement (in some languages, the "Then" is implied).
- If the condition is false, the computer does the action or actions that are listed in the Else statement.
If/Then/Else Examples
- Still staying with Amazon.
- "IF" you're logged in, show your name and cart numbers. "ELSE", show the login page.
- "IF" you're an Amazon Prime member, you get free shipping. "ELSE", you get to pay for shipping!
Let's Do Some If/Then/Else! (1/4)
If/Then/Else Excercises (2/4)
- For this excercise, we're using Ruby.
- Go to repl.it, which is an online terminal to practice writing code.
- Choose 'Ruby'.
IF Excercise (3/4)
cart_total = 8
if cart_total > 2
print "You get free shipping!"
end
- Change the numbers to see what happens.
- Change the operators (greater than, less than, etc.)
IF/THEN/ELSE Excercise (4/4)
- ELSE is the companion to the IF statement. An IF/THEN/ELSE statement says "If the statement is true, run this block of code; if it's not true, run the code after the else statement."
cart_total = 8
if cart_total > 2
print "You get free shipping!"
else
print "You'll have to pay for shipping."
end
- Change the numbers to see what happens.
- Change the operators (greater than, less than, etc.)
- Change the string statements.
Loops (1/2)
- A loop is a list of instructions that repeats until a certain condition is reached.
- Two kinds of loops are For Loops and While Loops.
Why Use Loops? (2/2)
- Using loops is very powerful. One of the main reasons to use loops is to reduce your lines of code.
- Depending on what you're doing, you could have hundreds of lines of code using "IF/THEN/ELSE", or you could write a simple Loop statement.
Let's Do Some Loops! (1/4)
Loop Excercise (2/4)
- For this excercise, we're using Python.
- Go to repl.it, which is an online terminal to practice writing code.
- Choose 'Python'.
Loop (while) Excercise (3/4)
papers_to_deliver = 65
while papers_to_deliver > 0:
print papers_to_deliver
papers_to_deliver = papers_to_deliver - 1
print 'Out of papers! Go home!';
- Change the numbers to see what happens.
- Change the operators (greater than, less than, etc.)
- Change the string statements.
- See the next slide that will explain what is happening in the loop (via a diagram).
WHILE Loop Examples
- Amazon or eBay: "WHILE" it's today, display the daily deals.
- Amazon cart: "WHILE" it's this book, display the book's image, title, price, etc.
Beware the Infinite Loop!
- An infinite loop is a loop that will never meet the condition to stop. It will keep going until it's used up all your computer's (or server's) memory (RAM). This is bad!
- Example: In the While loop:
- If the "papers_to_deliver = papers_to_deliver - 1" line was missing, it would keep looping because 65 is always greater than 0!
- If "papers_to_deliver = papers_to_deliver - 1" was changed to "+ 1", it would keep adding 1 to 65 forever!
Project Implementation
Example
- When companies implement a new program, they take various things into consideration:
- Possible languages to use:
- Python: computer program
- SQL: manage the data
- HTML/CSS: web development to share on the Internet
- Programming structures:
- Variables: place to store the information such as, colors, amounts, etc.
- Detailed steps to tell the computer what to do.
- Loops: Instructions that keeps repeating as neccessary.
Coding Classes Resources (most are free) and Books