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.

Thursday, August 21, 2008

Origami Diagrams and Crease Patterns

These are some of the old diagrams from the old Origami Tips website:

Ninja - intermediate
Peacock (cp) - intermediate

Models designed and diagrammed by Yehuda Peled
Bee Orchid
Stem for Daffodil
Long Neck Bird
Orchis Anatloica
Pentagon from A4
Pentagon from Square
Stem and Leaves
Tripod Stem

Sunday, August 10, 2008

Origami Tip - Folding a Double Rabbit Ear

This article is part of the Origami Tips series.

I've had trouble with double rabbit ears for a long time, until I realized their secret. The secret to a double rabbit ear fold is:

Double Rabbit Ear = Petal Fold

Yes, a petal fold, as in the crane. Here are some pictures to demonstrate:
  1. We start with a square folded in half along the diagonal twice to get simulate a flap. We begin the double rabbit ear fold by performing an inside-reverse fold.
  2. The result of the inside reverse fold. The trick is to now look at the model at a 90 degree angle, as shown in the picture.
  3. And this is the secret - perform a petal fold!
  4. The petal fold complete. Now we just fold in half to close the model.
  5. The finished Double Rabbit Ear fold!

Saturday, August 9, 2008

Folding From Crease Patterns

This article is part of the Origami Tips series.

It was originally published on April 2004. Other than formatting, it appears as the original, which can downloaded here.

Folding from Crease Patterns
by Gilad Naor

Very little written information exists on the subject of folding origami models from their crease-patterns. Due to the fact that this is a very interesting subject, I had reached the conclusion that something had to be done about it. And so I waited, and waited, and yet the situation did not improve. Seeing that none of the masters were writing anything on the subject, I decided to write what I myself learned from my very modest experiences in this field.

It is important for me to note that this is not a tutorial written by an origami master, but by an average origami enthusiast who is struggling to learn how to fold from CP, and is just sharing his experiences. Mistakes and bad advice may very well lurk inside this document. If anyone has better ideas I would be strongly welcome receiving them for future version of this document.

Please note that this document includes various thought I have on this subject which do not directly aid in explaining how to fold CP. I do, however, find them interesting, so I included them in the document. If you don't like it, then feel free to write your own document.

1. What is a Crease Pattern?
I once heard a story about how someone was introduced to origami. His friend presented him with a square sheet of origami paper, and asked him what he saw. That person, slightly puzzled, answered that he saw a piece of paper. His friend then told him that he was wrong, and that it was in fact a duck! He then folded the paper, and indeed, there it was – a duck!

One of the things I like most about origami is that it shows that in a simple, square piece of paper, much like the Torah, all of creation already exists. In this sense both the simple crane and the super-complex insect are, in essence, a square, and therefore the same. In origami, we do not create something new, we simply manipulate an existing shape into a different one, and yet remains the same thing. We can always return it to its origin. It is always its origin.

And like most great theories, this ideal concept is also hampered by a little thing called reality. In reality, unfolding a model back to the square will not give as the original square back. We will get, instead, a square scarred by the manipulation we made. These marks are called creases, and every model creates a pattern of creases which is almost unique.

One of the methods of sharing a new origami creation is by distributing the model's crease-pattern. A person who receives a crease-pattern can then re-create those creases himself and refold the model. Recreating the model from its crease-pattern is not an easy task, however. It is very time consuming, boring, frustrating, and not many people do it. The more common method for distributing instruction for an origami model is by writing diagrams. Diagrams show exactly what needs to be done in steps for the creation of the model. In other words, they include the fourth dimension – time. They explain which creases need to be made when.

There are benefits and drawbacks to each method. I have listed a few:

Diagram Benefits:

  1. East to recreate the model
Diagram Drawbacks:
  1. It takes a lot of work for the designer to create the diagrams. It's also a very boring task.
  2. You introduce unnecessary creases which may spoil the model's appearance.
  3. It is much harder to understand the model's “structure”, and how it was invented.
Crease-Pattern Benefits:
  1. Much easier for the designer to create a CP.
  2. The final model is much cleaner because no unnecessary creases are made and there is a smaller error in folding.
  3. After “deciphering” the CP, it takes much less time to fold the model afterwards
  4. It is easier to memorize the folding sequence by heart because you remember the "structure” of the model.
Crease-Pattern Drawbacks:
  1. It takes a long, frustrating, time to “decipher” the CP.
  2. Not all CP include the same amount of information about the model.

And now, after blabbering so much, it's time to learn how to fold from a crease pattern!

Well, actually, not just yet. First we have to understand...

2. The difficulties of the CP
It has already been hinted that before actually folding from the crease-pattern, there exists a preliminary stage of deciphering it, and this deciphering process includes several steps. Different authors create their CP differently and some stages may be skipped in some CP. It all depends on how much information is encoded into the CP. Almost all of the difficulties when dealing with CP comes from the incomplete information they give us. I will now list these difficulties, but you should keep in mind that they are not always relevant, depending on how descriptive the CP is.

A CP describes only the creases actually used to fold the model (creases are missing).
If you look at diagrams for intermediate or higher level models, you'll notice that in many cases the first several steps are used to locate some starting point inside the square, and that the following stages use that point as a guideline. These very first steps will usually include text telling you not to make the creases sharp. The reason is that they are only used to find that starting point and are not part of the model's CP. Therefore, the CP will not include these very first steps for finding the reference point.
There are other creases left out from the CP, but this example is the most common and very similar to all the other cases.

A CP does not describe which direction the creases go.
Every crease goes in one of two ways – either down (mountain) or up (valley). Many CP show both of these creases in the same way. This is because the standard way of marking mountain (slash – dot – dot) and valley (slash – slash) creases would make the CP unclear. It is much clearer to mark the creases with straight lines.

A CP does not tell you in which order to fold the creases.
As already said, the major advantage of the diagram over the CP is that it adds the fourth dimension – time. Knowing where all the creases are and in which direction they go is not a lot of help, because some creases have to be made before others.

The CP does not describe the model, but only the model's base.
Without getting into too lengthy a discussion about origami bases, I will simply state that a base is an origami “model” which has all the flaps needed to create the “real” model. A base will usually have no or little resemblance to the finished model other than that it has all the materials” for it. For example, the base for the classic crane is a famous base called the “bird” base. To continue with this example, the CP for the classic crane will be the CP for the bird base. If we were to try and fold the classic crane from a CP, we'd only get as far as a bird base. To finish the crane, we'd need more information which does not exist in the CP. This extra piece of information comes in the form of a picture of the finished model. With a picture of a crane, we can now turn our bird-base into the finished model.

The reason crease patterns only include information up to the base, and not the finished model is that the finishing folds usually create so many creases that it would be impossible to see anything in the CP had they been included. In the case of the crane, it is logical to include ALL the creases for the entire model, and not just the base. But it would also be logical, in such a case, to just write diagrams, because it's such a short model. Most CP describe complex models for which writing a full diagram would be too time-consuming, and since they are complex, there's only room to describe the model's base. A picture of the finished model is therefore essential.

And now, finally, it's time to start talking about how to decipher and fold the damn crease-pattern.

3. The deciphering process
I will divide this section in two. The first part will go over the difficulties presented in the previous section and explain how to overcome them. The second part will include some general tips I've found to be very helpful, but do not directly help to overcome a particular difficulty.

A CP describes only the creases actually used to fold the model (Creases are missing).
Many crease patterns include information about the starting reference point:

- Sometimes you will be given folding instructions beside the CP itself on how to reach the starting point. A famous example is Satoshi Kamiya's Ancient Dragon. In such a case you don't have to do anything else.

- In other cases, the edges along the square will have numbers which state the relations between the various “sections” of the CP. For example, if there are two major sections along the edge, and one is marked with the number 2, and the other with the number 3, then you know that the paper is divided into 5 (2+3) imaginary units, and the first section is 2 “units” long and the second one is 3 “units” long. Knowing this, we can now find the reference point using either folding (dividing the paper into fifth, for example), or you can use a less pure method and measure it with a ruler and a calculator.

- And in a great many cases, no information is given at all. In such cases, the best approach is to start with trial-and-error. Just fold, divide angles, connect lines, until you get to the reference point. You can do this by printing/photocopying the CP and folding along it. With time and practice, you will develop a larger “bank” of how to reach various reference-points, and you will be able to intuitively find reference points. Another method is to use a computer program, such as Robert Lang's aptly named “Reference Finder”. You will need to calculate the point's location in relation to the square (as an XY grid), and feed that into the program which will give you a folding sequence to find the point.

- And a last and very “impure” method, is to print the CP and just fold it. In this way you will not have to struggle to find out how to reach the various creases, but you will not learn how to fold it from any piece of paper.

