Monthly Archives: October 2010

Project SICP

SICP book cover

Structure and Interpretation of Computer Programs” is by far the greatest programming book I have ever read. The majority of other programming books don’t teach you about the big ideas in programming or about managing complexity in large software systems. These books spend most of the time teaching you about the peculiarities of the syntax of a particular programming language. And when they do go beyond that the problems they tackle are so fucking mundane and mind numbing. It’s no wonder a majority of the people who program don’t see the beauty in it.

What’s so awesome about this book?

Well firstly, it uses Scheme as the programming language for discussing the various ideas. It never really teaches Scheme because there isn’t much syntactic complexity to the language, you just learn it as you progress through the book. This is great because it means that Scheme doesn’t get in your way when the big ideas are being taught. And mind you this book is all about the big ideas. Take chess as an example. Anyone can be taught in 5 minutes (if so much) the rules of chess and how each of the individual pieces move on the board. But the complexity of chess comes from the interaction of the pieces and the various ways in which the moves can be combined. So to become a master of chess you don’t spend your time studying the rules, you spend your time studying tactics, strategies, openings and end game scenarios. These are the big picture ideas in chess. Similarly, anyone can be taught in 1 hour (if so much) the rules of Scheme and how most of its primitive constructs and special forms work. But the complexity of Scheme comes from the means it provides for forming combinations and making abstractions. So to become a master programmer (not Scheme programmer but programmer in general) it is clear to see that we should spend most of our time understanding how to combine elements (procedures and data) to form compound elements and more importantly understanding techniques for abstraction which allow us to control complexity in both small and large software systems. SICP devotes each printed page to get this knowledge across and because of this the complexity of the programs you begin studying from the start are orders of magnitude more interesting and intellectually enriching.

Secondly, the book is well written and the authors don’t treat you like a “Dummy” or an “Idiot”. This book expands your mind and changes the way you think about programming. They are not afraid to tackle complex issues. Maybe you won’t understand all of the ideas in a 1st, 2nd or 3rd reading but because you’ve been exposed to it your mind is forever changed. They also assume you are willing to spend some time digesting and understanding this material. Its not a become a master programmer in 21 days type of book. Who the fuck can master anything in 21 days?

Anyway here are some of the topics covered in the book: functional programming, object oriented programming, logic programming, programming with constraints, lazy programming, nondeterministic computing, interpreters and compilers, data-directed programming.

And here are some of the interesting algorithms, data structures and programs that are used as examples: algorithms for numerical computing, interval arithmetic, a picture manipulation language, symbolic differentiation, stacks, queues, sets, trees, symbolic algebra, a simulator for digital circuits, a scheme interpreter, an interpreter with lazy evaluation, an interpreter for nondeterministic computing, an interpreter for logic programming, a scheme compiler.

Seems like a lot but its what any good book on programming should be about.

Now onto the reason I started this post.

Project SICP is my attempt to program solutions to every problem in the book. I have already completed a vast majority of them but I want to organize them in a structured way and solve the remaining ones. And yes. I am completely aware of the successful attempts made by other people (for example: Eli Bendersky) to do exactly this but I learn by doing, not by seeing how other people did it.

Check out my SICP repository on github if you want to view my solutions to these problems.

A ray tracer in Racket

Racket is a very cool programming language based on the scheme/lisp family of languages. For the past couple of months I’ve been having lots of fun implementing and re-implementing various programs in Racket. My latest project is a ray tracer. A ray tracer is a program for generating realistic images. The code I’m writing for the ray tracer is based on C++ code taken from the book “Realistic Ray Tracing (2nd edition) by Peter Shirley and R. Keith Morley“. I’m now on the first section of the third chapter which is the part where they show you how to implement a single sample ray tracer with an orthographic camera. Its just beautiful to see how nicely the ideas in the book seamlessly translate into readable Racket code.

By the way, I plan to put the source code for this project up on github. So keep checking there for the code if you’re interested.

In the mean time, here’s my first image ever generated by the program:

And, yes I know its not looking realistic but that will change as I add more features.

Update: I added the repository to github. Check it out at http://github.com/dwayne/rt.

Follow

Get every new post delivered to your Inbox.