Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: David Kopec

Rating 4.0 AI initial rating

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

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...
View in text
Excerpt 2
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...
View in text
Excerpt 3
col_start=minus.col_start, col_end=expression.col_end, operator=TokenType.MINUS, expr=expression) raise ParserError("Unexpected token in numeric expre ssion....
View in text
Excerpt 4
. 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...
View in text
Excerpt 5
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...
View in text
Excerpt 6
bles(n1, n2, n3) + self. v[0] jumped = True case (0xC, x, _, _): # v[x] = random number (0-2 55) & last2 self.v[x] = last2 & randint(0, 255) case (0xD, x, y,...
View in text
Excerpt 7
(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...
View in text
Excerpt 8
self.ppu.spr[i] = self.read_memory((from_address + i), MemMode.ABSO LUTE) # Stall for 512 cycles while this completes self.stall = 512 elif address == 0x4016...
View in text
Tags
AI categories
Programming LanguagePython
ISBN: 1718504306
Publisher: No Starch Press
Publish Year: 2025
Language: English
Pages: 398
File Format: PDF
File Size: 20.2 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…