User-Friendly Expression of Information
Lab: Building Blocks of Programming
Video Runtime: 22:42
In this episode, you will learn about user-friendly expression of information. What does that mean? Information is data. This episode talks about how data is represented in software, including variables, memory, and more.
Your key takeaways are:
- Variables:
- represent data
- are user-defined – meaning you name them what you want (within reason)
- Quality Tip: purposefully name your variables to describe the data it represents
- Variables are stored in a memory location and then hold the location to where the data is stored
Study Notes
Imagine language where you spoke in data instead of generic names. What do these numbers mean?
2014 | 2015 | |
---|---|---|
October | 90,512 | 79,436 |
November | 128,039 | 98,180 |
What does this number mean?
- “Compared to last year, my store has declined 40,935.”
Imagine Coding in Data
if ( 98180 - 79436 > 218551 ) { printReport(); }
- What do the numbers mean?
- These numbers are now fixed (hardcoded)
- These numbers cannot vary
- The threshold cannot be adjusted without editing the code
Variables
Thought experiment: What is common about the data above?
In software, we say data is variable.
- Not constant
- Varies
- On its own, it lacks context
Variables Represent Data
- User defined names
- Language requirements:
- begin with a letter
- no symbols
- unique (to the scope)
- not a reserved word (keyword)
- Quality code tip:
- Name the variable for the data it represents
- Give it a meaningful and purposeful name
By adding the label Units Sold, is this table more meaningful than the one above?
Units Sold | 2014 | 2015 |
---|---|---|
October | 90,512 | 79,436 |
November | 128,039 | 98,180 |
Variables in Action
// $unitsSold has the data from the database | |
$totalUnitsSoldInQ4 => array( | |
2014 => $unitsSold[2014][10] + $unitsSold[2014][11], | |
2015 => $unitsSold[2015][10] + $unitsSold[2015][11], | |
); | |
if ( $totalUnitsSoldInQ4[2015] < $totalUnitsSoldInQ4[2014] ) { | |
printReport(); | |
} |
if ( ( 98180 + 79436 ) < ( 128039 + 90512 ) ) { | |
printReport(); | |
} |
What happens in memory?
Picture a wall filled with little compartments, just like at the post office. Each compartment holds a piece of data.
Notice in the picture, each compartment has a unique identification number.
Hey... hey you... yes you!... Having a good time? Learning new things? Good!
Episodes
Total Lab Runtime: 02:17:55
- 1 Lab Introductionfree 06:21
- 2 User-Friendly Expression of Informationfree 22:42
- 3 Fundamentals of Syntaxfree 08:57
- 4 Decision Branching - if/then/elsefree 10:39
- 5 Decision Branching – switch/casefree 07:47
- 6 Basics of Iterationfree 14:14
- 7 Iteration in Practicefree 12:51
- 8 Order of Executionfree 10:55
- 9 Abstractionfree 11:45
- 10 Scoping – Who Can Communicate With Whomfree 31:44