Skip to content

Instantly share code, notes, and snippets.

@alfahami
Last active March 21, 2023 18:09
Show Gist options
  • Save alfahami/b4f88c91c94d7b331ad1f8a4ec4b41e7 to your computer and use it in GitHub Desktop.
Save alfahami/b4f88c91c94d7b331ad1f8a4ec4b41e7 to your computer and use it in GitHub Desktop.

Abstraction = Interface (What it does) + Implementation (How it does it)

Abstraction has Multiple Layers Seven Steps of solving a problem:

  1. Work Example By Hand (Solve Small instance by hand | unclear problem | Domain Knowledge )
  2. Write Down What you did (Write Down Exact Steps | Just that instance | Tricky: Do without thinking)
  3. Find Patterns (Algorithm for any instance | Repetitions | Conditions | Values, Try step1+2 again | Different Inputs)
  4. Check By Hand (Incorrect Pattern? Check with different inputs)
  5. Translate To Code (Programming Language)
  6. Run Test Cases
  7. Debug Failed Test Cases

JAVASCRIPT

Variables in JS

  • Boxes that holds value
  • Declare with var
  • Assign with =

Expressions

  • Combinations of variables, constants, operations

new SimpleImage("image")

  • Create an image

Methods

  • Perform some(complex) operation
  • Act on a object
  • Can have parameters

Why are methods important?

  • Abstraction

  • Separate interface from implementation

  • Implemention

Call image.getWidth(), get width of image

  • Interface
- Code in DLTP library(not shown)
- No need to see!

How Does a Language Know the Type?

  • How Does JavaScript knows the type?

  • Keeps track of it with the value

  • Called dynamically typed

Finding and fixing bugs

Scientific Method

 1. Observe a phenomenon 
   --> 2. Ask a question 
    --> 3. Gather Information & Apply Expert Knowledge
         Gather Information = Print Statements, Debugging Tools, Execute Code by Hands
         Expert Knowledge = Comes with Experience
     --> 4. Form Hypothesis
          Good Hypothesis are: Testable (Prediction about behaviour)
                               Actionable (Can fix program if true)
                               Being specific helps with both
      --> 5. Test Hypothesis:
                             Run program
                             Behaviour matches predictions:
                              No: reject hypothesis
                              Yes: more confident
                               Confident enough? Accept.
       --> 6. (Reject | Accept) Hypothesis 

Temptation: Ad Hoc Changes:

     Temptation: "Maybe if I just change ..." (poor idea)
     Metaphor: Medical doctors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment