If you’ve been programming for a while, you may have found yourself wondering about the deeper principles behind the code. How are programming languages implemented? What does an interpreter really do? How does the microprocessor execute instructions at a fundamental level? How does a machine learning algorithm make decisions?
Computer Science from Scratch is for experienced Python programmers who want to fill in those gaps—not through abstract lectures, but through carefully designed projects that bring core CS concepts to life. Understanding these fundamental building blocks will make you a more versatile and effective programmer.
Each chapter presents a focused, hands-on project that teaches a fundamental idea in computer science:
- INTERPRETERS: Understand syntax, parsing, and evaluation by writing a BASIC interpreter
- EMULATORS: Learn computer architecture by building an NES emulator from the ground up
- GRAPHICS: Explore image manipulation and algorithmic art through computer graphics projects
- MACHINE LEARNING: Demystify classification by implementing a simple, readable KNN model
These projects aren’t about building tools—they’re structured lessons that use code to reveal how computing works. Each chapter concludes with real-world context, thoughtful extensions, and exercises to deepen your understanding.
Authored by David Kopec, a computer science professor and author of the popular Classic Computer Science Problems series, this is not a beginner’s book, and it’s not a theory-heavy academic text. It’s a practical, code-driven introduction to the essential ideas and mechanisms of computer science—written for programmers who want more than syntax.
If you’ve been writing Python and are ready to explore the foundations behind computing, this book will guide you there—with clarity, depth, and purpose.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A hands-on tour of computer science fundamentals for experienced Python programmers, taught through seven progressively harder projects—from a tiny Brainfuck interpreter to an NES emulator, retro graphics, and a KNN classifier. Read it if you want to understand how the machinery beneath your code actually works, not just how to use it.
【Book Arc】
- **Opening (~0%–10%)**: Frames the book's premise—experienced Pythonistas filling conceptual gaps—and starts with the smallest possible language, a Brainfuck interpreter, to introduce the core tenets of any interpreter (cells, instruction pointer, bracket matching).
- **Early (~10%–35%)**: Builds a full NanoBASIC interpreter, covering imperative vs. declarative paradigms, grammar design, tokenizer/parser/interpreter phases, AST node types, and the distinction between parser (syntax) and interpreter (semantic) errors.
- **Middle (~35%–50%)**: Shifts to retro image processing—dithering a modern photo to 1-bit black-and-white for a classic Macintosh, plus the PackBits compression scheme and MacPaint/MacBinary file formats and raw-byte handling.
- **Late (~50%–85%)**: The book's hardest project, an NES emulator built from the ground up, teaching computer architecture and low-level instruction execution (excerpts do not detail the intermediate graphics/art chapters beyond the dithering project).
- **Ending (~85%–100%)**: Demystifies machine learning by implementing a readable K-Nearest Neighbors classifier, closing the arc from language internals to hardware to data-driven decision-making.
【Key Takeaways】
- **Interpreters decompose into tokenizer, parser, and evaluator** (Early): the Brainfuck and NanoBASIC projects show how grammar production rules map directly onto recursive-descent parser functions and AST nodes.
- **Grammar is a blueprint, not the whole story** (Early): syntax rules specify structure but leave semantics—like variable initialization—to the interpreter, which is why error handling splits into parser vs. interpreter errors.
- **Imperative vs. declarative is a design lens** (Early): NanoBASIC's imperative style (explicit how) contrasts with declarative "what" thinking, sharpening how you reason about language design.
- **Raw bytes and file formats matter** (Middle): working with `bytes`, `bytearray`, and `array("B")`, plus PackBits and MacBinary, reveals the practical layer beneath high-level abstractions.
- **Compression schemes have structural limits** (Middle): PackBits' run-length cap is sidestepped by encoding MacPaint one row at a time—a lesson in designing around constraints.
- **Emulation teaches architecture from the inside** (Late): building an NES emulator forces engagement with how a microprocessor executes instructions at a fundamental level.
- **ML can be demystified with readable code** (Ending): a simple KNN model shows classification decisions without heavy math or black-box libraries.
- **Projects are lessons, not tools** (Opening): each chapter ends with real-world context, extensions, and exercises, reinforcing that the goal is understanding mechanisms.
【Reading Tips】
- **Deep-read the interpreter chapters (1–2)**: they establish vocabulary (tokens, AST, grammar) reused throughout; skimming here makes later chapters harder.
- **Skim the "Code Meets Life" interludes** for motivation, but don't skip the exercises—they're where the concepts consolidate.
- **Treat the NES emulator as the hard summit**: expect the steepest climb; lean on the provided source code and tests rather than trying to derive everything yourself.
- **Run the tests**: the book ships unit/integration tests and continuous integration; using them turns reading into active verification.
- **Bridge chapters by theme**: interpreters → emulators → graphics → ML form a fundamentals-to-application progression; read in order to preserve that arc.
【Coverage Limits】
The excerpts are thin on the intermediate graphics/art chapters and the NES emulator internals; this guide reflects the interpreter, dithering, and framing material most fully represented, and does not cover chapter-level detail the excerpts omit.
Excerpt 1
ook will guide you there—with clarity, depth, and purpose. only in an editorial fashion and to the benefit of the trademark owner, with no intention of infri...
alues for the line numbers are arbitrary as long as they’re in increasing order. On lines 10 and 11, we start the sequence with the hardcoded initial values...
. 128 Skip. Have you thought of a limitation of this scheme? What if there are more than 128 bytes in a run? Thankfully, we won’t run into this problem when...
on the core algorithm while leaving the busywork to Pillow. That’s what a great library enables. x2 = max(xcoords) y2 = max(ycoords) return x1, y1, x2, y2 A...
(IRQ). Since Python has only a single type for all integers regardless of size, we represent all of these registers except the flags with the int type. Inste...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Add Tag
Enter tag name (max 50 characters)
Share E-Book
Computer Science From Scratch Building Interpreters, Art, Emulators and ML in Python (David Kopec)(Z-Library)
Scan QR code with your phone to access
Copy the link or scan the QR code to access this e-book on your phone
Share to WeChat Moments
Computer Science From Scratch Building Interpreters, Art, Emulators and ML in Python (David Kopec)(Z-Library)
Scan the QR code with WeChat to open this book
Tap the ··· menu in the top-right corner
Choose Share to Moments
You are already in WeChat. Tap ··· in the top-right corner and choose Share to Moments.
Share E-Book via Email
Please enter email address
Donation Statistics
¥.00
Total Donations
0
Donation Count
Computer Science From Scratch Building Interpreters, Art, Emulators and ML in Python (David Kopec)(Z-Library)
Find Your Favorite Books
Only registered users can comment after logging in. Comments need to be reviewed by administrators before being displayed
Loading comments...
Reply to Comment
Edit Comment