Friday, October 31, 2008

Languages

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration."
Edsger W. Dijkstra (SIGPLAN Notices, Volume 17, Number 5)

If you think about it, and please do just that right now, then you'll probably notice that you use your native language to facilitate the thinking, at least to some extent. Taking this observation to the next step, how much does our native tongue influence our thought patterns, and how we perceive the world around us?

This is not a new question. There's even a theory in linguistics which studies this question, called the Sapir Wohrf hypothesis. In fact, George Orwell, in his classic book "1984", has a whole new dialect, "Newspeak", introduced by Big-Brother to aid in preventing "thoughtcrime". This imaginary language is unique in that it attempts to reduce its vocabulary, thus intending to limit thinking patterns.

A couple of years ago I heard a lecture (in hebrew) by Physicist turned Computer-Scientist, Prof. Naftali Tishbi, on some of the research he's conducted on languages and their affect on thought (and vice-versa). Since then, the subject has been sitting in some corner of my brain.

A couple of examples:
  1. When a procedure that I already know is coined, I can understand and use this procedure much more easily. For example, in Origami, the term "Double Rabbit Ear" allows my brain to much more easily choose an appropriate course of action, rather than just remembering some sequence of folds I've done before. In programming, that's exactly what Design Patterns do. I've used the Factory pattern before, but coining it made it more accessible cognitively, and it's now much more easy to notice when this pattern is appropriate.
  2. When attempting to solve a programming challenge, the choice of language affects the solution. This is taken to a very interesting extreme in LISP, where the first step to solving a problem is to create a new language tailored specifically for it.
There is no doubt that what programming languages a developer knows critically affect the quality of the solutions he'll be able to come up with. Until I learned Perl, I wrote simple text processing tools in C. The results were buggy programs which took too much time and thought to write.

But it is much deeper than this. A programming language affects how we even think about problems. Knowing several programming languages is important in developing our own minds and allows us to better think about problems. This is not new. Edsger W. Dijkstra already talked about this in his excellent 1972 lecture, "The Humble Programmer".

So, my resolution for the following year is to learn two new languages. While I think I know enough of Perl to get what I want done, I'm no expert in it, mainly because I don't like too many $ and too few letters. That's why I'm going to spend the next year studying Python. And I intend to really study it, inside-out.

I have a full-time job, a wife, some non-programming hobbies, an obligation to write a computer game, but I intend to follow through.

Funny comic from www.userfriendly.org, August 15, 1999

The other language I'll be learning is Japanese, by the way.

Saturday, October 11, 2008

Active Learning

"Reading, after a certain age, diverts the mind too much from its creative pursuits. Any man who reads too much and uses his own brain too little falls into lazy habits of thinking."
Albert Einstein

It's been several years since I realized I don't know anything. Occasionally, I make the mistake of thinking I know something pretty well. Reality always reminds me that I don't, usually using a sledgehammer. So I keep trying to learn. I read blogs and even (gasp) books. In fact, I even spent four years in what some people say is a pretty decent university. I even managed to surround myself with people who are way smarter than myself at work.

The thing is, you can only learn so much from other people. Consider Tom for example. He wants to learn a bit about thermodynamics and the heat conductivity of various substances, say, a human hand. It doesn't matter how much he reads Fermi's book, or even how much he hears lectures by distinguished professor Mom. In fact, said professor told Tom just last week that touching fire is dangerous, because fire is very hot. Now, Tom is a very intelligent boy for his age. His mother told him so, as a matter of fact. Yet, all of the theoretical knowledge he's learned won't stop him from trying to touch the flame with his hands. Only after such an experiment will Tom really understand that the heat conductivity of the human hand is, well, ehm. It hurts. That's what he'll finally learn.

My point being is that the only real way of learning something is by doing. That's why work is so much more tiring than a university lecture. In a lecture, you sit passively and listen. You can cover more material faster this way, but you don't really learn anything this way. Work has that annoying aspect wherein you actually have to work.

I'm not against reading books. I really love books. I am, after all, a nerd. Reading books is important. But it's not enough. You have to learn things the hard way.

So I'm going to write a game. I don't know too much about it yet, but that's what I'm going to write in the spare time that I don't have. A game is a good subject, because it covers nearly every imaginable aspect of Computer-Science and software development. I've already finished the dreaded Requirement gathering process. Here are the games requirements:

  1. It should be a game.
  2. I should finish it.
That's it. Now to start codi, em, I mean, designing. Yes, that's what I mean. Designing.

Sunday, September 21, 2008

If You Can't Test It, You Can't Program It

A well known axiom of business management is: "if you can't measure it, you can't manage it". I believe there is a software development corollary:

If You Can't Test It, You Can't Program It

At a first glance, this may seem stupid. You can program what ever you want to. But programming is about making the computer do what you want it to do. And computer have been scientifically proven to be bizarre, unpredictable creatures. They do what you tell them, and not what you think you told them. Unless you test, you can never know if you got your message to the damn computer.

And because source code is a dynamic, ever-changing being, you have to test and re-test and double re-test. That's why you need Unit Tests and Regression Tests. But that's for another post...

Tuesday, September 2, 2008

New Origami Diagrams


I have uploaded many of the diagrams for models by Yehuda Peled, diagrammed by him, which were hosted on the old Origami Tips website, and who had no internet location since that site went down.

You can find them in the diagrams section.

Monday, August 25, 2008

Programming by Coincidence

In their excellent book, The Pragmatic Programmer, Andrew Hunt and David Thomas have a section on "Programming by Coincidence". Although their book is jammed with useful tips, I think this is one of the most important ones.

Recently, I had a deadline for a large university project. Since my class partner and myself both have jobs, we really had to stretch ourselves to finish the project in time. This included a 30 hour sprint to finish the damn thing before the deadline. Programming in such conditions is always, shall we say, interesting. Despite the hour, I was actually able to catch myself programming by coincidence.

So what is Programming by Coincidence (PbC)? I'll try to explain.

It is well known that the best way to solve a maze (the ones you find in children magazines) is to start in the end, and work your way backwards. I've always favored a similar technique for solving logic problems - first you find the solution, and then you go back and understand why its the solution. This is not as silly as it sounds. Most logic problems can be solved using brute force by a 10 line computer program. But, as I've learned the hard way, this is the path to the dar, erm, programming-by-coincidence side.

So, a logic puzzle analogy to PbC is to start guessing solutions, and hope you stumble upon a correct solution to the puzzle at hand. The catch and downfall of logic-puzzle PbC practitioners is that, although a correct solution is found, no real understanding is gained. Even if, after finding a solution, one tries to understand the solution, all reasoning will be biased towards the known solution.

The flaw in my maze analogy is that solving a maze backwards is just a technique for finding the solution. The maze end is not the solution. The path is the solution. So there is no real correlation between the two.

In programming, PbC is similiar. It mainly involves guessing, finding a working solution, and then moving onwards to the next task. The problem is that the set of working programs is quite huge, but the set of good working programs is much, much smaller. If we don't truly understand what the problem is, why our solution works, then we're PbC.

And the danger of PbC is that things start to break down. Making changes in one place results in unit-tests failing in completely unrelated locations (you are using unit-tests, right?). This is a symptom of many software development problems (tight coupling, for example), but also of PbC. Many times, hacked together solutions work because of bugs in other people's code, or non-standard behaviour. When that changes, a once working solution a zillion lines of code away stops working.

If, instead of taking the trial and error path to finding a solution, we were to take a step back, look at the big picture, understand how everything fits together, and then think of a correct solution, then we wouldn't have such problems.

And I must confess that after 25 hours of coding, I knew I was PbC, but I kept at it, frustrated as I was. Lukily for me, my project partner is more experienced, and he had the sense to call a full stop, until we really understood the problem, and only then did we start looking for a solution.