Jump to ratings and reviews
Rate this book

Exercises in Programming Style

Rate this book
Using a simple computational task (term frequency) to illustrate different programming styles, Exercises in Programming Style helps readers understand the various ways of writing programs and designing systems. It is designed to be used in conjunction with code provided on an online repository. The book complements and explains the raw code in a way that is accessible to anyone who regularly practices the art of programming. The book can also be used in advanced programming courses in computer science and software engineering programs.



The book contains 33 different styles for writing the term frequency task. The styles are grouped into nine categories: historical, basic, function composition, objects and object interactions, reflection and metaprogramming, adversity, data-centric, concurrency, and interactivity. The author verbalizes the constraints in each style and explains the example programs. Each chapter first presents the constraints of the style, next shows an example program, and then gives a detailed explanation of the code. Most chapters also have sections focusing on the use of the style in systems design as well as sections describing the historical context in which the programming style emerged.

304 pages, Paperback

First published January 15, 2014

10 people are currently reading
531 people want to read

About the author

Cristina Videira Lopes

3 books4 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
51 (46%)
4 stars
46 (41%)
3 stars
11 (10%)
2 stars
2 (1%)
1 star
0 (0%)
Displaying 1 - 15 of 15 reviews
Profile Image for Eduardo.
71 reviews7 followers
August 30, 2015
I must say I'm impressed with this book. The idea is not new (Rosetta Stone has been around the corner for a while), but a major innovation of this book is the discussion of each style and how it relates to other styles.

I have to admit I was a little bit thrown off by the, apparently weird at the time, choice of Python as the one and only language to demonstrate the different styles. In the end I realized that far from being a nuisance, this was yet another constraint that proved useful to demonstrate the major point of the book: styles are defined by constraints.
Profile Image for SY77.
29 reviews2 followers
July 11, 2020
I've been programming since late 90s, and while I'm familiar with all (and more than I like to admit with some) of the styles described in this book, it was interesting to see it from a zoomed out perspective.

The material is nicely structured and I think would be accessible to beginners. I was delighted to see a chapter on monads which boils it down to essentialls (while admittedly losing many important details) instead of yet another confusing attempt to draw a box or burrito analogy.
Profile Image for Eric Lewis.
8 reviews5 followers
June 4, 2018
Exercises in Programming Style takes one programming problem (what are the 25 most frequently used words in Pride and Prejudice?) and solves it in 33 different programming styles (e.g. functional, monads, pub-sub). Lopes presents code examples in Python, as well as a few paragraphs of commentary and historical context on each.

To be honest, I can't remember a more useful book about the technique of programming I've read. It's easy to focus on one style while working with a single library or technology. This book will zoom out your perspective. Directly comparing the pros and cons of different programming styles is good terrain to be able to navigate as a software engineer.

I read the entire book, but I don't think everyone need to. I would suggest a casual reader go through the "Basic Styles" section that covers the monolithic, cookbook (functions modifying global state), pipeline (functional programming) and code golf styles. After that keep the book as a reference, and read up on Monads or the three styles of error handling when you're curious.

Links to further reading are included to foundational literature. I have a note from the monolithic chapter that I should read Dijkstra's paper "Go To statement considered harmful".

Here's an excerpt from the Code Golf chapter:

> trying to shorten programs for the sake of brevity is usually not a good idea. Often times, the result is a small program that is very hard to read and that may also have some serious performance issues.
Profile Image for Greg Williams.
224 reviews5 followers
June 23, 2018
This book takes a simple problem and solves it 33 different times, each time using a different "programming style". In this book, "programming style" is not about aesthetics. Instead, it is a way of organizing a solution based upon a set of constraints (what I think of as an "architectural style"). The "styles" are organized into "domains", e.g. function composition, object-oriented, metaprogramming, error handling, data-centric, concurrent, etc. As such, a typical software solution will use many of these styles simultaneously.

As an old software engineer, I think this book provides a great overview of different architectural styles in a way that makes it easy to understand. But I think that the use of Python as the programming language is both a strength and a weakness of this book. On one hand, the use of the same programming language across all the styles makes it easy to compare the different styles with each other. On the other hand, Python doesn't really lend itself well to some of the styles, which resulted in contorted code in some cases. For those cases, I really wish the author had included an example in a second programming language that could better illustrate the power of that particular style.

For me, I really enjoyed this book and would recommend it to any software person with an interest in software architecture.
Profile Image for Julian.
167 reviews
July 10, 2017
The premise of this book is brilliant, but the execution is flawed. It's still worth reading.

Before I read the book, I had qualms about all the exercises being in Python. As I started, I decided this was actually a great idea, because it should allow the stylistic ideas to shine through, removed from differing syntax. As I read on, however, I started to feel that Python was a poor semantic fit for many of the styles, many of the implementations felt forced, and it would be unclear to anyone not familiar with a given style why it even had merits.

A genuinely multi-paradigm language like Common Lisp or Oz might have been a better choice, but I get that doing it Python makes it accessible to a broad audience.

