Programming
Essence
Programming is turning a problem into a runnable program: data model, algorithm, code in a language, build, debugging, maintenance. Code is only part of it; reading other people's code, tests and the ability to explain a decision matter just as much. With this question an interviewer usually wants to hear about paradigms and about what kind of language Swift is.
Paradigms, and what they look like in Swift
- Imperative / procedural — a sequence of commands that change state (
for,var, functions). - Object-oriented — data and behaviour are bundled into objects; classes, inheritance, polymorphism.
- Functional / declarative — we describe what to compute, not how: pure functions, immutable data,
map/filter/reduce. SwiftUI is declarative UI. - Protocol-oriented — Swift's signature style: behaviour is described by protocols and extensions rather than class hierarchies.
// Imperative: we describe HOW, step by step, with mutation
var squares: [Int] = []
for n in 1...10 where n % 2 == 0 { squares.append(n * n) }
// Functional: we describe WHAT — pure functions, no mutation
let squares2 = (1...10).filter { $0 % 2 == 0 }.map { $0 * $0 }
// Protocol-oriented: behaviour via a protocol + extension
protocol Shape { var area: Double { get } }
extension Shape { func describe() -> String { "area = \(area)" } }
struct Circle: Shape { var r: Double; var area: Double { .pi * r * r } }
Swift is multi-paradigm: one file can combine all four approaches.
Compiled vs interpreted
- Compiled (Swift, C, Rust): source is translated to machine code ahead of time; faster, type errors are caught before launch. On iOS this is the only option: JIT is forbidden for third-party apps.
- Interpreted (Python, Ruby, JavaScript): an interpreter executes the code at run time; slower but more flexible. Modern engines use JIT, so the line is blurred.
Static vs dynamic typing
- Static (Swift, Kotlin, TypeScript): a variable's type is known at compile time. Swift is static, strong (no implicit conversions) and type-inferred.
- Dynamic (Python, JavaScript, Objective-C's message passing): the type is checked at run time; one variable may hold values of different types.