In any case, after finding the reference point (if there even is one) we need to start making all the creases on the paper. After doing this, our paper should have at least all of the creases marked on the crease pattern. Do not be afraid of making extra creases during this stage, because, as noted, the CP does not have all the creases marked. If you get confused, you can mark the creases which will ultimately make the CP with a pencil, at least during the first try.

A CP does not describe which direction the creases go.
Some CP have different line styles to mark mountain and valley folds, but most don't. I will not explain how to find which creases are valley and which mountain for two reasons. The first is that Ben Ball's excellent CP tutorial already goes into some depth on this, and the other is that I have found that it is not very important. In most cases, while collapsing the model, you will have to reverse the direction of various creases several times, so that where they lie in the end is not really important for finding out how to collapse it. It is certainly very helpful to know where they will lie in the end, because it helps to understand the model's structures, but it is not essential. I find that it is usually rather straightforward. I suggest you mark all the creases as both valley and mountain, and try to collapse the model. Again, in time a “bank” of mini crease-patterns will be built in your head, and it will become easier.

A CP does not tell you in which order to fold the creases.
After all the creases are in place and you have marked them all as both valley and mountain, it's time to actually fold the model. You should note that you have not yet fully “deciphered” the CP, but this is almost the final stage of the deciphering. In most cases this will be the hardest part. I cannot give a straightforward course of action for collapsing all CP but I can give a couple of tips.

1. Just do it. If you won't try, you won't succeed. With experience it gets easier, but you have to start somewhere.

2. And keep on doing it. You probably won't succeed in the first, second, third, or tenth try. But don't give up. Keep on doing it. I find it's easier if you watch TV while doing it (though I certainly don't encourage anyone to waste their lives watching TV). You will eventually make it.

3. And if you don't eventually make it, I strongly suggest working on different parts of the CP separately. When I tried collapsing the Ancient Dragon and failed, I moved to collapsing only the head. I cut a new sheet in the shape of the creases forming the head (not a square), put the creases in, and then tried to collapse it. After succeeding here, I then returned to the whole model. Working from the head which I already knew, I was able to eventually collapse the whole model (though this did not happen at once and took several tries).

In any case, this stage can be the most depressing, because you can really have no idea what to do. I suggest you don't give up and keep on trying. If you're stuck on it for a week, ask for a few pointers on the O-List.

The CP does not describe the model, but only the model's base.
As already pointed before, having a picture of the finished model is essential. Using the picture, try to identify which part of the paper becomes which part of the finished model. Many CP already give you this information, but if not it is usually not too difficult to figure out. Just look at the picture and at the base you've collapsed, and try to see what remains. This stage is usually either very easy or very difficult.

General Tips
1. Just do it. I've been afraid of CP for a long time because there was no good written tutorial on how to fold them. And even if there were a thousand written tutorials on the subject I would probably have still been afraid of them. The fact remains, that the only way to truly learn anything in this world is by doing. Reading and listening to other people is a method for expanding your own personal experience pool, but there is always a big difference between our own experiences and those we've learnt from others. A little child will not understand that fire is hot until he puts his hand in the flame, no matter how much he is taught that that is the case. Likewise in crease patterns. The only real way to learn them is by jumping into the water and trying it. I cannot express this point strongly enough.

2. Use a sheet that is very easy to work with. Kami or printer paper (preferably 40 g/m2) are both pretty good. After you understand how to fold and collapse the model, you can move to a more demanding (and rewarding) material.

3. Putting all the creases in place is one of the most boring things you'll even get to do in origami, and in life in general. And since you're bored, time moves slower (in relation to how you perceive it), and you therefore live more during this time in relation to others. This way, you actually live longer. Make sure you appreciate it!

4. Don't be afraid to make extra creases. When “deciphering” the model, I like to mark the “real” creases with a pencil so I don't get confused during the collapsing.

5. Try to break the CP down to pieces. The CP will usually be separated in one of two ways – it will either be several pieces attached to each other, or inside each other. In the first case, each part will usually belong to a different part of the finished model, and you can usually practice collapsing each part separately. In the second case it will usually be a blintzed base. A blitzed base is a base that is turned around 45 degrees, an so allowing for more paper in the corners. In such a case you can try to start by collapsing the innermost part, and then move outwards.

6. Try to recognize mirror creases. Such a crease pattern usually means that these creases go one over the other.

7. Just do it. The more you do it the easier it will become. You'll be able to draw upon your experience and recognize the patterns. Even a journey of a thousand miles must start with a single step (or fold).

