DevPrep

All topics › Programming basics

Programming

Junior

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: 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

Static vs dynamic typing

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store