Saturday, November 12, 2011

Presumed Innocent

It's been good to get back into coding after several years away from it. Things are starting to click for me again, and it's interesting to see how much things have changed (and how much they've stayed the same!)

One thought that occurred to me last night as I was working on a subtle bug was the idea of presumption of innocence in law, and how it applied to coding. Basically, there are two ways that one can approach a criminal case: a) you can assume that the person being accused is guilty and ask them to prove their innocence, or b) you can assume they are innocent and ask the accuser to prove their guilt. Either position has some drawbacks, but the general consensus is that (b), the presumption of innocence, is the most civilized manner in which to construct law.

So how does this relate to coding? Much like the law, we code to define a certain conduct of behavior and the consequences for not following that conduct. And also much like the law, we can code with the assumption that the user is innocent or guilty. Consider the simple if - then - else clause. Typically, this is written as

if (something_that_is_true) {
  then_do_this();
} else {
  then_do_that();
}

At minimum, we can remove the else (and in some languages the surrounding braces too, but I'll be sticking with Java syntax), to just:

if (something_is_true) {
  then_do_this();
}

What if we consider "true" as equal to innocent, and "false" as equal to guilty?

Presumption of Innocence would suggest that we assume truth and only code for guilt:

if (something_is_false) {
 then_do_that();
} else {
 then_do_this();
}

Or even better, for languages that support the construct:

unless (something_is_false) {
  then_do_this();
}

If you aren't using such a language, but do support ad-hoc returns from functions:

if (something_is_false)
  return;


then_do_this();

The idea being that unless guilt (falseness) is proven, you assume truth (innocence) and proceed with code execution. In contrast, presumption of guilt would only execute code if it is proven true (innocent):

if (something_is_true) {
  then_do_this();
}

Most of the time I find myself mixing styles. Sometimes coding with presumption of innocence, sometimes with presumption of guilt. I wonder what would happen if I only ever used a single style? Would this be better or worse, or no change?

Sunday, October 30, 2011

iFun

I was excited because I had a chance to get to sleep (relatively) early today.

I was also excited because I had started the process of upgrading my phone to iOS 5.

Apparently these two states are in contradiction to each other and cannot coexist. Three hours after starting the process my phone is finally in the process of "restoring" the apps. I'm hoping its not much longer until everything is done. I can't just leave me phone to complete the process on its own either because by the miracle of technological convergence, my phone is also my alarm clock. So I need it working before I go to sleep.

Seriously -- did my internet connection suddenly get reduced to a 56k modem and my phone flip from usb to an rs-232 serial port!?!?

All this and I don't even get to enjoy Siri...

Thursday, October 27, 2011

Get It Done (How To)

How do you get things done and accomplish your goals? Search for this on Google and you'll find, oh, about 93 million results. And a lot of them are trying to sell you something too. Want a secret? If your goal is to sell a book, make it a "how-to" book. After all, Amazon has only 499,071 (oops, now it's 499,072) for sell.

Ok, so obviously there are a thousand different opinions on how to accomplish your goal and a hundred thousand success stories for every one. All of them claim to be the secret sauce, and all of them have that rave review from the friend of a friend. However, discounting the claims of your best friend's grandmother's hair dresser, what does science tell us about how to accomplish your goals?

1. Don't tell them to anyone when you start. There's a short but informative Ted talk that explains it well, but the gist of it is, as soon as you vocalize your goals to another person your brain produces a small rush that is similar (though much less powerful) to that feeling you get when you actually accomplish your goal. The problem is that now that you've experienced that nice euphoria you have much less incentive to go through the hard work and pain of accomplishing the intended goal. Eventually you're going to tell people your goal, but get going on it first. Put in some sweat and effort, enough that when you do tell someone and you do get that little feeling of pleasure it isn't enough to overcome the effort you've already put in. At that point, your brain will keep saying "I need the real thing now" and it won't let you settle for less. But speak too soon and you'll have hijacked your effort before you even started.

