CS61A 2018 Pathway

This is my learning path of CS 61A, you can check at my github repository for slides.

ref: Structure and Interpretation of Computer Programs

Spring 2018

Instructor: John DeNero

Pooling Chart

Lecture Reading Note Handout Homework
Functions 1.1, 1.2 Note 1 Lab 00: Introduction & Workflow
Names 1.3, 1.4 Note 2 Disc 00: Lost on the Moon HW 01

suggested accompany

  • Data8 for data science, of fundamentals of computing, statistical inference, & machine learning applied to real-world data setsmachine learning, with ore statistics than computer science. A great programming practice for CS 61A

1-1 start

  1. Priciples: beauty, simplicity and readability

  2. Definitions:

    • Statements: codes usually describe actions
    • Expressions: codes do computations
    • Functions: a box of series of statements and/or expressions
    • Objects: data and its unalienable properties
    • Interpreters: to evaluate compound expressions in a predictable way

      functions are objects, objects are functions, and interpreters are instances of both.

  3. Expect errors:

    • Debugging: know error itself and dignose it
    • Priciples of debugging:

      • Test incrementally, identify probles early and easily
      • Isolate errors, localise according to output
      • Check assumptions, make sure assumptions check with codes precisely
      • Peer consulting, chart of valuable helpers

        Name|Specialize
        —|—
        Official Py Documentation|Everything

The fundamental equation of computers is:

computer = powerful + stupid

Programming is about a person using their real insight to build something that the computer can do.

— Francisco Cai and Nick Parlante, Stanford CS101

1-2 elements of programming

  1. Aims programming serves:

    • instruction to a computer
    • a framework of ideas, which is mor important
  2. Notice means to combine simple expresions and statement to complex combination and abstractions

  3. Expression: operators and operands

    • with infix notation, eg. 1/2 + (1/4 + 1/8 + 1/16) + 1/32 + 1/64 + 1/128
    • with function notaton, eg. max(min(1, -2), min(pow(3, 5), -4)), and have THREE advantages over infix ones:
      • arbitary number of arguments
      • nested expressions in a straightforward way
      • easy to type, no limit to kinds
  4. Definitions:

    • ‘=’: assignment operator
    • names: variable nams
    • trees: grow from the top down
  5. Pure and non-pure functions

    • Pure function have no side effects beyond return a value, call it for arbitary times with the same arguments must return same values.
    • Non-pure function have side effects
    • Advantages of pure over non-pure:
      • more reliable to compose
      • simpler to test
      • essential for concurrent programs

The Zen of Python by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one– and preferably only one –obvious way to >do it.
Although that way may not be obvious at first unless you’re >Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good >idea.
Namespaces are one honking great idea – let’s do more of those!

1-3 define functions

  1. A function have signature and body

    • Singature have all variebles needed
    • body indict expressions and statements
  2. Names of variebles remain local within function bodies

  3. Choosing names: essential to the interpretability, and usually follow simple rules:

    • lowercase, words separated by underscores, good to be descriptive
    • parameter names should be lowercase, in single word, and meaningful
  4. A helper function can be write at a a later time in the function

  5. Functional abstracion:

    • Domain:
    • Range:
    • Intention:

A programmer should not need to know how the function is implemented in order to use it

1-4 designing functions

  1. Functions are abstractions:

    • Single job for each function, with a shortname and a short description
    • Don’t repeat, abstract
    • Generally defined, considering broader usage.
  2. Use docstring, triple quoted:

    • First line: job of the function
    • Following lines: argument and behavior
    • Use help(function) to see the docstring
    • Write docstrings for all functions necessary

Code is written only once, but often read many times.

  1. Comments: attached following the # symbol, fr humans alone

  2. Values should be assigned defauts in most cases.

1-5 control

  1. Definitions
    • Statement: to change thethe interpreter state
    • Clause: a header and an indented suit of statemtns, and a suite is controlled by a header
    • Compound Statement: consists of arbitary number of clauses
    • Execution rule: excuted in order, end by redirection to control
    • Modular Programs: where pure functions interact only via the values they take and return.

To execute a sequence of statements, execute the first statement. If that statement does not redirect control, then proceed to execute the rest of the sequence of statements, if any remain.

  1. Local Assignment: bind a name to a value within the local frame

  2. Conditional statements: conditional statements, bool contexts, bool values

  3. Iteration

  4. Testing

    • Assert statments: followed by a bool expression, and a text for FALSE, proceeded to next only when expectation is met.
    • Doctests: seperate by a blank line from the description
    • Unit Test: test that applies a single function, should be exhaustive.
    • Key: test immediately after implementing
 上一篇

System Center Operations Manager SCOM