Monday, February 17, 2014

Why Programmers Should Exercise

I was told that this article should be retitled, and I should make the target audience a bit more explicit.  So I did.

IF reader.alreadyExercises()
  THEN GOTO 5
ELSE GOTO 10

5
You can skip to the part where you get happy signals from someone reinforcing your beliefs and you share this on your Facebook/Twitter/other networking site.  You probably won't find much new in this article, though feel free to read on.


10
Now that that's dealt with, I'll get to the meat of this post, namely, why you should want to be in shape, whether or not your occupation / hobbies are physically involved.

First, I'll lay out some of the research around this:
1) Fitness (especially aerobic exercise) substantially lowers the risk of Alzheimer's, dementia, and, of course, heart disease.  You can expect serious longevity increases just from those, though there are other things it helps with (e.g. likelihood of dying from infectious disease, ability to handle chemotherapy).

2) Study after study after study suggests that exercise improves all sorts of cognitive processes.  Your code will almost definitely be improved, either in elegance or number of problems solved / time.  Just because your job doesn't directly involve physical activity doesn't mean it's not helpful.

To inject some anecdotal evidence, I used to never exercise.  I made all sorts of excuses.  "Oh, that's all well and good, but I don't have time!"  "I'm in good enough shape <runs around the block /> <hyperventilating> see? </hyperventilating>."  "I can't afford to be tired."  Rationalization is probably the most unfortunately-rooted word in the English language, and most reasons not to exercise fall into that bucket.  I've noticed a few major benefits that I was quasi-deliberately underaccounting for:

1) Time - my level of physical activity seems to have a strong causal link to clarity and speed of cognition.  I tend to get the same amount of (or even more) work done as I was previously, but in time_awake - time_exercising instead of time_awake.

2) Energy - exercising has, oddly enough, left me feeling less tired, not more.  There is a relatively established link between physical activity and awakeness/energy/whatever-you-wish-to-call-it.  Finding relevant papers is left as an exercise for the reader.

Now, to directly address some common rebuttals:
Exercise is boring! - I thought that too.  If you're finding it boring, you're doing the wrong kind of exercise.  Running on a treadmill not working for you?  Run while watching TV, or run outside so you have things to look at.  Road biking got you down?  Get a mountain bike.  Most worries about boring exercise can be solved by sitting and actually thinking about third alternatives for 5 whole minutes.  I started to get into shape with a combination of rock climbing and miming.  I'd be willing to bet neither of those were in your first two options.  THINK OF A THIRD ALTERNATIVE.

Exercise is hard! - Yes.  Yes it is.  Sorry, but downsides exist to policies in complex systems.  I tend to get a positive feeling of accomplishment from doing difficult things, but your mileage may vary.  The benefits are still probably going to outweigh the cost of some willpower though.


Other things worth noting:
There's already some pretty good material on optimal exercise out there, if you're concerned with getting the most bang for your metaphorical buck.

As with any health-related-lifestyle-changes, your mileage may vary.  That's not an excuse to give up after one day.  If the "this is hard" part goes for months, something's probably up, but don't reach that conclusion much earlier.

Another important thing to pay attention to is diet.  Not dieting, diet.  Exercise without eating healthy is like a high IQ without any conscientiousness.  It's worth something, but you won't get much done.  Finding a diet that works for you and sticking to it probably deserves its own post, but I'll try to summarize a bit here:
Paleo and its variants seem to have very mixed results, though they match up pretty effectively with my understanding of human metabolism.  Eating a diet more similar in contents to what you'd find in the ancestral environment seems like a good heuristic, if not a perfect one. 

Conclusion:
Changing habits around physical activity is probably one of the simplest lifestyle changes you can make with really established benefits.  You'll think more clearly, write better code, feel healthier, and almost definitely live longer.  Yes, it's hard.  Do it anyway.  You won't regret it.

Wednesday, February 5, 2014

A Few Essential Vim Tweaks for Working in Haskell

One of the things I found most annoying about Haskell when I started working with it was the lack of a real IDE.  I searched around for a while and found nothing all that good (except maybe FP Haskell Center, but I like being able to work offline).  At first I worked with Sublime Text 2, for which there are several very useful packages available through the package manager.  And that was fine for a while.  But there were still a few things missing.  It didn't have good command line integration, and SublimeREPL just wasn't cutting it.  Around the time that this was becoming most annoying, I had also gotten to an introduction to Vim in a Unix course I was taking.  This got me investigating different editors again, this time focusing mainly on Vim and Emacs (though others were considered), and I ended up settling on Vim (though I'm considering trying to switch to Emacs again).  For some reason the modal interface seems more natural, though your mileage may vary.

Anyway, after installing Vim, I wasn't quite done - I still needed to add a few packages to make editing convenient.

Pathogen makes plugin management a whole lot easier.  Install it before anything else here to preempt headaches.

2) A Good Color Scheme
While it isn't specific to Haskell, you should care about your color schemes.  I plan to write a full post on this at some point, but for today I'm just going to assume you agree that pretty colors are important.  Anyway, there are lots of good ones to choose from.  As you might be able to tell from the colors on the blog, I'm a fan of Ethan Schoonover's Solarized, though there are plenty of others worth looking at.  A good color scheme will make it much easier to read your code at a glance while greatly reducing eye strain.

This package consists of a few plugins aimed at making Haskell development easier - GHC support, syntax highlighting, the works.  It doesn't do everything, but it sure does a lot.  You could start working in Haskell with just this and a color scheme.

Syntastic is another one that's not Haskell specific, but adds enough general functionality that it's definitely worth getting - it'll add some type checking capability to vim before you hit the compile button.  Speaking of...

I threw those lines into my .vimrc for one very simple reason:
GHC gives very useful information when you compile
Going to a different tab in iTerm and typing out ghc (filename) is annoying.
So I just nmapped F5-F7 to ghc, ghci, and ghc --make respectively

File management.  'Nuff said.  I personally prefer to use Vifm for most things, but it's really a difference of preference.  From what I understand, NERDTree is a bit more powerful, but I also find it a bit less elegant.

Better support for quick commenting - not much more to say really.  A useful feature, really strangely lacking from vim.  Much faster than 0i--.  It makes debugging a good bit easier (you can quickly comment out different pattern matches and recompile to test where the bug is, things like that).

YankRing improves copying and pasting in a lot of ways -
It allows you to copy and paste across buffers.  It essentially emulates Emacs' "kill ring" while adding a few other nice features.  


Anyway, those are the main tweaks that I use.  I've heard many times that I should use SHIM, but I've never really seen the need for it.  This may turn out to be isomorphic to the blub paradox, but until I get around to testing it I won't know.