No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-12 10:53:51 -04:00
examples Simplify 2026-10-12 10:53:51 -04:00
examples-swift Simplify 2026-10-12 10:53:51 -04:00
pkg Simplify 2026-10-12 10:53:51 -04:00
tools Simplify 2026-10-12 10:53:51 -04:00
.gitignore Simplify 2026-10-12 10:53:51 -04:00
INDEX.txt Swift by Example: complete gobyexample.com translation (104 checks, 85/85 chapters) 2026-10-08 00:11:21 -04:00
README.md Simplify 2026-10-12 10:53:51 -04:00

Swift by Example

Go by Example translated to the simplest Swift we could write: imperative, zero inheritance in the translation, neat functional tricks only — plus a Swift-only tour (OO included) and a package chapter that finishes what the stdlib can't. Every script chapter is self-contained: swift examples/05-for.swift is go run for.go.

Layout

examples/          all 85 chapters, numbered per gobyexample's own order
examples-swift/    19 Swift-only pages: language gaps (optionals, guard,
                   closures-to-HOFs, grapheme strings), the 6-page OO tour,
                   NIO server family, AoC + Testing capstones
pkg/               11 SwiftPM packages (NIO servers, ArgumentParser CLIs,
                   embed resources, testing tour)
tools/serve-docs.swift
                   browsable reader: `swift tools/serve-docs.swift` →
                   http://127.0.0.1:8080 — all chapters, comments/code
                   side by side, prev/next 1…104 (zero dependencies)
run-all.sh         harness: runs every file, diffs its `//>` expect block
INDEX.txt          chapter order; line number = filename prefix
TRANSLATING.md     style rules, known traps, package-chapter notes
SKIPPED.md         package chapter + supplant + deviation ledger

Ground truth for future chapters: clone mmcgrana/gobyexample into upstream/ (gitignored) — see TRANSLATING.md.

Highlights beyond the translation

  • OO tour (examples-swift/classes-and-inheritance.swift … composition-and-delegation.swift): the inheritance/super/final machinery Go lacks, value vs reference semantics, protocol-oriented defaults, generics vs any vs some, subscripts/operators — closing with why composition beats inheritance anyway.
  • NIO server family: HTTP/1, TCP echo, WebSocket, UDP echo, chat broadcast — real MultiThreadedEventLoopGroup servers, self-testing, deterministic by happens-before rather than sleeps.
  • Testing tour: 52 tests mirroring docs.swift.org/documentation/testing page by page (see pkg/testing-tour).

Rules of the house

  • let by default; scripts, no ceremony; imports on demand.
  • Go concepts with no clean mapping are supplanted by the Swift-native page (inout, actors, cancellation, Swift Testing) — see SKIPPED.md.
  • Third-party deps live only in the package chapter: swift-nio and swift-argument-parser, nothing else.