Tuesday, August 26, 2014

Loop proof

For a while now, I've realized I have a bad habit. I think the habit is perhaps best illustrated by recent XKCD comic "The Loop".

XKCD Comic 1441 - The Loop

As I refreshed reddit for the umpteenth time, I stared at the screen and asked myself:  

What am I doing with my Saturday morning? What am I actually doing. I'm refreshing reddit. Then I'm refreshing a news site. Then I'm on facebook. Then I'm checking my email inboxes. Then I'm back on reddit again! This isn't fun, or productive, or rewarding. Why am I actually doing this?!

Struck with this insight  I closed my chrome instance. Within seconds, and without thought, I had started it again and was back on reddit and the news site. This unconscious action was very unsettling to witness first hand. I subsequently blocked the affected sites both on my desktop and laptop computers.

I'll still browse these sites on my mobile phone, but thanks to my gargantuan bear-hands, that's so awkward and clunky I don't at all seem to get stuck looping in the same way. Incidentally, the weeks that have passed since I implemented this change have been very enjoyable. I've had so much more time, now that I don't waste a bunch of time every day looping.

Sunday, August 17, 2014

The long swim back

In 2012, my life changed.

Getting lost

I had really let my health go during my university studies, and put on a significant amount of weight. I think it started with a mild depression which in turn set off a downward spiral of self-destructive behavior, I did everything wrong in terms of eating, drinking, smoking, sleeping, and exercise.

I'd like to compare putting on a lot of weight like swimming in the ocean and getting caught in a current that takes you really far off shore. Eventually you realize that you're probably not going to make it back, and the only thing you'll accomplish by even trying is to drown tired and sore. So you stop even trying to get back. That's where things really go down hill.

