L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30,...
Transcript of L9 HTTP and Patterns€¦ · Lecture 9: HTTP and Patterns Craig Zilles (Computer Science) March 30,...
Lecture 9: HTTP and Patterns
Craig Zilles (Computer Science)
March 30, 2020
https://go.illinois.edu/cs105fa19
CS 105
Today1. The Internet• Domain names, IP, HTTP, HTML, CSS, JS
2. Patterns• E.g., Even/Odd, Count, Sum, Find, Find Best
2
The Internet• Is kind of important• I'm hoping you get the big picture (no memorization)
• Hostname -> name lookup -> IP address• Top-level domains
• You can buy your own domain• URL structure: (three parts: scheme, hostname, path)https://illinois.edu/assets/img/navigation/submenu_about.jpg
3
The Internet
4
192.168.0.101
192.168.0.182.10.251.47
192.168.0.102
192.168.0.104
ISP
INTERNET
172.217.23.174172.217.23.175172.217.23.176172.217.23.177
Your Homecompany.com
ISP = Internet Service Provider
Domain Name Server (DNS)78.46.75.45
HTTP/HTTPS• HyperText Transport Protocol (HTTP)
5
HTML5 = HTML, CSS, Javascript• Separation of Concerns• HTML = content, CSS = styling, JS = interactivity
• HTML documents are hierarchical, cause web pages are• Elements have begin/end tags• Elements can be nested in other elements
• CSS consist of:• Selectors that specify which elements • Attribute : value pairs• Like a Python dictionary
• Javascript is a lot like Python but looks pretty different• variables, expressions, functions, conditionals, loops
6
Common Idioms / Patterns• There are structures that show up in lots of programs
• Check if even/odd• Visit everything in a collection• Sum • Counter• Finding "best" in collection• Filtering a collection
7
Check if something is even/odd
(value % 2) == 0 # returns True if value is even
(value % 2) != 0 # returns True if value is odd(value % 2) == 1 # returns True if value is odd
8
Visit everything in a collection
for thing in collection:… thing …
9
Computing a sum / total
total = 0 # initialize variable to zero
… # usually in a looptotal += value # accumulate
… total … # do something with the total
Also Average = sum / count10
Counting
counter = 0 # initialize variable to zero
… # usually in a loop and/or conditional counter += 1 # increment
… counter … # do something with the counter
11
Compose patterns to solve problems• Write a function that counts the number of even
elements in a list
12
Finding best in a collection
current_best = a value you know is worse than best
for thing in collection:if thing is better than current_best:
current_best = thing
return / do something with current_best
13
Filtering a collection (pattern)
newlist = []
for thing in collection:if thing meets criteria:
newlist.append(thing)
14