4. Conclusions
Folding origami models is really quite boring and usually frustrating. It is also very gratifying when you succeed. An added bonus is that you also learn a lot about the model and how it's built. I strongly recommend that you try it. I myself am only just trying it. But the key is to try.

5. References
1. The O-List:
2. Ben Ball's Origami Page -
3. Ancient Dragon / Satoshi Kamiya – Tanteidan Magazine #55

Origami Tip - Folding a Closed Sink

This article is part of the Origami Tips series.

A closed sink is one of the more dreaded folding sequences in Origami. Here is an explanation of how to fold a closed sink in two ways. The first is a general way, and the second is a more elegant method applicable only when you can unfold the model sufficiently.

First Method
In the pictures, I give an example of close sinking a petal fold in half. The text attempts to be more general.
  1. The first step to performing a closed-sink is to firmly crease the fold line. If the paper allows it, fold the crease in both directions.
  2. If you can, try and look inside the model. Look at the inside, and identify the existing creases. What separates a closed-sink from an open one, is that these existing folds remain locked in place. In our example, the marked fold must remain in place. So place a finger as marked on the inside, and hold tightly.

  3. Now, looking again from the outside, start pushing the corner inside. The key to this part is to use violence. We'll worry later on straightening things out, so don't worry if things get a bit crumpled right now. Use force!

  4. Continue pushing inwards, and then start straightening along the crease lines from step 1.
  5. Now, if you can, look once more on the inside. This is your chance to straighten everything out and make sure everything is flat exactly along the crease lines.
  6. Close everything back. You have completed the closed-sink fold!

Second Method
This method is better than the previous method, but it requires a bit of thought and intuition, and, more importantly, the ability to unfold much of the model. The idea of this method is to understand how everything needs to fold into place. This is different for various folds, so below is a step-by-step example of folding a close-sink on the tip of a preliminary base.
  1. We start by marking the crease we want to sink on, and then unfold as much as possible.
  2. If we understand the crease-pattern of the closed sink, we can understand which folds need to be made. In this example, we start by mountain folding along the diagonal. In an open sink, this line would have been a valley fold. For a closed sink, it's a mountain.
  3. We next fold the diagonal line together, by folding inside the internal square. This is the key to the closed-sink, in that it locks the layers together.
  4. And finally, we close everything up to get the closed sink.

Origami Tips

In this page I'll post various tips, some revived from the old Origami Tips website, some new.

Common Folding Sequences

Specific Models

Crease Patterns

General Tips

  • Tissue-Foil - how to make and when to avoid

Wednesday, August 6, 2008

Creativity and Constraints

This post has moved! Please click here and update your bookmarks.

Although my university obligations are enormous at the moment, I find myself drawn back into the Origami world. Thus, I came across this month's challenge on the Origami Forum - fold something cute. This brought me back to a subject I've given quite a lot of thought to over the last few months - the importance of constraints to creativity.

This a fact that I keep bumping into, and I'll give a few examples.

1. At work, we've had to decrease the memory consumption of our product by an order of magnitude. This resulted in some very creative solutions by the team, which I think will also result in a better product overall.

2. Parkinson's law states that no matter how much time you allocate for a given task, then that's how much time that task will take to complete. This means that what could have been accomplished in a week can take a month, without necessarily any added value introduced.

3. The limitations posed by Origami on the designer forces one to think on what exactly defines the subject. I've seen too many cats and horses which end up looking like dogs. So think about it - what is it that makes a cat, well, a cat? For example, I made a human model several years back, and it turns out it's an Elvis. Because of the hair, you see?

4. There's a phenomenon here in Israel, which I suspect happens elsewhere in the western world, where parents attempt to give their children everything they didn't have growing up. This has many downsides. Children growing up without having to work hard in order to succeed will have a hard time coping with the real world, where nothing is given for free. That's why we see so many people still living with their parents well after the age of 18, or not working, or spending more than they earn, or many other things. Count me guilty!

I think I could talk about the last example quite a bit more, and I've obviously made a lot of simplifications and generalizations, but I hope you get the idea - boundaries, limits and constraints are good.

I'm sure I'll write more about it, but right now I have to think what exactly defines "cute".

Monday, August 4, 2008


Jeff Atwood wrote a very interesting blog post where he postulated that quantity is more important than quantity. From my point of view, this is an interesting extension of the fact that the only way to learn is by doing. Especially if this means making mistakes.

In a prior post, Jeff wrote that the same holds for blogging, and that one should make a commitment to uphold a schedule. Therefore, I will now declare that:

I will post at least one post every week

And no, this post doesn't count.