As a result of this, in 2011, I was a wreck. I weighed 140 kg (that's 310 lbs for the metrically challenged). I was constantly tired. I was constantly hungry. I had the blood pressure of a 70 year old, and elevated cholesterol. I was 25 years old and seriously questioned whether I'd live to see 30.

I had done some futile efforts at regaining my health before, without much success. Usually I succumbed to my constant hunger. If I did lose weight, I rapidly regained what I'd lost.


In the early weeks of January 2012, while perusing reddit, I learned about a guy who had lost a lot of weight with something called a ketogenic diet. It even had its own subreddit, /r/keto. In short, the diet dictates strict carbohydrate limitation, moderate protein intake, and the rest of your energy in fat. After a couple of days, your glycogen stores run dry and your body starts to produce ketones, an alternative fuel that has some advantages for people with a messed up metabolism. /r/keto has an excellent FAQ if anyone is interested in learning more.

I have a background in science, so I was a bit skeptical at first, as it sort of looked like the usual pseudoscientific hokum people conjure up in order to sell books. To my surprise, this wasn't Keto, it was just keto. Having followed the money and gotten nowhere, I decided to look into the science. I must admit, in my blind naivete I had assumed nutrition was rigorous like any other modern science. This turned out to be very wrong. I was shocked and terrified by the quality of some of the studies that laid the foundation of most modern dietary guidelines. Nutritional science is improving, but the pace is glacial. Scientific paradigm shifts are frustratingly slow for a reason, it's a defense mechanism against poorly developed theories.

There was enough reasonable doubt for me to decide to do an experiment (that is, after all what scientists do). After all, it's not like I really had anything to lose in terms of health. It worked. Unlike other diets I've tried, keto didn't leave me constantly hungry. It didn't leave me constantly tired--if anything, after a month or so, I was more energetic than I had been in years. The diet also bestowed upon me a mental clarity I hadn't experienced in years.

Note that there is pseudoscience and snake-oil peddlers peripherally attached to keto. You also see the occasional crackpot conspiracy theories about the evil mustache-twisting villains of mainstream nutrition. This is unfortunate to have to wade through, but the diet itself is solid enough.

I weigh 94 kg today (210 lbs), that's "normal" BMI for someone of my tall stature. I'm about 2/3 the man I was. I've gone off the diet a couple of times, including a large portion of 2013, but progress has been steady and in the right direction. My cholesterol is way below reference, and my blood pressure is down to 125/85--normal.  As I've lost weight and gained mobility and energy, I've been able to exercise a lot more as well. Mostly LISS and biking.

In short, I am healthy again. I attached some comparison pictures at the end of this post.

Changing priorities

I blasted through most of my adult life with a self-destructive devil-may-care attitude, burning the candle at both ends like there was no tomorrow. This left me in a very miserable state, and my health in shambles. The long way back has taught me many lessons about the value of taking care of my body.

Today, I always cook my own meals, usually from scratch. I barely drink. I don't smoke. I never snack.

Recently, I've started prioritizing sleep more. 8 hours a night is sacred. For as long as I can remember, I used to stay up too late, undersleep, and be a wreck all day long. Usually I'd crash on the weekends and sleep 11-12 hours. Actually consistently getting the sleep you need changes everything. The mental clarity alone is worth it.

Appendix A: Pictures

2011. 140 kg. 3XL shirt. Needing a haircut.
2014. 94 kg. L shirt. Needing a haircut. And a shave.

Sunday, April 27, 2014


Middle of last year, the project I had been working on since 2012 was drawing to an end, and reflecting back on the work I had done, I realized that the quality of the code was incredibly uneven. Some parts were easy to maintain and extend, whereas others were poorly structured and a severe headache to work with.

Having identified this quality issue with my code, I began to contemplate what could be the problem. I re-read all the great books on code quality and the software development process; Clean Code, the Programmatic Programmer, and so forth. It turned into a bit of an obsession.

By the time I identified the common factors in the problematic code, which was mostly down to the code having too many responsibilities, and one instance of using inheritance where aggregation would be better, the quest for a solution to this problem had inadvertently left me a changed man.

Problem solving is something I am very good at. It's in my mixed education I think, both physicists and programmers are tasked with solving problems--it's the very essence of the crafts, I'd argue--and I have one foot in both professions. The crux is that before you can solve a problem, you need to first realize that it's a problem (and it can be solved by you).

My epiphany was that problems with my development process were "problems" like I knew them from problem solving. That is, I could apply myself to them. I've always liked the concept of kaizen, continuous improvement, but the idea of applying it to the craft of programming never occurred to me. But now everything came together very rapidly. I have probably improved more in the last 9 months than I have in the last 4½ years, and I was by no means a bad programmer to begin with.

Over these months, I have made innumerable alterations to almost every aspect of how I work, and most changes are small, but I think among the more drastic changes I did was one to how I write my code.

I used to half-write a function, then half-write a function it called, and so forth, jumping around in the source file like a mad-man; and then when all the compiler errors went away, cross my fingers I didn't make any mistakes when I put everything together. Besides creating one hell of a clutter, this method also tends to introduce a lot of unnecessary bugs. With this method, your code simply isn't very well thought through, because there is no human alive that can keep all that half-finished code fresh in their mind all at once. As a compensation for this, it tends to lead to pretty long functions, and some severely unhealthy complexity.

I've realized that if you start at the top, and make it a rule to always finish your functions before doing anything else, while keeping them short and giving everything descriptive names, calling other functions that haven't yet been written and using fields that aren't defined, you're able to produce much clearer code. This way, you don't need to keep very much in your mind at all. When you move to implement the next function, you just need to look at its name to know what you intended it to do.

Before incorporating this method into how I work, I mostly got things right, but my ambition ended there. My biggest problem was that I never consistently put any thought to what I was doing. I tried to get better, but my attempts at improvements were wildly undirected, so I saw no tangible change in quality. For the most part it isn't very fruitful to try to assimilate solutions to problems that aren't your problems. So even though I read all the right books and blogs, I was pretty stagnant in terms of skill. I thought I was pretty good, but I just had no idea how much better I could become. The solution to re-iterate being to use self-reflection as a tool to identify problems, which you can solve, and use as leverage for greater understanding.

All that said, I'm still learning and improving. The day I stop is the day I am dead.