Comparative Programming Languages

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/92

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

93 Terms

1
New cards

[Typing] Static type checking (definition)

Types are checked before execution (compile time); many type errors caught early.

2
New cards

[Typing] Dynamic type checking (definition)

Types are checked during execution (runtime); type errors occur when code runs.

3
New cards

[Typing] Static typing: 2 advantages

Early error detection; better tooling/optimisation.

4
New cards

[Typing] Static typing: 2 disadvantages

More upfront type constraints; some dynamic patterns are harder.

5
New cards

[Typing] Dynamic typing: 2 advantages

Flexible prototyping; fewer upfront annotations.

6
New cards

[Typing] Dynamic typing: 2 disadvantages

More runtime errors; harder refactors without tests.

7
New cards

[Typing] Type inference (definition)

Compiler deduces types from usage (often still statically checked).

8
New cards

[Typing] Is Haskell statically typed?

Yes; static typing with strong inference.

9
New cards

[Typing] C type checking (one line)

Mostly static (declared types checked), but casts/UB can bypass safety.

10
New cards

[Typing] Python type checking (one line)

Dynamic at runtime; names can be rebound to different types.

11
New cards

[Typing] Strong vs weak typing (safe phrasing)

Strong: fewer implicit unsafe coercions; weak: more coercions—use examples.

12
New cards

[Typing] maplist definition in paper (what it does)

Maps a list of functions over a list of values elementwise.

13
New cards

[Typing] Type of maplist (from paper)

maplist :: [a -> b] -> [a] -> [b]

14
New cards

[Typing] Why maplist is partial

Missing cases for mismatched list lengths; pattern match can fail.

15
New cards

[Typing] Compile-time vs runtime error

Compile-time caught before running; runtime occurs during execution.

16
New cards

[Typing] Example dynamic type error (Python)

"3" + 4 raises a TypeError at runtime.

17
New cards

[Typing] What is a type error?

Applying an operation to incompatible types under language rules.

18
New cards
19
New cards

[Scoping] Lexical/static scope (definition)

Name resolution depends on program text structure (nearest enclosing definition).

20
New cards

[Scoping] Dynamic scope (definition)

Name resolution depends on call chain at runtime (most recent binding).

21
New cards

[Scoping] Static scoping: 2 pros

Predictable from code; supports modular reasoning.

22
New cards

[Scoping] Dynamic scoping: 2 cons

Harder to reason; depends on call path and can cause accidental capture.

23
New cards

[Scoping] C: how to create a new scope

Use blocks { } (functions, if/for/while blocks create lexical scopes).

24
New cards

[Scoping] Haskell: how to create a new scope

let/in, where, lambda parameters, pattern bindings.

25
New cards

[Scoping] Classic scope-difference pattern

Global x; f prints x; g defines local x then calls f—static prints global, dynamic prints g’s x.

26
New cards

[Scoping] Why outputs differ in that pattern

Static binds f’s x to global; dynamic binds to latest active x in call stack.

27
New cards
28
New cards

[Parameters] Call-by-value (definition)

Argument value copied into parameter; callee assignment doesn’t affect caller.

29
New cards

[Parameters] Call-by-reference (definition)

Parameter aliases caller variable; callee updates affect caller (aliasing).

30
New cards

[Parameters] Call-by-result (definition)

Copy-out only; final parameter value copied back to caller at return.

31
New cards

[Parameters] Call-by-value: 2 pros

No aliasing side effects; simpler reasoning.

32
New cards

[Parameters] Call-by-value: 2 cons

Copy cost for large values; cannot directly modify caller variable.

33
New cards

[Parameters] Call-by-result: key pitfall

If same variable passed twice, copy-out order can change result (aliasing ambiguity).

34
New cards

[Parameters] C: inc by value vs reference (effect)

By value leaves caller unchanged; by reference (pointer) changes caller.

35
New cards

[Parameters] Haskell parameter passing (exam-safe phrasing)

Call-by-need (lazy with sharing); values are immutable, so no reference-style mutation.

36
New cards
37
New cards

[Memory] Manual memory management (definition)

Programmer explicitly allocates/deallocates memory (e.g., malloc/free).

38
New cards

[Memory] Automatic memory management (definition)

Runtime automatically reclaims unreachable memory (garbage collection).

39
New cards

[Memory] Manual management: 2 advantages

Fine control; potentially predictable performance (no GC pauses).

40
New cards

[Memory] Manual management: 2 disadvantages

Leaks/dangling/double-free risk; higher programmer burden.

41
New cards

[Memory] Automatic management: 2 advantages

Fewer memory-safety bugs; simpler development.

42
New cards

[Memory] Automatic management: 2 disadvantages

GC overhead/pauses; less control of reclamation timing.

43
New cards

[Memory] Stack vs heap (one line)

Stack: frames/locals, automatic; heap: dynamic objects, manual free or GC.

44
New cards

[Memory] How to allocate in C

Heap allocation via malloc/calloc/realloc; locals typically on stack.

45
New cards

[Memory] How to deallocate in C

free(p) for heap; stack memory is automatic on return.

46
New cards

[Memory] How to allocate in Java

Objects allocated with new on heap (managed by JVM).

47
New cards

[Memory] How to deallocate in Java

GC reclaims unreachable objects; no explicit free.

