Running Example

Resourceful Code Reuse — by Dmitry Zinoviev (9 / 20)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 C vs. Python | TOC | Chapter 1 Reuse Code at Compile Time (C and Python) 👉

Throughout the book, I’ll show you how to reuse code written mostly in the C language and occasionally in Python. For that, we’re going to need a running example. We’ll start with a program in C that isn’t necessarily unstructured, cluttered, or hard to maintain, but it’s also not designed to be reused in the future. We’ll slice, dice, and even tear this program apart and put it on different computers to make the code more reusable.

Interestingly, you don’t even need to know anything about the problem that the program solves to understand the reuse mechanisms. A differential equation solver is as good as a web browser, which, in turn, is as good as a program that controls a unicorn feeder. So, let’s pick a common problem that has been automated time and again: a program that reads the content of a JSON file into a C or Python data structure, modifies it somehow, and writes the modified data structure to another JSON file.

A Note on JSON

The name “JavaScript Object Notation” (JSON) is misleading in almost every aspect. For starters, JavaScript itself may have more in common with Java coffee than Java language, but that’s not JSON’s fault. Second, JSON was designed to work with JavaScript, but now it’s used as a programming language — agnostic data exchange language and isn’t attached to JavaScript anymore…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.