CSfSCover?timestamp=6374

You know how to write Python. Now master the computer science that makes it work.

Get Sample ChapterBuy Book

Projects

Seven awesome educational projects illuminate computer science principles

The book uses code as a teaching means in a tutorial-like fashion. After a little bit of opening theory, all of the source code for each project is explained step-by-step and in detail.

1. Brainfuck

One of the smallest possible programming languages is used as an example to understand ideas about Turing Machines and interpreters.

NANOBASIC
2. NanoBASIC

An interpreter for Nano BASIC, a dialect of Tiny BASIC—a programming language that was used during the personal computer revolution.

figure3_2
3. Retro Dither

A program that converts modern photos for display on a classic 1980s Mac by performing 1-bit (black & white) Atkinson dithering and converting them to MacPaint format.

figure4_7
4. Impressionist

Impressionist uses a simple stochastic hill climbing algorithm to create abstract art from photographs that (sometimes) looks like the work of an impressionist painter.

figure5_4
5. CHIP-8

An implementation of the CHIP-8 virtual machine that can play all of the 1970s games that were released for CHIP-8.

figure6_8
6. NES Emulator

The simplest possible NES emulator with support for playing real games but lacking sound, performance, compatibility with most mappers, and several other features.

figure8_3
7. Digit Recognizer

You draw a digit and the program can interpret your drawing (KNN classification) and/or complete it (KNN regression).

Contents

Front Matter

Acknowledgments

xv

Introduction

xvii

Part I: Interpreters

Chapter 1: The Smallest Possible Programming Language

3

Chapter 2: Writing a BASIC Interpreter

21

Part II: Computational Art

Chapter 3: Retro Image Processing

63

Chapter 4: A Stochastic Painting Algorithm

89

Part III: Emulators

Chapter 5: Building a CHIP-8 Virtual Machine

115

Chapter 6: Emulating the NES Game Console

141

Part IV: Super-Simple Machine Learning

Chapter 7: Classification with K-Nearest Neighbors

205

Chapter 8: Regression with K-Nearest Neighbors

221

Back Matter

Afterword

231

Appendix: Bitwise Operations

237

Index

245

Description

Computer Science from Scratch: Building Interpreters, Art, Emulators, and ML in Python

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.

Code

This isn’t just sample code. It’s seven working projects

While all of the code is in the book alongside detailed step by step explanations, many readers prefer to have it open in an IDE side-by-side as they read. Most of the projects also have unit tests to check they’re working correctly. Checkout the GitHub repository.

What readers of my books have said

Computer Science from Scratch just came out so it has hardly any reviews. But here’s some quotes about both it and some of my past books. The icons to the left of the reviewer name link to the source of the praise.

Computer Science from Scratch

"I would highly recommend this book to any developer who enjoys learning through practical, project-based work and wants to build interesting and rewarding projects.”

Nekketsu

Amazon (ES) Reviewer

Classic Computer Science Problems in Python

"David is an excellent programmer and teacher and you should buy his book if you have ANY interest in algorithms period.”

Dan

Founder/CTO

Classic Computer Science Problems in Python

"Computer Science degree condensed into a thin book"

Pisarenco

Amazon (DE) Reviewer

Classic Computer Science Problems in Python

“...this is a fantastic book, and I am confirming what I do know and learning all kinds of new information."

Jamie

Engineer

Classic Computer Science Problems in Swift

“Classic Computer Science Problems seems to understand the psychological quirks of software developers and how to use them as a motivational tool."

Mitch

Software Developer

Classic Computer Science Problems in Java

“This book introduced me to the algorithm that I need to solve real-life engineering problem. The language is easy to understand for an non-computer-science person."

Yi

Amazon (US) Reviewer

Get the Book

Get the print book or eBook from Amazon or the publisher.

CSfSCover

No Starch Press

DRM Free

Get the eBook
  • cms icon

    PDF

  • cms icon

    Kindle

  • cms icon

    ePub

No Starch Press

Direct from the Publisher

Get the Print Book
  • cms icon

    280 Pages

  • cms icon

    Includes Free eBook

Amazon

Fast Shipping

Get the Print Book
  • cms icon

    280 Pages

  • cms icon

    Lowest Price

Amazon

Delivered Directly to Your Device

Get the Kindle Book
  • cms icon

    Access in Seconds

  • cms icon

    One Click Purchase

Author

Hey, thanks for stopping by to check out my new book

Find Out More About Me

I’m David Kopec, an Associate Professor of Computer Science at Albright College in Reading, Pennsylvania, USA. Before my decade in academia, I worked as a software developer. Computer Science from Scratch is my fifth book. I think it’s my most fun. I’m also a podcaster, open source project maintainer, and indie app developer.

Author Picture