Code Story

Imperative Code Story Prologue

motivation, story content, references

0.0  Prologue

Code Story surveys the core features common to imperative programming languages - the constructs every language provides and every developer uses daily. Starting from primitive data types and moving through variables, operators, control flow, functions, closures, error handling, memory management, modules, concurrency, generics, and metaprogramming, each chapter covers one feature category in depth.
Why study language features systematically?
  1. Language features are the vocabulary of programming. Mastering them lets you read and write code in any language faster because you recognize the pattern even when the syntax differs.
  2. Trade-offs between features are not arbitrary. Understanding why a language chose garbage collection over ownership, or dynamic dispatch over monomorphization, helps you pick the right tool for each task.
  3. Feature gaps between languages are where bugs hide. Knowing what your language omits or handles differently from others is the fastest route to avoiding surprises.
  4. Fundamentals transfer. Syntax ages; the concepts behind closures, ownership, type parameters, and async state machines do not.
Each chapter is language-agnostic: concepts are illustrated with concise examples from Rust, C++, C#, or Python as appropriate to make ideas concrete.

0.1  Popular Imperative Languages

Language Description
Python High-level, dynamically typed; emphasizes readability and a large standard library. Dominant in data science and scripting.
JavaScript Event-driven, prototype-based language of the web; runs in every browser and on servers via Node.js.
Java Statically typed, class-based; JVM platform gives write-once-run-anywhere portability across enterprise systems.
C# Statically typed, multi-paradigm .NET language; strong generics, LINQ, async/await, and record types.
C++ Systems language with zero-cost abstractions, templates, RAII, and manual memory control; used in performance-critical software.
Rust Systems language with ownership-based memory safety and zero-cost abstractions; no garbage collector, no data races by construction.
Go Statically typed, compiled language from Google; simple concurrency via goroutines and channels, fast compile times.
Kotlin JVM language interoperable with Java; null safety, coroutines, and concise syntax. Primary language for Android development.
Swift Statically typed, compiled language from Apple; value types, optionals, and protocol-oriented design for iOS/macOS development.
C Low-level procedural language; direct memory and hardware access. Foundation of operating systems, embedded systems, and systems software.

0.2  Getting Started

No prerequisites beyond experience in at least one imperative or object-oriented language. Each chapter is self-contained - skip what you know. The Pages list at the lower right navigates between chapters.
  1. Start with Data (Chapter 1) to understand how languages model values before operations are applied to them.
  2. Start with Control Flow (Chapter 4) for a reference on the branching and looping constructs languages provide.
  3. Start with Memory (Chapter 8) if you are moving between languages with different memory models (C++ to Rust, Python to C).
  4. Start with Concurrency (Chapter 10) if your focus is correctness under concurrent execution.

0.3  Story Content

Each chapter covers one imperative language feature category and its sub-topics as page sections. The full sequence:
Chapter Topics
0 – Prologue Motivation, layout, and references for the Code Story.
1 – Data Primitive types, composite types, string types, and type aliases.
2 – Variables & Binding Declaration, mutability, scope, lifetime, shadowing, constants, and statics.
3 – Operators Arithmetic, comparison, logical, bitwise, assignment, and operator overloading.
4 – Control Flow if/else, match/switch, loops, break and continue, and pattern matching.
5 – Functions Declaration, parameters, return types, overloading, recursion, and higher-order functions.
6 – Lambdas & Closures Anonymous functions, environment capture, closure types, and function pointers.
7 – Error Handling Exceptions, Result/Option types, panic and abort, and error propagation.
8 – Memory Management Stack vs heap, ownership and borrowing, garbage collection, reference counting, and manual management.
9 – Modules & Namespaces Module declaration, visibility, imports, packages, and crates.
10 – Concurrency Threads, synchronization primitives, channels, async/await, and atomic operations.
11 – Generics & Polymorphism Generic types and functions, traits and interfaces, trait bounds, dynamic vs static dispatch, and variance.
12 – Metaprogramming Macros, reflection, code generation, attributes and decorators, and compile-time computation.
13 – Projects Ten imperative programming projects, each instructive and producing a useful program or library.

0.4  References

Reference Description
The Rust Programming Language Comprehensive coverage of ownership, types, traits, and concurrency in Rust.
cppreference.com Authoritative C++ language and standard library reference.
C# Language Reference Complete reference for C# language features and syntax.
Python Language Reference Formal reference for Python syntax and core semantics.
ECMAScript Specification The authoritative specification for JavaScript language semantics.