What is the halting problem?

Consider the following situation:

There is a delicious cake. Chuck Norris* must jump up and down until the cake is not delicious anymore.

Will Chuck Norris ever stop jumping? Let’s look at a few scenarios:

  1. The cake is outdoors. It gets rained on and becomes soggy, therefore it is not delicious anymore. Chuck Norris stops jumping.
  2. Chuck Norris realizes how stupid this situation is and stops jumping of his own accord because Chuck Norris does what he wants.
  3. The cake stays delicious forever. Chuck Norris is compliant and continues to jump for all eternity.

We only looked at three scenarios, but there are an infinite amount of things that can happen. As you can see, whether or not Chuck Norris stops jumping relies on a number of different factors. The only way for him to keep jumping forever is if he remains compliant and the cake never stops being delicious. Even though this seems to be a simple situation, it’s actually very complex because there are millions of factors in the world that could make the cake not be delicious anymore. Or Chuck Norris could decide not to comply, causing an error.

So let’s revisit the question: Will Chuck Norris ever stop jumping? The only way to find out is to watch and see for yourself. There’s no way to tell ahead of time whether he’ll ever stop. If you watch him for 51 hours and he continues to jump, can you tell if he will ever stop in the future? No, you can’t.

Translate this situation into a computer program, and our question is a variation of the halting problemGiven a description of an arbitrary computer program, decide whether the program finishes running or continues to run forever.

This problem is significant because it cannot be solved. There are many programs where, when given a description of the program, there is no way to determine whether it will ever stop or whether it will run forever. The Chuck Norris/cake example is one such program. Given that situation, you can’t always tell ahead of time whether his jumping will ever cease.

* Chuck Norris was used in this example because he does not need to eat or sleep, and he has enough willpower to not immediately eat the cake.

Like this post? Follow me @seangransee or check out my personal blog.

What is Git? What is revision/version control?

You and your team of oompa loompas are on a mission to create the greatest cake the world has ever tasted. You all have your own specialty. Stroompa is an expert at creating sweet, delicious strawberry toppings. Boompa ain’t messing around when it comes to cake batter. And choompa? Well, let’s just say that chocolate is kinda his thing.

Everyone starts off getting their own boring cake, and they all go off separately to work on their respective parts. They all create something that tastes amazing all by itself. Then, they come together to combine their parts into one cohesive cake. You taste it, and you’re underwhelmed. Turns out, everyone made amazing ingredients, but they didn’t blend well together. The chocolate and the strawberries didn’t balance each other out. The inside wasn’t moist enough to work well with the rest of the cake. Wouldn’t it have been better if everyone worked on the same cake, iterating with each other until they had something that even Chuck Norris couldn’t resist?

Now let’s look at another scenario…

Same deal as before. Your team of oompa loompas is creating the world’s greatest cake. This time you start with a magical box that contains a basic cake. When you take the cake out of the box, the cake actually duplicates (just go with it…) and you’re really taking out an exact copy of the cake. When you put a cake into the box, the cake that was already in there combines with the changes you’ve made to the cake.

Everyone works on their respective part of the cake again. But this time, whenever anyone feels satisfied with his progress, he puts his cake in the magical box and takes out a new one. This time around, everyone always has a cake that includes the best of everyone’s work, so they can work together to make the ingredients combine into cakey goodness.

Let’s put this into technical terms…

Your individual copy of the cake is your local repository. The magical box is called the remote repository. When you put the cake into the box, you push it to the box. When you remove the cake that has everyone’s combined changes, you pull it.

When you’re working with other developers on a software project using Git, you always have a copy of the code on your own computer. When you’ve made changes that you feel satisfied with, you commit them, which is basically saying that you want those changes to go into your local repository. When you want the others to be able to use your code, you push your local repository to the remote repository, which the other developers can then pull from. Now, everyone always has an up-to-date copy of everyone else’s code, so it’s much easier to make all the moving parts work together into one cohesive whole.

Who can give me access to that remote cake repository?

Like this post? Follow me @seangransee or check out my personal blog.

What is a linked list?

Your city has just begun its annual Cake Tour Extravaganza. As a die-hard cake lover, you couldn’t be more excited for today.

The concept is simple. You can walk into any participating bakery in the city and try some cake. Afterwards, the bakery directs you to the location of another bakery. You can keep following this chain until you get to the end, and hope you don’t get diabetes along the way.

The city doesn’t release the names or locations of any participating bakeries except for one. If you want to go on this cake tour and you don’t have inside information about the participating bakeries, you need to start at the beginning and follow the chain until you’re satisfied.

Let’s put this into technical terms…

A linked list is essentially just a location in the computer’s memory, just like the location of the first bakery. At this location, you have the first item in the list. Right next to it, you have a pointer to the location of the second item. When you follow this pointer you arrive at the second item, and right next to it there is a pointer to the third item. At the very end of the list there is a terminator, which tells the computer that it has reached the end of the list. Fortunately, a computer can move to another location much faster than you can move to another bakery.

Why not just use an array?

That’s a good question. With an array, you can instantly jump to any point in the list. You don’t need to start at the beginning and go through them all, so isn’t that better? Depends on the situation. In an array, all the items are right next to each other in the computer’s memory. That would be like putting 30 bakeries right next to each other on one city block. It’s possible if there is a large vacant piece of real estate, but it’s not always guaranteed that this will be the case. Also, what if you want to put a new bakery in the middle? When they’re all adjacent with each other, you can’t stick a new bakery in the middle. But with the first example, you can instruct the bakery owners to direct customers to a different location if a new bakery joins the party.

Now go out and eat some cake! Did I mention that it’s free today?

Like this post? Follow me @seangransee or check out my personal blog.

What are APIs and why are they important?

You like cake, right? Of course you do. But you’re not good at making cake.

Your friend (let’s call him the cakemaster) teaches you how to bake the perfect cake. You learn which store to go to, which shelf each ingredient is on, and how to follow the recipe. You now know how to bake the perfect cake.

You start baking yourself a yummy cake every week. One day your friend, the cakemaster, gets eaten by lions. Doesn’t matter though, because your cake is so damn delicious that nothing can bother you. You continue to bake yourself a cake every week for the next few months.

Then one day the store closes. Oh shit! The cakemaster isn’t around to teach you how to bake a cake with ingredients from another store. You can’t make cake any more, and your existence is meaningless.

Now let’s look at another scenario…

You like cake, and your friend is very good at making cake. Every week you ask him for a cake, and he delivers.

Then one day, the store closes down. Not a problem, because your friend is so good at making cake that he can adapt. So he goes to a new store, uses a different recipe with different ingredients, and gives you the same delicious cake.

However, you have no idea that any of this is going on. You just know that every time you ask your friend for a cake, he gives you a cake. You don’t need to know anything about the process of baking a cake, you just need to ask for cake to receive cake.

Let’s put this into technical terms…

You are the user-facing interface for an application. Your friend is the API. The store is the database.

If you’re a mobile app, your code is on a device until a user manually updates you. You can’t simply change on the fly. That’s why you need to be able to just make a request (“I want cake!”) and receive a response (a delicious cake) without any knowledge of how the process works. Databases can change shape, process can be rewritten, and the user-facing part of the app continues to run smoothly.

Even if your code can change on the fly, it’s much easier for a frontend developer to make something happen when he needs no knowledge about how the backend works.

If you want outside developers to be able to integrate your service (think Facebook, Twitter, Instagram, etc.) into theirs, they can safely do so by using your API without needing direct access to your database or any of the inner workings of your system.

And that’s why good APIs are important.

Like this post? Follow me @seangransee or check out my personal blog.