• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/23

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

23 Cards in this Set

  • Front
  • Back

Unix line end

“\n”

Why should ADT be separate?

For re-use

Every variable has? 2 things

Type and storage class

3 modes to open a file?

1. “r” - read


2. “w” - write


3. “a” - append

Two space optimization features

1. But fields on structures


2. Unions

Difference between struct and union?

Struct: Memory allocated for each member. Each member can hold a value at the same time.


Union: Memory allocated for the largest member of union and shared among all. Only one member can hold a value at a time

Difference between locally declared variables and dynamically allocated variable

Locally Declared: live in the stack. Life begins at the place where it is defined and it ends at the end of the block of code.


Dynamically Allocated: live in the heap. Life begins when they are allocated (using Malloc) and ends when they ate freed (free) or the program is terminated.

Header Guard

until.h:


#ifdef _UTIL_H


#define _UTIL_H


#endif

Manual Testing

1. Run program


2. Enter the nth test case


3. Check output


4. Go back to #2 until you’ve run out of data


5. Did it work? Yes: Done No: Back to coding

Automated Testing

1. Each function should be atomic as possible


- Test 1 thing well


2. The data for the test belongs in the test function


3. Main function ONLY calls other function

Test Scaffolding

Write code to test our code

Debugging: Spelunking

Read code, understand code, where is the bug?

Debugging: Use assert()

Encode assumptions (preconditions, postconditions, invariants) with asset

Debugging: Printf

Place printf throughout code to get a handle on the flow of the app

Source-level Debugger

A program used to:


- step through program line-by-line (observe flow)


- watch variables as they change (observe state)


- stop execution at certain points with breakpoint

Source-level Debugger Strategy

1. Run the code generator with no breakpoints


2. Inspect the stack trace after the code crashes


3. Add a breakpoint near the crash


4. Rerun program, step through each line. (Observe state)

Exception

Something happens while your program is running where it cannot proceed.


- NULL pointer


- File-related issues


- Division by 0

Programming Errors

1. Syntax errors


2. Index and bound errors


3. Network calls on UI thread


4. Forget to check inputs

3 places our assumptions can be violated

1. Before we start processing data


2. After we finish processing data


3. State of an object throughout execution

Runtime Prevention

Main tool for preventing range-related runtime errors is conditional statements

Compile-time Prevention

Use language-level features to limit values the programmer can use

Enum

Let’s you define a type with a specific set of values


Useful when all possible values a variable can have is known in advance


Hard to misuse


Code is easier to read/understand

Design by Contract

Tool to prevent programming errors.


Not languages specific


Code you write that encodes your assumptions about inputs, outputs, and state of your program.