Lecture 9.1 (March 22)

  • Return Quiz 2
    • Overall scores not as bad as it sounds like people feared
    • We will be dropping lowest quiz
  • Quiz 3 is on Thursday
  • P1 and P2 grades are up
  • A1 is b0rken.

Learning

I understand that there's a fair amount of ‘what are we doing?’.

For one thing, we're running very high on the abstraction stack. A lot of your future work will be at a high level like this.

Also, lectures are not enough to learn. They cannot be.

  • Read the Wiley textbooks
  • Read the documentation

The documentation is not an afterthought, or just supplemental material. In order to succeed in programming, and in this class, you need to read it. Fortunately, several of the tools we are using have very good documentation.

Sadly, others do not.

I'm happy to spend time in lecture or office ours talking about points that are confusing in the docs.

Recap!

Where are we at?

  • HTML
  • Python and Flask
  • Serving over HTTP
  • Storing data in the database

Review Data Storage and Access

Look at the Python code from ‘animals’ about how to work with relationships.

  • our relationship has a backref parameter
  • backref creates a field on the other object

Refresh how to add and save objects.

Creating Lists

We can't store lists directly in a field — limitation of the relational database model underlying SQL.

We need to use multiple tables and relationships.

Example: tags, like for a blog post

  • add tags to the Animal example

JavaScript

The next stage of our program is to add client-side interactivity in the form of JavaScript.

Fire up a JavaScript notebook and start writing some code.

JavaScript has a syntax that looks superficially a lot like C or C++.

Like Python, variables have no types.

Unlike Python, variables must be declared (if you don't, it works, but is probably not what you intend).

JavaScript is even looser than Python.

Useful tool: JSHint will check your code for common problems.

Note

Pay attention to PyCharm warnings in your JavaScript. Fix them. They are likely problems later.

Like Python, JavaScript has built-in lists (arrays) and maps / hash tables (objects).

JavaScript Versions

JavaScript has gone through several evolutions over its time.

  • Original JavaScript in Netscape Navigator
  • Microsoft
  • Continued improvements, some in engines, others standardized

The most recent version of the standard is ES6 (ECMAScript version 6.0, 2015). This provides a number of nice features. Two particularly useful ones:

  • arrow functions make it easier to write inline functions
  • class provides more familiar syntax for defining object behavior

However, these features are still missing from key browsers, so we can't depend on them in the production Web yet, and we're not going to mess with transpilers for this class.

Exam

We have an exam on Thursday!

  • Review past material! (URLs, HTTP, CSS, HTML)
  • Cookies and sessions
    • What does it mean that HTTP is stateless?
    • How do cookies and sessions deal with that?
  • Data storage
    • How do you create and add an object?
  • Security
    • CSRF tokens
    • Hashing passwords (use bcrypt, PB-KDF2, or scrypt)