48
New cards

[Memory] Memory leak (definition)

Allocated memory is never freed and becomes unusable; memory consumption grows.

49
New cards

[Memory] Dangling pointer (definition)

Pointer refers to memory that has been freed (use-after-free risk).

50
New cards

[Memory] Double free (definition)

free called twice on same pointer; undefined behaviour.

51
New cards

[Memory] Segmentation fault (typical cause)

Invalid memory access (NULL/dangling/out-of-bounds).

52
New cards

[Memory] Minimal leak pattern (C)

malloc then lose pointer / return without free.

53
New cards

[Memory] Minimal use-after-free pattern (C)

free(p) then dereference p.

54
New cards

[Memory] Buffer overflow (definition)

Write past allocated bounds; can corrupt memory and crash/exploit.

55
New cards
56
New cards

[OOP] Inheritance (definition)

Class derives behaviour/state from another; supports reuse via specialization.

57
New cards

[OOP] Encapsulation (definition)

Hide internal state; expose operations through controlled interface.

58
New cards

[OOP] Polymorphism (general definition)

Same interface, different implementations depending on type.

59
New cards

[Polymorphism] Inclusion polymorphism (definition)

Subtype polymorphism: subtype usable where supertype expected (dynamic dispatch).

60
New cards

[Polymorphism] Parametric polymorphism (definition)

Generic code works uniformly for many types (e.g., Java generics).

61
New cards

[Polymorphism] Inclusion poly: Java example

List xs = new ArrayList<>(); (ArrayList used where List expected)

62
New cards

[Polymorphism] Parametric poly: Java example

static int len(List xs){ return xs.size(); }

63
New cards

[Polymorphism] Overriding (definition)

Subclass replaces superclass method implementation with same signature.

64
New cards

[Polymorphism] Why overriding matters for inclusion poly

Base reference calls method; runtime dispatch picks subclass override.

65
New cards

[Polymorphism] Dynamic dispatch (definition)

Method chosen at runtime based on object’s actual class.

66
New cards

[Polymorphism] Multiple inheritance (definition)

Class inherits from more than one parent class.

67
New cards

[Polymorphism] Diamond problem (definition)

Ambiguity when inheriting same member along two paths from a common ancestor.

68
New cards

[Polymorphism] Java vs diamond problem

Java avoids MI of classes; uses interfaces and requires disambiguation for default method conflicts.

69
New cards

[Polymorphism] Python vs diamond problem

Python supports MI and resolves via MRO (C3 linearization); method lookup follows MRO.

70
New cards
71
New cards

[Prolog] Declarative programming (one line)

Specify what should hold (relations), not step-by-step control flow.

72
New cards

[Prolog] Fact vs rule vs query

Fact: basic assertion; rule: derived relation; query: ask what satisfies relations.

73
New cards

[Prolog] Unification (definition)

Make two terms equal by binding variables (constraint solving).

74
New cards

[Prolog] Backtracking (definition)

Prolog explores alternatives; on failure it tries the next possibility.

75
New cards

[Haskell] Pure function (definition)

No side effects; output depends only on inputs (referential transparency).

76
New cards

[Haskell] Immutability (definition)

Values don’t change; “updates” create new values.

77
New cards

[Haskell] Lazy evaluation (definition)

Evaluate only when needed; results are shared (call-by-need).

78
New cards

[Compare] Prolog relations vs Haskell functions

Prolog relations can generate/check via unification/backtracking; Haskell functions compute results and must explicitly enumerate alternatives.

79
New cards

[Compare] Pattern matching vs unification

Pattern matching decomposes values one-way; unification binds variables to make terms equal (often bidirectional).

80
New cards

[Prolog/Haskell] Prolog split using append

pairs(L,A,B) :- append(A,B,L). Generates all (A,B) via backtracking.

81
New cards

[Prolog/Haskell] Haskell generate all splits idea

Enumerate n and return (take n xs, drop n xs) for n=0..length xs.

82
New cards

[Prolog/Haskell] Haskell remove-all (idea)

Recurse; if x==n skip else keep x.

83
New cards

[Prolog/Haskell] Prolog remove-all (idea)

Two recursive rules: drop head if equals N; otherwise keep head.

84
New cards
85
New cards

[Rust] Ownership (definition)

Each value has one owner; when owner goes out of scope, value is dropped.

86
New cards

[Rust] Borrowing rule (core)

Many immutable references OR one mutable reference at a time (enforced at compile time).

87
New cards

[Concurrency] Data race (definition)

Two threads access same memory concurrently, at least one write, without synchronisation.

88
New cards

[Rust] Why Rust prevents data races

Borrow checker prevents unsynchronised shared mutable aliasing; safe sharing requires sync types.

89
New cards

[Rust] Channels (definition)

Message passing; ownership of messages moves from Sender to Receiver.

90
New cards

[Compare] Rust channels vs Java threads

Rust: ownership + message passing reduces shared-state races; Java: shared memory common and must be synchronised.

91
New cards

[Java] Threads (definition)

Concurrent execution units sharing memory; correctness depends on synchronisation.

92
New cards

[Haskell] Why data races are “not a problem” (core idea)

Pure code + immutability means no shared mutable state in ordinary functions; concurrency evaluates expressions safely.

93
New cards