cpap.com introduction to coding: part 1
TRANSCRIPT
![Page 1: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/1.jpg)
Introduction To CodingJohnny Goodman
![Page 2: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/2.jpg)
We Tried To Get Jeremy To Teach
But...
3:49:17 PM Ashley Thompson: I will work on Jeremy.3:49:30 PM Ashley Thompson: He told me to contact his agent… which isn't a "no".
![Page 3: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/3.jpg)
● You will see coding
● You will learn basic concepts
● You will know where to go to practice
● You will know where to go with questions
What Today's Session Will Do
![Page 4: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/4.jpg)
● Teach you ever more advanced concepts
● Teach you how to code on your local box
● Teach you how to leverage existing code
● Build stuff that is day to day useful
What Future Sessions Will Do
![Page 5: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/5.jpg)
There are too many concepts to pack into an hour.
We're going to go in smaller chunks.
We are "eating our veggies" today by learning a lot of concepts which will relate later.
No SQL Today
![Page 6: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/6.jpg)
What Is Coding?
Playing with numbers and words until they are useful, then saving them and reusing them.
![Page 7: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/7.jpg)
Computers vs. Humans
Computers are like this 10101101010101.
Humans are like this "hi! k. thx, bye"
This is "hi! k. thx, bye" in computer:
011010000110100100100001001000000110101100101110001000000111010001101000011110000010110000100000011000100111100101100101
![Page 8: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/8.jpg)
Code Like A Human
I do not want to write a bunch of 1s and 0s.
I need a coding language to take my English and turn it into 1s and 0s for me.
Many good languages do this.
I like Ruby.
![Page 9: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/9.jpg)
Where Do I Go To...Ruby?
To punch stuff in and see what Ruby does:
● http://tryruby.org/
To go through a structured, type it in course:
● http://www.codeacademy.com/tracks/ruby
![Page 10: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/10.jpg)
Where Do I Go To...Ruby?
To ask questions to other coders:
http://stackoverflow.com/questions/tagged/ruby
![Page 11: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/11.jpg)
Today's Coding Concepts
● Words and Numbers● Storage● Comments● Running Code● Comparisons● Arrays● Commands On Variables● If/Else Statement
![Page 12: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/12.jpg)
Words
In code, you store words in Strings.
Examples:
● "I am a string because I am words"● "I am also a string"● "jello"
Quote signs tell the computer that its a String.
![Page 13: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/13.jpg)
Numbers
In code, you store numbers in Integers.
Examples:
● 5● 555● 102125
No quote strings needed.
![Page 14: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/14.jpg)
You'll need to do three things to store stuff:
● To make up a name● Type an equals sign● Type a word or number
Example:
save_me = "this will be stored to save_me"
Storing Values
![Page 15: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/15.jpg)
pudding = "word or number"
The made up name pudding is commonly called a variable.
johnny = "hi hi"carolyn = "bye bye"
johnny and carolyn are variables.
Storing Values
![Page 16: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/16.jpg)
Lets store "my words" to the my_value variable:
my_value = "my words"
Display that variable with the puts command:
puts my_value=> "my words"
Storing Values
![Page 17: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/17.jpg)
Examples of how to store Strings:
words = "my words"oscar = "grouch"johnny = "occasionally grouchy"
Storing Values
![Page 18: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/18.jpg)
Examples of how to store Integers:
total = 5 + 4another = 10 - 3last = 42 * 125
Storing Values
![Page 19: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/19.jpg)
Another Example:
pudding = "tasty goodness"
puts pudding=> "tasty goodness"
This is because we stored "tasty goodness" to pudding, then said "print the value of pudding"
Storing Values
![Page 20: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/20.jpg)
Storing Values
You can use variables just as if they were the original value they store.
Example:
one = 1two = 2three = one + twoputs three=> 3
![Page 21: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/21.jpg)
Storing Values
You can overwrite variables with new data
var = "this won't last"puts var=> "this won't last"
var = "overwrite the current data"puts var=> "overwrite the current data"
![Page 22: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/22.jpg)
Storing Values
You can store variables to other variables
Number Example:
one = 1also_one = one
puts also_one => 1
![Page 23: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/23.jpg)
Comments tells the computer to skip the line.
The symbol for a comment is the # sign.
Here are what comments look like:
#var1 = "test"#my comment line will be skipped#var1 = "test2" a third skipped line
Comments
![Page 24: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/24.jpg)
Comments are used by coders to add context, warning and overviews of code
#This will store "hi" to myvarmyvar = "hi"
#This will store 2 + 2 to the variable fourfour = 2 + 2
Comments
![Page 25: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/25.jpg)
To run code:
1. Go to the command line
2. Type in Ruby code
3. Get a response from Ruby
Running Code, The Command Line
![Page 26: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/26.jpg)
Where do you find command lines?
1. Inside tutorials like codeacademy/tryruby
2. On your computer, if ruby is installed (irb)
3. On other computers where ruby is installed, like if IT configures one and gives you creds
Running Code, The Command Line
![Page 27: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/27.jpg)
Lets move to the command line and run examples we've worked on so far.
1. Johnny's command line
2. The code academy tutorial
Running Code, The Command Line
![Page 28: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/28.jpg)
If Ruby is installed on your computer:
1. Create a file.
2. Make it end in .rb (instead of .doc, .txt, etc)
3. Navigate to the file's directory via command line
4. $>ruby my_file.rb
Running Code, From A File
![Page 29: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/29.jpg)
If you have downloaded a Ruby focused text editor, you can also load and run the file right from the GUI.
Lets pause for examples.
Running Code, From A File
![Page 30: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/30.jpg)
The == sign tells us if two values are equal:
1 == 1=> true
1 == 2=> false
Comparisons
![Page 31: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/31.jpg)
one = 1two = 2
one == 1=> true
one == two=> false
Comparisons
![Page 32: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/32.jpg)
Welcome Back
![Page 33: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/33.jpg)
Arrays
Arrays let you store a group of the same data to one variable.
Some examples of groups:
people = ['johnny', 'robert', 'nelson', 'jayson']animals = ['sloth', 'toad', 'zebra']presidents = ['clinton', 'bush', 'obama']
![Page 34: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/34.jpg)
Arrays
To get all that data back out
$> people => ["johnny", "robert", "nelson", "jayson"]$> puts peoplejohnnyrobertnelsonjayson
![Page 35: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/35.jpg)
Arrays
To get only one element out, you need to learn a trick...
Arrays are zero indexed.
Meaning you count and reference the elements from 0.
![Page 36: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/36.jpg)
Arrays
0 1 2 3
['johnny', 'robert', 'nelson', 'jayson']
Examples:
people[0] => 'johnny'people[2] => 'nelson'
![Page 37: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/37.jpg)
Arrays
![Page 38: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/38.jpg)
Commands On Variables
First, lets just look at it:
people=> ['johnny', 'robert', 'nelson', 'jayson']
people.count=> 4
![Page 39: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/39.jpg)
Commands On Variables
You can call commands on variables.
Structure:
<variable>.<command>
Example:
people.count=> 4
![Page 40: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/40.jpg)
Commands On Variables
Here's another one:
people=> ["johnny", "robert", "nelson", "jayson"]
people.reverse => ["jayson", "nelson", "robert", "johnny"]
![Page 41: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/41.jpg)
Commands On Variables
If you want to see all the commands you are allowed to call on a given variable, use the methods command
people.methods=> [:inspect, :to_s, :to_a, :to_ary, :frozen?,:==, :eql?, :hash, :[], :[]=, :at, :fetch, :first, :last, :concat, :<<, :push, :pop, :shift, :unshift, :insert, :each, :each_index, :reverse_each, :length, :size, :empty?, :find_index, :index, :count]
![Page 42: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/42.jpg)
More Helpful Array Commands
Add a new person to people:
people.push('jenny')=> ["johnny", "robert", "nelson", "jayson", "jenny"]
![Page 43: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/43.jpg)
More Helpful Array Commands
Remove the last person from people:
people.pop=> "jenny"
people=> ["johnny", "robert", "nelson", "jayson"]
![Page 44: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/44.jpg)
If/Else Statement
A variable's value can be used as a decision point that determines which code to run next.
You do this using an if / else statement.
![Page 45: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/45.jpg)
If/Else Statement, Structure
If / Else Structure:
if variable == <value>#run this code if true
else#run this code if false
end
![Page 46: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/46.jpg)
If/Else Statement, Example 1
one = 1
if one == one puts "true, one equals one"else puts "false, one does not equal one"end
=> "true, one equals one"
![Page 47: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/47.jpg)
If/Else Statement, Example 2
one = 1
if one == 2 puts "true, one equals one"else puts "false, one does not equal one"end
=> "false, one does not equal one"
![Page 48: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/48.jpg)
Command Line Examples
Time for command line examples...
![Page 49: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/49.jpg)
The Big Picture
A web page does this:
1. Queries a database and stores data to arrays2. Loops through the arrays3. Manipulates elements of the arrays4. Displays results to the user
![Page 50: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/50.jpg)
The Big Picture
You know:
1. How to create and store variables2. How to manipulate variables with commands3. About arrays4. How to decide which code to run via IF/Else
![Page 51: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/51.jpg)
The Big Picture
You do not know:
1. How to loop through arrays2. How to wrap code in reusable methods3. How to wrap methods in reusable classes4. How to use other peoples code
![Page 52: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/52.jpg)
The Big Picture
Once you fill those holes in, you have the core concept of how to build any web page.
You can also look at a web page and say "I know how they did that" in a conceptual way.
![Page 53: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/53.jpg)
The Big Picture
Code is slowly automating everything.
Code is the new universal language.
Nearly every other skill will eventually be code involved or code dependant.
Be in the "can code" part of the work force.
![Page 54: CPAP.com Introduction to Coding: Part 1](https://reader033.vdocuments.site/reader033/viewer/2022052912/55a1e0081a28ab1b778b472c/html5/thumbnails/54.jpg)
Next Time
● Loops● Arrays + Loops● Classes and Methods● Connecting To Databases● Looping Through Database Query Results● Using Other People's Code In Yours