Code1161 — Week7
IO, Refactoring, Recursion
OPEN DATA PROJECT
Lots of open urban data is available. Try:
Data.gov.au
Process
First, you need to care about something.
- pick a data set
- document it
- understand how it was collected
- explore it
-join it to another set (compare/contrast)
-find amazing insights
-communicate these insights
IO
Notes on working with other files:
Writing
Mode = “w” (open file in write mode)
e.g.
History_book = open(file_path, mode)
History_book.write(name + “ is cool”)
History_book.close()
(here history_book is the “file object”)
Reading
Mode = ‘r’
History_book = open(file_path, mode)
Response = history_book.read()
(in Linux everything is a file, it doesn’t matter if it’s .txt etc.)
REFACTORING
When you are writing code, you are building up “technical debt” — i.e. the longer you go, the more junk you’re building up.
Things to look out for:
DRY — Don’t Repeat Yourself
If you only write it once, you can only write it wrong once.
Major culprits when something goes wrong:
-repetition — obvious culprit
-inappropriate naming — e.g. names and content no longer matching
Think about what comments and names actually mean. What they actually are, not how it’s being used right now)
-bloated functions
-unnecessarily complicated code
-overly large pages
-lack of useful comments
- check if things are very stepped in/nested
(see also: “code smells” — signs something is off)
RECURSION
No, don’t call it “inception.”
A Kosch snowflake is a simple example.
TUTE
Ctrl+ / — comments stuff out
JSON xml’s cool young child. Object based file system.
http verbs “get” “post”
status codes:
404 — can’t find
200 — everything good
Response object : <response[200]>
API- “ application programmer interface”
The way that you would access somebody elses code