Date archives "June 2015"

New design

Hi all,

I updated the blog with a new design. The old one was just the default wordpress theme, and I thought it would be nice to have something a little bit more custom. I personally like big fonts when reading blogs, so that’s what I went for. If you have any feedback, please let me know 🙂

Cheers,

-Freek

Using syntax highlighting to improve the readability of your tests

One thing I obsessively focus on is test readability. The reason being that it’s often very hard to understand what a test is really about; usually the signal-to-noise ratio in tests is very low, and that makes it hard to understand what is being tested. So I continuously try to improve the readability of my tests by experimenting with different styles. Yesterday I was working with my colleague Sander, and we discovered yet another trick that I think can help: syntax highlighting.

Consider this piece of code:
nohighlighting
It tests for certain SEO properties (the contents of the robots meta tag in the HTML) based on the current status of the specific page.

Now, I think these tests already have a relatively high signal-to-noise ratio. The thing is at a pretty high level of abstraction, and you can probably follow what’s going on as non-technical person. It is, however, less clear what the difference are between these two tests. In fact, only 8 characters are different, out of a total 312 characters. It’s really hard to spot what those differences are when you start reading this code.

Now consider this form:

withhighlighting

While the number of changed characters is exactly the same, I think both the original intent and the differences between the tests are way more clear. When I get back to this code, my eyes will immediately be drawn to the strings, which happen to also capture the essence of the tests, which is what we’re after.

Book thoughts: Hackers and Painters

Hackers_&_PaintersI finished reading Hackers and Painters: Big ideas from the Computer Age by Paul Graham the other day. This book was suggested to me by Henk Jan Pluim (very nice guy), and I really enjoyed reading it. It’s nice short book, with very strong opinions about pretty much anything, including politics, popularity, economics, statistics and, of course, programming.

For me, one of the most interesting parts of the book is that the author asserts that one of the key competitive advantages when running Viaweb was that they were programming in Lisp. He goes even further, by stating that “Lisp is the most powerful language available”.  The argument goes that it’s a fact that some languages are more powerful than others (due to the fact that they vary in abstractness: c is more powerful than asm), but you can only see that another language is less powerful when you actually know the more powerful language. At the top of the chain is Lisp, since apparently its macros let you do things that are extremely powerful, yet not any other language contains a feature that is at all comparable.

Now I’m not entirely sure if that reasoning is entirely sound: the whole point of language wars is comparing your language to another language and arguing the other language is less powerful due to it missing certain features. I currently take the position that in business (web) apps, you can probably solve similar problems in the same amount of effort and with the same amount of elegance in C#/F#/Ruby/Python/Scala/PHP/Java/Go/Clojure or any of the other currently popular high level languages for that kind of work. Nonetheless, I don’t want to dismiss the idea that there can be unknown unknowns that might significantly shift my thinking. Maybe Lisp-style macros is one of them, so I’ll definitely put in some effort to learn more about them.

Exploring the essence of object-oriented programming

Warning: no actual answers are given in this post 🙂

For a long time I’ve been fascinated what object-oriented programming is really all about. I’ve never talked to someone who could give me a closed definition, or could even give me the reasons why OOP is a good (or bad) idea. Lately I’ve been doing quite a lot of research, which led me to things as The early history of Smalltak, Smalltalk itself, a lot of work from Alan Kay, the Viewpoints Research Institute, Lisp, COLAs, Meta II and a lot more stuff. Very interesting, I can tell you, but while I learned a lot, I still don’t have the answers. Nevertheless, I thought it would be time to write down my results/thoughts so far.

For a lot of people, OOP is mostly about classes, inheritance, polymorphism and modelling nouns from the real world. When you go back in history, however, you’ll find that the term object-oriented programming was first used by Alan Kay, and he doesn’t seem to mean the aforementioned things at all. Instead, he says the most important idea about OOP is messaging, and that the term OOP was actually not that well chosen since it puts the focus on objects instead. He also says:

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things.

I’m specifically interested in this “definition”. Why? If a visionary like Alan Kay finds this important, it probably is. And I like to know important stuff 🙂 So what do these 3 things mean, what problems do they solve and how does OOP relate to them. Spoiler: I don’t have (all) the answers yet. Let’s visit these three concepts, and how I understand them at the moment.

Messaging. Communication between objects is done through messaging only. Each object decides how to interpret and act on a message themselves. Objects need to decide how messaging works up front.

Local retention and protection and hiding of state-process. An object has private memory which no other object can access. If another objects wants access to some of the data of an object, this needs to happen through a message. An object itself is in control of actually granting that request.

Extreme late-binding of all the things. This is the one I have the most trouble with grasping the consequences. The idea is to bind everything to concrete stuff as late as possible. For example: compiling to bytecode binds your code to a particular machine later than compiling directly to machine code. The main idea here is that you can delay important choices until you have better understanding. In C# a lot of decisions are already made for you (everything is an object, no multiple inheritance, etc) and we bind early to those decisions since there is no way to change them later. If we later find out multiple-inheritance would help in some part of our code, we have no way to do that. The same goes for selecting which method is gonna interpret a message, in C# this is determined compile time which forces you to do all kinds of weird stuff should you actually want to do that runtime.

From a software development point of view, I’ve seen all three things being helpful in one context or another: it feels logical that combining them indeed yields a very powerful programming model. Why Alan Kay thinks these 3 specifically are that important, however, I’m still not sure. At one point, he talks about Real Computers All The Way Down (RCATWD), meaning that every object can represent anything. That’s powerful, and I currently think it’s related to that, but I’m not exactly sure in what way yet.

One thing I noticed on reviewing this post is that at no point I’m talking about programming languages. That’s probably not coincidental, in the sense that OOP is not tied to any particular language; you can actually do OOP in a non-OOP language, and you can program in a non-OO style in OO languages.

So what is OOP? It seems safe to say that fundamental elements of this programming style are at least objects and messages, where objects communicate with each other through the messages. Objects have a private memory to store the data they need to carry out their computation. And that’s where things get messy: does everything need to be an object? If it is, how do you actually represent data (something like church numerals?)? If it’s not, where do you draw the line? Does it really matter, or is it fine to do just parts of your system OOP? How does functional relate to OOP?

All kind of questions I don’t really have an answer to at the moment, but I’ll get back to you if I find out..