1/86
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Excdeptions
catch things that are truly exceptional (can’t proceed with future statements in block if exception occurs)
Error
caught synchronously, can recover
approach to exceptions
caught should go from more specific to general
resumption model
resume execution right after exception was thrown
termination model
resume execution after the block where the exception handler was found (what modern langs use)
should exceptions be used
cause overhead - error detection is less expensive
checked expections
checked at compile time, to check if you handle the exception
unchecked exceptions
not checked at compile time (runtimeException, divide by 0, index out of bounds)
type inference
determine type based on value or expression
static typing
determined and checked at compile time
reduce amount of code to be compiled
programming errors caught early
improve security and reliability
Dynamic typing
determined at runtime
flexibility
less efficient
strong typing
type is checked at compile time or before operation
prevents unsafe operations
weak
any type can be used and an attempt to use it will occur
type compatibility
allows you to swap certain types for others (int for float)
implicit conversiona
when there isn’t enough room to store full representation
explicit conversion
occur with casts or methods in language
data type definition
set of values
different ways to check if two types are equal
structure - same objects, structure, or properties
include names?
enums
types that are more readable and restricted to a certain range of vals
union
allows you to choose which type at runtime, reduce memory requirements
arrays in C
on stack
specifiy size
arrays in java
on heap,
get the size with length prop
pointer vs reference types
c pointers you can use in an expression and manipulate
java you cant perform operation on actual reference
logical programming what is it
write statements of what is true and what can lead to something being true
logical constants
names or numbers (atoms)
logical predicates
names that return true or false, can accept args
logical functions
returns something other than true or false
logical variables
can hold a val like other langs, but determined by logic and reasoning
issues with logical programming
define what solution is, not how to solve it
ordering is very important
not proven to be true, then its false
limited applications
prolog fact
csds.
prolog predicate
major(cs)
prolog language is compiled or code and interpreted
language(X) :- compiled(X).
language(X) :- code(X), interpreted(X).
prolog method recursion format
method(X,Y,R) :- method(X+Y+R)
side effect
values change in a function
referential transparency
a value of what a function returns only depends on the value of its arguments
functional programming compontents
no side effects
referential transparency
functions are treated as data
easier to perform parallel execution
vars in functional
stand for values, should not change
state in functional
no notion of state
values of function depend on values of arguments
should not care about internals of functions
loose coupling
easier testing
control in functional
no loops, if is a function
functional, composition
takes two functions as params and returns a function
higher order function
function has function param or returns a function
functional benefits
predictible
easy to test
easy to understand
downside of functional
copying a lot
less efficient
less intuitive
key functional ideas
all functions have clear inputs
no assignments
no loops
function only depends on value of params, not outside values
functions are first class data values
haskell print
putStr $ “hello” ++ show x
haskell input
putStr ““
input ← getLine
let x = read input :: type
haskell function
name param1 param2 param3 = if param then blah else blah
haskell guards
name param
| param >= 30 = “blah”
|
| otherwise = “blah”
update list haskell
let updated list = list ++ [x]
print list haskell
print (x:xs) = do
putStrLn $ “hi: “ ++x
print xs
print [] = return ()
binding times
definition of lang
implementation of language
compilation
linking
loading
execution
extern keyword
global variables to be defined across files
symbol table
names and binding, in binding type and (scope)
static scoping
primarily used
determined at compile time
block defines scope
structure of language defines scope
dynamic scoping
not really used
determined at runtime
when dues c vs java use symbol table
compile time | both
activation
local vars are allocated at runtime when block is reached
memory used for each block is activation record
OOP main idea
mimic real world object
primary OOP goals
promote code reuse
promote modifiability with less code
promote independence of software
code reuse oop
redenfinition
overriding
abstraction
polymorphism
inheritance
interfaces
C++
dynamic binding is optional
support multiple inheritance
Kotlin vars
var name: String
var y = 3
kotlin input
print(“HI $varIfNeeded”)
val entered = readLine()
let kotlin
length?.let{
}
kotlin function
fun name(param:type) : return type? {
}
kotlin list
val todos = mutableListOf(““, ““)
todo.add(““)
kotlin interface testable
interface Testable {
fun takeQuiz()
}
class Student: Testable{
override fun takeQuiz(){
}
}
kotlin class
open class Plant (var x:type) {
open fun function(){
}
}
class Tree : Plant
constructor (donor:type) : super (x)
kotlin regex
Regex(““)
results = regex.matchEntire(x)
kotlin reader and writer
val reader = BufferedReader(FileReader(““))
val writer = BufferedWriter(FileWriter(““))
c input
char buffer[32]
printf(“Enter”)
char * x = fgets(buffer, 32, stdin)
c string copy
strcpy(destination, source)
c struct
typedef struct name {
char x
int years;
} name
scanning
convert sequence of character to tokens
parser
processes tokens and focuses on syntax structure
Go
concurrency
imperative/OOP
Lua
simple
space time effient
oop
no concurrency
R
stats
functional and OOP
Cobol
old
processes records, payroll, accounting
readable
imperative
like assembly
Crystal
oop
good performance
readable
faster than python
Rust
memory safety without garbage collection
functional and oop
hard to learn
takes a while to compile
C#
similiar to java
c style
desk and mobile apps
Julia
for research
clean syntax
math friendly
easy parallelism
Clojure
functional
for concurrency
Velato
music
no parallelism
Lean
proofs
functional
Lua
procedural
people needed their own language
good for games, apps, embedded systems