Software Construction Flashcards

1
Q

statically vs dynamically typed

A
  • ** statically:**
  • compiler is strict about types
  • dynamically:
  • ## assigning a variable a diff type will change the vars type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

java, typescript, javascript

A

java: !interpreted & static
typescript: !interpreted & optionally static
javascript: !interpreted & dynamic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

interpreted vs compiled

A
  • interpreted:
  • top down
  • compiled:
  • compiled languages are first analyzed and transformed by a compiler before they can be executed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

linters common warnings

A
  • unused method
  • var is hoisted to scope of entire method rather than in the block:
      • use let to restrict to block
      • use const (var wont be overwritten at all in method)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Asynchronous execution in JavaScript

A
  • JavaScript uses an asynchronous execution model
  • Functions run on the call stack and always execute to completion—one function runs at a time
  • If a function takes too long, it blocks the main thread
  • extra info: JavaScript functions should ideally finish in under 16ms, if they dont they cause “jank”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Thread pool & Blocking Tasks

A
  • Long operations (e.g., network requests, file I/O) often take much longer than 16ms
  • These are offloaded to a limited thread pool in the browser or Node.js
  • Once finished, results are passed back to the main thread via callbacks, using the event loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Callback example: SetTimeout(onDone, delay)

A

SetTimeout(display, 1000);

function display() {
console.log(‘Hello’);
}, 1000);

this calls the function when done

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Four Main Parts for Async

A

Call Stack
Web APIs
Event Loop
Callback Queue
NOW DRAW THIS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is error handling difficult in traditional JavaScript callbacks?

A

Because callbacks don’t return values, errors must be passed manually through parameters. This relies on the error-first convention (e.g., function(err, result)), which depends on developers checking err properly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Why can’t exceptions be caught with try/catch in callback-based code?

A

Because callbacks are executed in a separate context from the function that triggered them, there is no parent frame for try/catch to intercept exceptions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Draw Promises Diagram

A

in notes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

promises pros

A
  • Flattening callback chains (dont actually create any functionality for thi alone, jsut make it easier for developers to read and “do the right thing”
  • Enabling try/catch for error handling.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Refactoring Rule of 3

A

1) code the feature
2) code it but take note
3) refactor code first

(this acknowledges that premature refactoring is also bad)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Refactoring: 4 fun facts

A
  • behaviour should be unchanged
  • test suite should be run before and after
  • without effective tests its harder to refactor
  • integrates well with agile methodologies (earlier is good)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Rafactoring Triggers

A
  • quality concern (add a new feature and its harder than expected, or bug fix is scattered)
  • code review
  • technical team benefits but risky and costly for stakeholders
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Types of Refactoring (6)

A
  • Rename (class/field/method).
  • Move (class/field/method).
  • Extract class/interface/method.
  • Push down/pull up field/method.
  • Replace magic number/string with constant.
  • Replace inheritance with delegation.
17
Q

anti-patterns: BAD (4)

A
  • deep nesting
  • bad naming
  • individual style
  • no comments
18
Q

Name Code Smells (8)

A
  • duplicated code
  • long method
  • large class
  • long parameter list
  • large class
  • divergent change
  • shotgun surgery
  • feature envy
  • middle man
19
Q

feature envy

A
  • when a method is in the wrong class
  • refacotr method: extract
20
Q

divergent change

A
  • when many independent changes involve modifying a specific code element
  • one symptom that a class is taking on more than one responsibility
  • method: extract
21
Q

middle man

A
  • when a method does not do anything itself but just ends up delegating all work to another class.
  • arises after refactorings that move functionality to other methods but the original base method remains
22
Q

shotgun surgery

A
  • when simple coherent changes require broad changes across a system
  • can be called delocalized/scattered changes
  • method: move method/field
23
Q

what does REST service return?

A

data representation (json, html, xml)

24
Q

how do REST services define resourcces?

A

as nouns using URIs (uniform response indentifiers)

25
Q

what is in what is returned by REST service?

A

header: metadata and one IMPORTANT metadata, the status code

body: json, html, or xml

26
Q

what is statelessness?

A

resource state vs application state

  • clients need to maintain application state
27
Q

API Versioning: 3 ways

A

1) PATH
- - GET /v2/users

2) QUERY
- - GET /users/?v=2

3) HEADER
- - APIVersion: 2

28
Q

REST often does authentication

A
  • token, cookies, or https