MathJax

Monday, November 11, 2013

Book Review: Thinking, Fast and Slow

"Given the subject matter, I can announce without hyperbole that this book is required reading for anyone with a brain."
Thinking, Fast and SlowThinking, Fast and Slow by Daniel Kahneman
My rating: 5 of 5 stars



View all my reviews

Monday, September 23, 2013

How it went

The day was almost standard. If anything, it was perhaps too low-pressure. The pressure at the surface of Renton Municipal Airport, 32 feet above sea level, was 29.60 inHg, rather than the standard 29.92 inHg.

Breakfast was eggs-in-the-nest with Dave's Killer Bread, a bunch of grapes, and a tall glass of 2% milk. I wasn't hungry enough to eat the banana.

Artist's rendition. The nest is actually buttered toast. Not pictured: bananas.
The temperature warmed from its initial standard conditions of 59ºF/15ºC to 73ºF/23ºC. Cruise performance would be midway between the center and right-hand columns of Cessna's cruise performance table in section 5 of the 172S Skyhawk's Pilot Information Manual. That's fine--I'd just be sipping a little less gas at 2500 RPM. And the checkride wasn't going to burn more than 15 gallons of the C172's 53 usable gallon capacity, anyway.

I had been looking forward to this day for two years. I had been ready in the fall of 2011, but mono, weather, a change of instructors, the school getting really popular, a determination to reach a normal BMI and never get fat again, and changing roles at work all took their toll on my training schedule. But now that that was all done, it was finally time to do what I could have done two years ago.

I got to the airport early to skim through the Private Pilot Oral Exam Guide one last time. Skimming through a book is free; the exam isn't.

The oral exam concluded around 2:15pm. I had skipped lunch on the strength of my breakfast, so I grabbed a Snickers. The 'E' in IMSAFE is Eat!

N639SP had just returned from her 100-hour inspection, trivializing the task of locating her maintenance logs. There were 7 crystal-clear quarts of fresh oil in the engine.

Both while climbing and while on final you could feel each of the day's variable wind's 5 knots shifting direction with the caprice of a bored dilettante. We never climbed above 2700 feet, so we had plenty of bumps from the terrain throughout the maneuvers. Because of the bumps, I increased my airspeed for slow flight and on final approach beyond what was necessary. There's being within PTS and there's being proud with your maneuvers, and I wasn't proud.


Anyway, I passed! This is my announcement! I am now a private pilot.

Here's where it happened.
I'm equal parts pleased with the accomplishment and frustrated that it happened two years later than it could have. I know that becoming-a-private-pilot-is-a-beginning-not-an-end, but it's a huge relief to have finished the end of the beginning, especially after such a delay.

I highly recommend aviation as a hobby for those with the means. Become a software developer, pay off your loans, build up your "oh *&@#$" money, and learn to fly.

Pro tip: don't get mono.1




1If you have to, kiss everyone in sight before starting your training. Stop being a baby about it and go contract a disease.2

2I'm kidding, of course...but only just. Seriously, don't get mono.

Monday, August 19, 2013

Computing for Everyone 6: Conditional Execution

Wasn't that last post fun? I'm guessing for a lot of you the answer is "no." I'm sorry--my bad.

So here's the thing: the goal of this series is to allow people who aren't programmers to take full advantage of their computers and other programmable devices at home, school, and work by giving a light introduction to computing concepts. I think the last post went too deep to really serve that purpose. I'll try to steer clear of posts like that in the future. All right, enough metablogging.


Today's topic is conditional execution.

You've seen this before:
visitor:
for your output:

Or have you? I decided to give myself some special treatment this time. Pretend you're me. Just go and tell that box that your name is John and click again.

Neat, eh? So what's the difference?

All computer programming languages support conditional execution: if something is true, do X; otherwise, do Y. Here's what the new code looks like:

function greet (visitor) {
    var greeting;

    if (visitor === "John") {
        greeting = "Hello, " + visitor + ". Remember, authentication is not authorization!";
    } else {
        greeting = "Hello, " + visitor + "!";
    }

    return greeting;
}

Neat, huh? if and else are special instructions in JavaScript (and in most programming languages). The stuff inside the () following if is evaluated as a boolean expression. If the expression evaluates to true, the block (starts with {, ends with the next }) right after the if statement is executed. Otherwise (else), the block ({ to next }) immediately following the else statement is executed.

The statement this new program evaluates is
  visitor === "John"
. A === comparison is true when the values to the left and right are equal and of the same type (e.g. both are numbers or both are strings), so if visitor is set to "John", the comparison visitor === "John" evaluates to true. "John" === "John" would also be true, just a little silly to write (you could just write "true" without the double-quotes (though writing if(true) is pretty silly to write as well)). "John" === "You" is false, 1 === 1 is true, 1 === 2 is false, 1 === "1" is false because the triple-equals comparison operator we're using treats the number 1 as distinct from a string containing 1.

JavaScript has other comparison operators, mostly for numbers. You'll see these same symbols across a wide variety of modern programming languages (well most of these are the same in, C, C#, F#, Java, Ruby, Python, Perl, PHP, BASIC, at least).

Comparing a and b in JavaScriptTrue when...
  a === b
a equals b
  a !== b
a does not equal b
  a < b
a is less than b
  a > b
a is greater than b
  a <= b
a is less than or equal to b
  a >= b
a is greater than or equal to b

Comparison operations can be combined using logical operators && (and), || (or) and ! (not) from last time:

function coverCharge (sex, itIsLadiesNight) {
    var doorPrice;
    if (sex === "F" && itIsLadiesNight) {
      doorPrice = 0;
    } else {
      doorPrice = 10;
    }
    return doorPrice;
}

So women get in free on ladies' night, otherwise it's $10 for everybody.
coverCharge ("M", true) returns 10.
coverCharge ("F", false) returns 10.
coverCharge ("F", true) returns 0.

In addition to if and else, there is "else if". This is how your describe a multi-tined fork in the road for the progress of your program instead.

function sign(birthMonth, birthDay) {
    var sign = "Oops, I guess I missed one. Sorry about that.";
    if (birthMonth === 3 && birthDay > 20  
            || birthMonth === 4 && birthDay <= 20) {
        sign = "Aries";
    } else if (birthMonth === 4 && birthDay > 20 
            || birthMonth === 5 && birthDay <= 20) {
        sign = "Taurus";
    } else if (birthMonth === 5 && birthDay > 20  
            || birthMonth === 6 && birthDay <= 20) {
        sign = "Gemini";
    // ...more of the same for 8 other signs...
    } else if (birthMonth === 2 && birthDay > 20  
            || birthMonth === 3 && birthDay <= 20) {
        sign = "Pisces";
    }
    return sign;
}

else ifs can be chained off of an if indefinitely, but an if must start the chain, and no else ifs may appear after the final else (the final else may be omitted, as above).

Exercise:
Pretend you're a robot. Imagine you have the data you need to make decisions about what to do as conveniently-named variables, and you have conveniently-named statements that describe what you can do. Can you use a chain of if/else if/else statements to describe what to do when you're bored? Describe a series of if/elses that will make your robot version of yourself behave as close to how you would behave as possible.

Bonus:
Death Note is an awesome anime show and manga. How could you express the rules for the Death Note in JavaScript so that your program can compute an outcome from use of the note? What are your inputs and outputs?

I do not often recommend anime shows, but when I do, it's always Death Note.