Appendices: Projects, Review Questions, Cheat Sheet & Resources
Capstone projects, interview and review questions, a cheat sheet, Nim for Python / C / Rust / Go developers, and resources.
Appendix A: Capstone Projects
Beginner: CLI To-Do Manager. Commands (add/list/done/delete), JSON file persistence, colored terminal output, parseopt, and unit tests.
Beginner: Text Adventure Game. Object variants for rooms and items, tables, a command parser, save/load.
Intermediate: Markdown → HTML Converter. String parsing, iterators, std/strscans or npeg, an HTML templating DSL, tests, and published docs.
Intermediate: REST API Service. Jester/Prologue/Mummy + SQLite via norm or debby, JWT auth, input validation, structured logging, Dockerfile, CI.
Intermediate: Concurrent Web Crawler. Async HTTP (asyncdispatch or chronos), rate limiting, robots.txt, HTML parsing (std/htmlparser), and storing results.
Advanced: Interpreter for a Small Language. Lexer, parser (object-variant AST), tree-walking evaluator, then bytecode compilation and a VM. Add a REPL.
Advanced: Compile-Time ORM / Serialization Library. Macros that generate SQL schemas and (de)serializers from object definitions, with runnableExamples and tests.
Advanced: Parallel Image Processor. pixie + malebolgia/weave, a filters pipeline, a benchmark against a single-threaded version, and a CLI with cligen.
Advanced: C Library Wrapper. Wrap a C library (e.g., zlib, SQLite, or libcurl) with futhark or c2nim, add an idiomatic high-level API with destructors (RAII), and publish to Nimble.
Systems: Embedded Firmware or Game. An RP2040/ESP32 blink-and-sensor project with --mm:arc --os:any, or a raylib/naylib 2D game with a WASM build.
Full-stack: Shared-Code Web App. A Karax frontend (JS backend) and a Mummy/Jester backend (C backend) sharing model types and validation code.
Appendix B: Interview and Review Questions
What backends can Nim compile to? Why does compiling to C matter?
Explain var, let, and const.
What is style insensitivity? What exactly is case-sensitive?
What is the difference between proc, func, method, iterator, template, macro, and converter?
What is the implicit result variable?
What is UFCS? Give examples.
Explain discard and {.discardable.}.
Difference between array, seq, and openArray?
How do .., ..<, and ^1 work?
What does when do vs if?
Types and Memory Value vs reference semantics: object vs ref object?
What are object variants, and when do you use them?
What is a distinct type? What does {.borrow.} do?
Explain Option[T] and nil handling.
Explain ARC vs ORC. What are =destroy, =copy, =sink, =wasMoved, =dup, and =trace?
What are sink and lent? When is a copy turned into a move?
How do you make a type move-only?
What is {.cursor.}? What is {.acyclic.}?
What are ptr, addr, and cast, and when are they appropriate?
Templates vs macros: when do you use each? What are untyped and typed?
What is template hygiene? What do inject, gensym, and dirty do?
How do you inspect and construct ASTs (dumpTree, quote do, genAst)?
What are concepts? Old-style vs new-style?
Explain the effect system: raises, tags, forbids, noSideEffect, gcsafe.
Exceptions: CatchableError vs Defect. What does --panics:on do?
How do threads share data safely in Nim 2 (channels, Isolated, locks, atomics)?
asyncdispatch vs chronos? How do async procs work under the hood?
How do you call a C function? How do you build a shared library from Nim?
What's the difference between -d:release and -d:danger?
What is NimScript used for?
What are mixin and bind in generics?
How do static parameters and const evaluation work (the Nim VM)?
Implement a generic Stack[T] with push, pop, peek, and an items iterator.
Write a template retry(n, body) that retries the body on exception.
Write a macro enumToString that generates a $ proc with custom names.
Implement a Matrix type with [], []=, *, and $ operators.
Implement a move-only UniqueBuffer with destructor hooks.
Write an async TCP echo server.
Wrap the C qsort function and call it with a Nim comparator.
Appendix C: Nim Cheat Sheet
# ===== Basics =====
var x = 1; let y = 2; const Z = 3
var a: int; var s: string = "hi"
echo x, " ", y, " ", $Z
echo typeof(x), sizeof(x)
# ===== Control flow =====
if x > 0: echo "pos" elif x < 0: echo "neg" else: echo "zero"
case x
of 0: discard
of 1..9: echo "digit"
else: echo "big"
for i in 0..<10: discard
for i, v in @[1, 2]: discard
while x < 10: inc x
block outer:
break outer
# ===== Procs =====
proc add(a, b: int): int = a + b
func sq(x: int): int = x * x
proc inc2(x: var int) = x += 2
proc greet(name = "World") = echo "Hi ", name
iterator evens(n: int): int =
for i in countup(0, n, 2): yield i
template twice(body: untyped) = body; body
# ===== Collections =====
let arr = [1, 2, 3]
var sq2 = @[1, 2]; sq2.add 3
let t = (name: "A", age: 1)
var tbl = {"a": 1}.toTable # import std/tables
var st = {'a', 'b'}
type Color = enum Red, Green
# ===== Types =====
type
P = object
x, y: int
R = ref object
v: int
K = enum kA, kB
V = object
case kind: K
of kA: a: int
of kB: b: string
Meters = distinct float
# ===== Errors =====
try: raise newException(ValueError, "bad")
except ValueError as e: echo e.msg
finally: discard
defer: echo "bye"
#
…nim c -r app.nim # debug build + run
nim c -d:release app.nim # optimized
nim c -d:danger app.nim # no checks
nim cpp / nim js / nim doc / nim check
nimble init | build | run | test | install pkg | publishAppendix D: Nim for Python / C / Rust / Go Developers
proc / func fmt"..." / &"..." exceptions / Result generics + traits generics + concepts concepts / methods ARC/ORC + moves templates + AST macros Key gotchas:
Python devs: there's no implicit int/float mixing, indentation must use spaces only, and / returns a float while div does integer division.
C devs: strings and seqs have value semantics (assignment copies or moves), and bounds checking is on by default.
Rust devs: there's no borrow checker. Safety comes from runtime checks plus ARC/ORC, and moves are optimizations, not ownership errors.
Go devs: there are no goroutines built in (use async or a thread pool library), and generics plus macros are much more powerful.
Appendix E: Resources
nim-lang.org: Downloads, Tutorial Parts 1–3, Manual, Standard Library docs, Nim Destructors and Move Semantics doc, Compiler User Guide, Nimble docs, the Nim blog
play.nim-lang.org: online playground forum.nim-lang.org, the Nim Discord/Matrix, r/nim Books and Courses
*Nim in Action*: Dominik Picheta (Manning; covers Nim 0.x but the concepts still hold)
*Mastering Nim*: Andreas Rumpf (the creator's book, Nim 2 era)
*Nim Basics* (narimiran.github.io/nim-basics): beginner tutorial
*Nim by Example* (nim-by-example.github.io) *Computer Programming with Nim*: Stefan Salewski (free online book)
Exercism Nim track, Nim Days, Advent of Code in Nim solutions Community Tools and Organizations
Status-im (nim-chronos, nim-results, nim-stew, nimbus-eth2), treeform (pixie, jsony, debby, mummy), SciNim, nim-lang/threading, awesome-nim (curated list on GitHub), nimble.directory (package search) Suggested 10-Week Study Plan Setup, syntax, types, operators Control flow, procs, strings Collections, objects, variants, refs Type system, iterators, modules, errors OOP, generics, closures/FP, effects Stdlib, files/OS, testing/docs, Nimble
Pragmas, compile time, templates, macros, DSLs, concepts ARC/ORC, move semantics, threads, async
FFI, JS backend, systems, build config, debugging, performance 42–49 + Capstone
Web, DB, CLI, GUI/games, embedded, science, best practices Final tip: Write a little Nim every day, read the Manual and the stdlib source (it's very readable Nim), use --expandArc and dumpTree to understand what the compiler does, and build one real project end to end. Happy hacking! 👑