fbpx

So far our game doesn’t do much and we’re going to fix that. The most important thing for you to realize is that when you’re programming, you’re not going to write your final code at the very beginning. I know, I’ve said this before, but I don’t think I can say this enough. Programming is a journey.

The main message in this episode is how you can skip over many details when programming and focus first on the bigger picture. Then you can elaborate a bit more on some other part. You don’t have to do any of this in order. So even though programming is a journey, it’s unlike any journey in the physical world. It’s extremely powerful and allows you to try things without fully committing to complete them.

Listen to the full episode or read the full transcript below.

Transcript

So far our game doesn’t do much and we’re going to fix that. The most important thing for you to realize is that when you’re programming, you’re not going to write your final code at the very beginning. I know, I’ve said this before, but I don’t think I can say this enough. Programming is a journey.

The next step of this journey is to change the winning message only when a word is guessed correctly. But isn’t that the whole point of the game? It is, yes, but we don’t have to fill in all the steps at once.

A physical journey has a definite starting and hopefully a definite destination. You may or may not know how to get to your destination. You have to just start taking steps. Once you’ve taken a step though, it’s done. You can’t change history. Sure you can undo that step by going back but really that’s just another step. If you keep a log of all your steps, it will show that you went one direction and then back again.

A programming journey is different.

And the steps you take don’t have to all be in order. Imagine being able to take a physical journey where your first step takes you all the way to your destination. You just have no idea how you got there. It gives you the chance to try out the destination and see if you really like it or not. Try that with a road trip. You get to avoid all the bumps, all the crazy drivers, and all the questionable motels and go right to your vacation spot. You can’t do everything on your vacation yet. But you do get to see for yourself if the destination is worth it.

Then on a programming journey, you don’t go back to the beginning and say, “Okay, it’s worth it. Let’s go now.” Your second programming journey takes you somewhere to the middle of your journey. Because you might find that right there in the middle is a huge stretch of road that’s still under construction. If you don’t like it, you get to change it. Your log will still show that you went there. But you were able to jump right to the middle, look around, and jump to a completely different middle spot instead if you want.

You’re able to effectively rewrite history now. That’s powerful. You can rewrite that history because it never actually happened. It was a potential history based on your initial middle jump. The middle jump happened. But all the individual steps that you would’ve had to take on a physical journey never happened and get to be erased from existence.

Let’s say you like your second middle spot better than the first. You could if you want try a third middle spot. Hey you could always come back. These are all single jumps but they set the direction for all the steps you’re going to eventually need to take to get you there. Picking good intermediate destinations is a good way to try things out before actually committing to a specific course.

Once you finally find your best middle spot, you’re not done. Why not repeat this process? I mean if it worked good to get you to the best middle, then how about using the same technique to find the best middle step between your beginning and the middle. Right, you use this same technique to find your best quarter spot. And then your best three quarter spot.

It’s sort of like a connect the dots activity where you get to add more dots as you go anywhere you want.

The WordGuess game is a good example of this type of journey. Because the next step we take fills in some of the playGame method but it completely skips over how we’ll get the words and how we’ll scramble them. In fact, it initially doesn’t use a variable at all for even a single word. It just says “Guess this word: tree” and prints the word tree as is with no scrambling.

Then we refine this a little and add a variable for the word to be guessed. But still no scrambling and still nothing about multiple words.

Then we add a little more structure with another variable for the word that’s been scrambled and even declare a method to scramble a word. But, you guessed it, the method doesn’t really do any scrambling yet. It skips over those steps for now. You can even fake it by coding the scrambleWord method to always return a jumbled set of characters that match the one and only word so far.

Everything’s good so far, right? If you like where your program is and how it’s taking shape, that’s when you start adding in the details. That’s when you start taking smaller steps. You might even get some code at this point that survives to the end.

We know we will want multiple words, so let’s add them now.

But we’ll skip over all the code that allows us to select one word randomly. Just pick one word and write the code so that one word is always selected. You can always test other words to make sure the rest of your program responds well by hard-coding another word instead and building and running your program again. Hard-coding means that you have some value built into your program that can’t change. Or if it can change, then it always starts out with the same initial value.

Only now do we add the ability to select a random word from the collection. But notice how the collection itself is still hardcoded to only know about three words, tree, cat, and cow. A real finished program should have hundreds or more words available for you to guess. We’re skipping over all that and just hard-coding three words into the program.

And the final step that the email course describes is how to scramble a word. It uses the same random number generation code that was used to select a word. Only this time it uses the random numbers to select individual characters within the word to swap positions.

That’s it. You can keep going with this if you want. You can decide to treat what this course used as the destination as just your middle step for a more advanced version of the game.