Once upon a time, I got scared of real life and tempted by the promise of a high-paying job in the programming field. I slogged through the rest of the year at my teaching position that was essentially a living hell (if hell had great coworkers), and I shipped out to California for an “apprenticeship.” I’m basically at a free coding boot-camp for one. My “master” is teaching me out of the goodness of her heart, and the promise that One Day I will be good enough pay her back by conributing to her work. We’ll see.
I had intended to start my documentation of my coding journey from the very first day I arrived in sunny—errr—extremely snowy California. I would end up in the part of Cali where it blizzards. Anyway, I got very distracted by the scenery and all the other things that we’ll just put under the umbrella term of “procrastination.” So now I’m about two months in, but don’t worry, I’m still coding like I’m on day one. Pretty much.
Today, I’m trying to program a game of chess. I’ve written about 350 lines of code, but I suspect at least 150 of them are unnecessary.Essentially, how I code is I use “if, elif, else” until the cows come home. For those of you who don’t know, “if” statements are essential to programming…but they are not essential to use on everything. Eventually, you’re supposed to get better at figuring out more efficient ways to say what I say in hundreds of lines. Since this is not a site for programmers (exclusively), let’s give a real world example so you know what the heck I’m talking about:
Suppose you’re trying to get to your friend’s house across town. You need to be there in an hour. It will take you exactly that amount of time to walk there. The bus that goes there unfortunately runs every 1.5 hours, so unless it’s already at the bus stop once you get there, you need to walk.
Your program would look like this:
IF you get to the bus stop and the bus is there:
ELSE (there is no bus):
that’s not so bad. But suppose you don’t know how to walk there. You would have to give directions in a very tedious way.
Note: to follow this, note the colors I’ve used. Try the first RED statement. If it does not apply, skip what’s not red and go to the next red statement. If that doesn’t apply to you either, go to the next red statement. At any time if the red statement, DOES apply, follow the non-red stuff underneath. Do the same thing for the blue statements.
IF you are not at an intersection and not at a dead end:
keep walking on the same street!
ELIF (else if) you are at an intersection:
check the street sign!
IF the street sign says “Oak St”
ELSE (if it is not Oak St).
ELSE (you are at a dead end):
And so on and so forth until you eventually get there. This is how I code. How good programmers code:
bring a GPS and follow what it says.
I feel like I’ll never get to that point. My teacher says I’m learning quickly, and that I’m totally better than average. I suspect that’s just to keep my ego happy, given that she just basically told me to restructure my entire chunk of code.