Beyond the language choice, I think it would have made sense to stray further from the original program in some of the paradigms, which the author does, but only in a few cases, near the end of the book. This would better motivate some of the choices. Some of this motivation is provided in the exercises, but I feel that's a poor substitute for being able to demonstrate these things in the main text.
105 reviews3 followers
April 10, 2019
I consider this to be a programming history book in disguise. Going through the chapters in order is like chronologically going through all of the advances made in programming in the last four decades or so. Python is an excellent choice for a programming language, I consider its readability to be its main strength (if you can write/read pseudocode then you can read this without any issues).

My favourite parts were the commentaries on system design, where the author tried to link the presented idea with a similar one (or identical) but on a systems level. Learning something about system design and the bigger picture is worth so much more than the nitty gritty details and quirks of a programming language. The references to articles are also an incredible source for those that want to dig even deeper.
174 reviews4 followers
March 31, 2023
This gives the reader a little bit exposure to many different styles of how code can be structured and how different parts of a system can interact.

It tackles one problem- the word frequency problem that Knuth used to illustrate "Literate Programming"- and solves it many times, all in Python but all in slightly different ways. In most cases there are about 5 one-liners that implement parts of the process, but the different examples show many ways of tying those parts together.

It reminds me a bit of "Thirteen ways of looking at a turtle" from the F# For Fun And Profit website. It also reminds me a little bit of the "Seven Languages [or other thing] In Seven Weeks" books, but taking a very different direction by illustrating styles in one consistent language.
249 reviews
February 14, 2019
A great book about different programming styles. Understanding why each of these should be used is a great learning opportunity. In a career of professional software development almost all of these will be encountered at some point. I love different perspectives on ways to approach similar problems especially with a book as well written as this that clearly explains the differences in data, results, and expectations. A great read that will help with writing cleaner code and tighter designs. Not to mention being able to understand code written by others in the past and future.
Profile Image for James Igoe.
99 reviews19 followers
August 18, 2017
An easily consumed, enjoyable read, and excellent review of the history of programming style, from older days of constrained memory and monolithic styles, through pipelining and object-oriented variants, to more recent patterns like model-view-controller (MVC), mapreduce, and representation state transfer (ReST). Along the way, each variant is described, along with its constraints, its history, and its context in systems design.
Profile Image for Alpha.
449 reviews10 followers
June 15, 2018
I think this would’ve been a much more interesting read several years ago for me, when I was far less experienced and knew much less about different programming languages/patterns. Even so, I think this would be a fantastic reference for getting re-familiarized with concepts presented in the book. I absolutely love how the author uses Python throughout the book as a reference sample for each new idea.

Would highly recommend for programmers that haven’t seen a lot of these styles before.
10 reviews
March 22, 2022
I really like the idea, but the reasoning behind the different paradigms and how to implement them are rather rushed and brief giving the impression it's a quantity over quality matter; sometimes the not showing the constraints implemented in the examples with the reasoning it is left for exercises felt lazy.

Overall not a bad book in any way, but it has a lot more potential and I hoped to learn more of it, on the plus side it has a lot of interesting references for further reading.
Profile Image for Juriy.
21 reviews9 followers
October 9, 2019
Amazing walk through the history of programming languages via 33 different ways to solve the same problem.

The only thing I'd love to see are examples of various paradigms in languages that natively/elegantly support those paradigms.

Still, a book that should be read by any aspiring PL junkie.
Profile Image for Henrik Warne.
309 reviews49 followers
April 1, 2018
“Exercises in Programming Style” shows different programming styles by solving the same problem in 33 different ways. The example problem used in all the examples is that of counting word occurrences in a text (term frequencies). The program reads all the words, normalizes them, removes short words (like the, a, in) and then prints out the 25 most common words in order.
All the programs are written in Python, but each program is written in a different style. Examples of styles are: only passing arguments via the stack, stringing function calls together, object oriented, actors, aspects, using an SQL database, and Map Reduce.
Each example is one or two pages of code, and is followed by a detailed explanation of how it works. This method of showing the styles works extremely well. First of all, the programs are short enough to completely understand, while still not being trivial. Second, you soon become so familiar via the problem solved (term frequencies) that you can easily concentrate on the differences between the styles. And finally, the descriptions of the styles are actual programs that can be run, instead of abstract hand-wavy descriptions, which I really appreciated.
I really enjoyed reading this book, and I learnt a lot. I think it is quite unique among programming books. At the same time it is relatively unknown, which is a shame. It is a great book that deserves to be better known.
I have written a longer review of it on my blog: https://henrikwarne.com/2018/03/13/ex...
Profile Image for Georgi Kolarov.
62 reviews1 follower
December 23, 2019
Много добър пълен обзор на стилове, прилагани почти винаги без да се замислим.
Макар да ме втриса от питон-ското безхаберие относно освобождаване на ресурси, както и да не съм съгласен с някои твърдения (като това че типовете са отживелица), тези негативи са пренебрежимо малко.
Книгата е особено ценна с малките на пръв поглед, но завършени и работещи примери, които водят към осмислянето и планирането на значително по-мащабни системи.
Displaying 1 - 15 of 15 reviews

Can't find what you're looking for?

Get help and learn more about the design.