From Fundamentals to Expert-Level Mastery
Introduction
- Why Another Systems Language?
- What This Book Covers
- How to Read This Book
- Prerequisites
- The Philosophy Behind This Book
Chapter 1: The Story of Nim – History, Philosophy and Vision
- The Birth of Nimrod: A New Beginning
- From Nimrod to Nim: Rebranding and Maturation
- Design Philosophy: What Makes Nim Different
- Where Nim Fits Today: The Language Landscape
- Who Should Use Nim and Why
Chapter 2: Getting Started – Installation, Tooling and Your First Programs
- Installing Nim: The choosenim Approach
- Your Development Environment: Editors, LSP and Debuggers
- Your First Nim Program: Hello World and Beyond
- The Nim Compilation Pipeline: Source to Binary
- Project Structure and Build Configuration
- Mini-Project Kickoff: Building a CLI Data Processor
Chapter 3: Syntax, Variables and Data Types
- Basic Syntax: Statements, Blocks and Whitespace
- Variables and Constants: var, let, const
- Primitive Types: Integers, Floats, Chars, Strings
- Compound Types: Arrays, Sequences, Tuples and Sets
- Type Conversion and Casting: cast, int()
- Idiomatic Nim: Data Types and Variables
- Common Pitfalls: Data Types
Chapter 4: Operators, Expressions and Control Flow
- Arithmetic and Comparison Operators
- Logical and Bitwise Operators
- Assignment and Compound Assignment
- Conditionals: if/elif/else and case Statements
- Loops: while, for, countup/down and break/continue
- Idiomatic Nim: Control Flow
- Common Pitfalls: Control Flow
Chapter 5: Procedures, Closures and Function Design
- Defining Procedures: proc vs func
- Parameters: Positional, Named, Default and Varargs
- Return Values and Result Variable
- Closures and Lambda-like Constructs
- Advanced Procedure Features: Pragmas, Effects and the Effect System
- Idiomatic Nim: Procedure Design
- Common Pitfalls: Procedures
- Modules, Packages and Project Organization
- Understanding Nim’s Module System
- Project Structure and Module Organization
- Nimble Package Management in Depth
- Module Design Best Practices
- Common Pitfalls: Modules
Chapter 6: Iterators, Generics and Type Parameters
- Iterators: The Heart of Nim’s for Loops
- Building Custom Iterators: From Simple to Complex
- Generics and Type Parameters: proc[T], type constraints
- Concepts and Type Classes: Static Duck Typing
- Generic Objects and Advanced Patterns
- Idiomatic Nim: Iterators and Generics
- Common Pitfalls: Iterators and Generics
Chapter 7: Object-Oriented Programming in Nim
- Objects and Fields: Defining Data Structures
- Operator Overloading and Custom Operators
- Inheritance and Subtyping: of, is and Dispatch
- Polymorphism: Dynamic vs Static Dispatch
- Classes and Reference Semantics: ref Objects
- Mini-Project Update: datatool – Data Models
- Idiomatic Nim: Object-Oriented Programming
- Common Pitfalls: Object-Oriented Programming
Chapter 8: Functional Programming Patterns
- Higher-Order Procedures: Passing Functions as Arguments
- The sugar Module: map, filter, toSeq and More
- Immutability Patterns with let
- Recursion and Tail Call Considerations
- Monads and the do Block Pattern
- Idiomatic Nim: Functional Programming
- Common Pitfalls: Functional Programming
Chapter 9: Templates, Macros and Metaprogramming
- Templates: Compile-Time Text Substitution
- Macro Basics: Manipulating the AST
- Building Useful Macros: Code Generation Patterns
- Advanced Metaprogramming: Static Code Analysis and Transformation
- The Meta Module and AST Utilities
- Idiomatic Nim: Metaprogramming
- Common Pitfalls: Metaprogramming
Chapter 10: Memory Management – ARC, ORC, GC and Manual Control
- The Reference Counting Systems: ARC vs ORC
- Garbage Collection: Refc and Mark-and-Sweep
- Manual Memory Management: alloc, dealloc, realloc
- The Stack vs The Heap: Where Data Lives
- Memory Safety Patterns and Ownership Conventions
- Idiomatic Nim: Memory Management
- Common Pitfalls: Memory Management
Chapter 11: Error Handling and Exception Management
- Exceptions: try/except/finally
- Raising and Creating Custom Exceptions
- The Result Pattern: Returning Errors as Values
- Assertions and Debugging Aids: assert, doAssert, staticAssert
- Error Handling Best Practices and Anti-patterns
- Idiomatic Nim: Error Handling
- Common Pitfalls: Error Handling
Chapter 12: Concurrency and Asynchronous Programming
- Async/Await: The async Module
- Threads and Parallelism: the thread module
- Channels and Message Passing: the Channel[T] Type
- Select and Multiplexing: Handling Multiple Async Operations
- Concurrency Patterns: Actor Model, Worker Pools and Pipelines
- Mini-Project: Concurrent Web Scraper
- Idiomatic Nim: Concurrency
- Common Pitfalls: Concurrency
Chapter 13: Interoperability – C/C++ FFI and Compile-Time Execution
- The Foreign Function Interface: importc
- Including C Headers and Linking Libraries
- Compile-Time Code Execution: the static Keyword and runNimScript
- Generating C Code: exportc and cexport
- Real-World FFI Examples: Using OpenSSL, SQLite and System Libraries
- Mini-Project Update: datatool – SQLite Integration
- Idiomatic Nim: Interoperability and FFI
- Common Pitfalls: FFI and Interoperability
Chapter 14: The Standard Library, Performance, Testing and Deployment
- The Standard Library Tour: Key Modules
- Performance Optimization: Compiler Flags, Benchmarks and Profiling
- Testing with unittest and Beyond
- Debugging Techniques: GDB Integration, Logging and Diagnostics
- Package Management with Nimble and Deployment
- Mini-Project: REST API Server with Jester
- Consolidated Best Practices and Common Pitfalls
Conclusion
- What You Have Learned
- The Nim Ecosystem: Where Things Stand
- When Nim Is the Right Choice
- When to Look Elsewhere
- The Future of Nim
- Your Next Steps
- Final Thoughts