2. Define your goal. Make it SMART. If you're the visual kind, diagram or map it out. Or make an audio recording of yourself talking about it (this can also double as practice for when you perfect your elevator pitch).

3. Have someone who will keep you accountable. Ok, so this kind of sounds contradictory to point #1, but it's all in the timing. First you need to keep things secret, but once you've dug in and actually started, it will help you a lot if you have someone who will ask you the hard questions and keep you accountable. They can also help you celebrate and, when the going gets tough, remind you why you even started in the first place.

4. Pace yourself. You won't go anywhere if you wear yourself out. Know your limits and push them a little, but remember that most goals are marathons and not sprints. That being said, the old saying of two steps forward and one step back often holds true. Most of our growth and accomplishments don't happen linearly but in spurts, and often we experience a slight regression before the spurt occurs. I don't know the scientific name for this, and there are many articles and books out there claiming to help you "skip" over it, but fact is this is how your body/brain grows and you'll just need to go through it. So just keep reminding yourself that it will be there, that it will end, and that when you come out the other side you'll be at a higher level.

5. Eat healthy and exercise. We all know this to intuitively be true, but the science proves it too. In her book The Secret Life of the Grown-Up Brain, Barbara Strauch touches on research showing how diet and exercise directly affect our ability to grow and accomplish tasks. For instance, somehow (the exact mechanism isn't known) the act of exercise results in, or at least accelerates, the birth of new brain cells. Since most of the time accomplishing our goals involves some form of stretching ourselves and learning or acquiring new skills and knowledge, having a few extra brain cells floating around can do nothing but help.

6. Write about it. Whatever your goal is, the act of writing about it, recording the progress, and getting thoughts out of your head and down onto paper can help immensely. If you have a blog you can put it there, or if you just need a private place to jot it down check out 750words.com. Or go the olde fashioned route and use a pencil and paper. It doesn't matter where, just get it out. Sometimes even forgoing words and just mind-mapping or letting things freeflow can help you get unstuck.

These are just some ideas and observations. What it all comes down to is just start and keep at it. 

Wednesday, October 26, 2011

Amnesia

Last night as I lay in bed, waiting for the bliss of sleep to descend on me, I found myself thinking about this blog and of the many things I'd like to write in it. I began to categorize them and to systematically think through each, to consider precisely the phrases I would use and how much detail I would put into each theme. Then, as time progressed and I became more excited about all the words I would type, my thoughts became hazy and sleep overtook me.

Now it's the middle of the afternoon of the day after, I'm wide awake and sitting in front of this open blog post, and of course I don't recall a single thought I had last night. As Snoopy said of the Red Baron -- "Curses, foiled again!"

Sunday, September 11, 2011

On the move

I'm writing this post from the iPhone, which is rather slow and tedious for me but I guess that's because I'm used to touch-typing what I want to say. Since I won't have a computer all the time, though, this may suffice to fill in the gaps.

It seems everywhere I look there are newborns and infants, and it's strange to see how quickly Sophia is growing in comparison. When we first took her out every other baby we saw was bigger than her. Now, although most still are bigger, in every outing there are more and more babies that are smaller. I don't think there's a strange epidemic of shrinking babies occurring so I must conclude that our little girl is getting bigger day by day. What an exciting, crazy thought!

As a closing token of wisdom, I'll leave you with this: the Blogger iPhone app doesn't seem to support a rotated (landscape) keyboard -- it really should.

Saturday, September 10, 2011

Let's get it started (in here)

It's been a while. Some things have changed, others have stayed the same. On the whole, probably more change than status quo. I'm going to start posting again now.

Politics, philosophy, technology, family and children -- they're all game! Actually not even sure where to start, but I'm sure I'll get going somewhere. Right now though a tiny little girl is getting hungry and her mommy and daddy are getting sleepy, so we'll continue this again soon. I promise. :)