Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: David Kopec

Rating No ratings yet

You know how to write Python. Now master the computer science that makes it work. 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 build-it-yourself projects spanning interpreters, retro graphics, emulators, and machine learning. Read this if you can already write Python but want to understand the machinery underneath the syntax. 【Book Arc】 - **Opening (~0%–10%)**: Frames the book's premise and audience—intermediate/advanced Python programmers who lack formal CS training—and previews the four project parts plus an appendix on bitwise operations. - **Early (~10%–30%)**: Part I on interpreters. Builds a Brainfuck interpreter to expose the tokenizer/parser/runtime structure, then a NanoBASIC interpreter, establishing the core interpreter pipeline before moving on. - **Middle (~30%–55%)**: Part II on computational art. Covers dithering and the MacPaint file format with run-length encoding, then a stochastic painting algorithm using hill-climbing to generate abstract impressions of images. - **Late (~55%–80%)**: Part III on emulators. Starts with a CHIP-8 virtual machine as a gentle entry point, then escalates to a partial NES emulator covering CPU and PPU emulation. - **Ending (~80%–100%)**: Part IV on machine learning. Implements KNN for classification (fish, handwritten digits) and regression (predicting fish weights, filling in missing digit pixels), closing with an afterword on further learning. 【Key Takeaways】 - **Interpreters decompose into tokenizer, parser, and runtime** (Early): Brainfuck and NanoBASIC show how even a Turing-complete language reduces to a small set of mechanisms—cells, jumps, and branching. - **Turing-completeness needs surprisingly little** (Middle): Integer variables, mutation, conditionals, and a goto suffice; this reframes "real" vs. "toy" languages as a matter of degree, not kind. - **Emulation teaches computer architecture from the inside** (Late): Building a CHIP-8 VM and then an NES emulator forces engagement with registers, memory, instruction execution, and graphics hardware. - **Dithering and run-length encoding connect algorithms to real hardware constraints** (Middle): Adapting color images to a 1-bit Macintosh display shows how historical limitations drive algorithmic design. - **Stochastic search can produce sophisticated art** (Middle): Matching random shapes to an underlying image, optimized by hill-climbing, demonstrates algorithmic creativity beyond deterministic pipelines. - **KNN is a readable gateway to machine learning** (Ending): Classification and regression with k-nearest neighbors demystify ML without heavy math, reaching ~98% accuracy on handwritten digits. - **Bitwise operations underpin several projects** (Early): The appendix on binary, shifts, AND/OR/XOR, and complement is essential groundwork for the emulator and graphics work. - **Each chapter closes with real-world context and exercises** (throughout): Extensions and notes point readers toward deeper study rather than leaving projects as isolated toys. 【Reading Tips】 - Skim the acknowledgments and front matter; start real reading at the Introduction to calibrate whether the book's level matches yours. - Deep-read Part I (interpreters) even if you only care about emulators or ML—the tokenizer/parser/runtime model recurs throughout. - Treat the appendix on bitwise operations as required reading before Part III; the emulator chapters assume fluency with binary manipulation. - Type out and run the code rather than reading passively; the book's value is in the build, and the GitHub repo provides source and a requirements file. - Use the end-of-chapter exercises and "real-world applications" sections as a menu for what to explore next, not as obligations. 【Coverage Limits】 The excerpts cover the book's structure, audience, and project descriptions but do not include detailed chapter content, so this guide cannot summarize specific implementation techniques beyond what the table of contents and introduction reveal.
Excerpt 1
r 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 bo...
View in text
Excerpt 2
der and found ways both large and small to improve the book. And, of course, I’d like to thank the rest of the team at No Starch Press who helped bring the b...
View in text
Excerpt 3
rpreters, computational art, emulators, or machine learning. That may sound weird coming from the author of a book on those topics, but it’s true. I’m not an...
View in text
Excerpt 4
cell is nonzero, move to the corresponding opening bracket. Using Table 1-1 , we have enough information to step through a Brainfuck program and understand w...
View in text
Excerpt 5
ndex] = clamp0_255_wraparound(cells[cell_index] - 1) case ".": print(chr(cells[cell_index]), end='', flush=True) case ",": cells[cell_index] = clamp0_255_wra...
View in text
Excerpt 6
elf): program_output = run(self.example_folder / "fibonacci.bf") expected = "1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89" self.assertEqual(program_output, expected)...
View in text
Excerpt 7
for personal computers from the mid-1970s to the mid-1980s. Common computers of the era, like the Commodore 64 and the Apple II, came with built-in BASIC int...
View in text
Excerpt 8
Tiny BASIC implementations were limited to 16-bit integers. Our variables are backed by Python integers behind the scenes, which are of arbitrary precision,...
View in text
Tags
AI categories
Programming LanguagePythonEducation
ISBN: 1718504314
Publisher: No Starch Press
Publish Year: 2025
Language: English
File Format: EPUB
File Size: 18.8 MB