Tuesday, February 28, 2012

Zen and the Art of Motorcycle Maintenance

I have read Zen and the Art of Motorcycle Maintenance.  There is a Japanese translation of the book, but I have read the English version, because the Japanese version is not available as an ebook.  The dictionary in Kindle helped me to read the book.
The book is about philosophy and motorcycle maintenance.  I learned philosophy in the university, and learned how to ride a motorcycle out of class, so I believe I'm one of the best readers of this book.  However, you don't need any background on philosophy or motorcycle.  Both concepts are well described in both classical way and romantic way.
This book can also be read as a good non-fiction novel, a story of a father, who is the author, and his son.  The author lost his memory, and was traveling by motorcycle with his son, to find something.  I have an 8 year old son, and he is at a rebellious age.  Unlike the author, I have not lost my memory, but I feel difficulty in talking with my son when he is upset.  he often gets upset.  I hope someday we can understand each other like the author and his son.  It may be good to travel by motorcycle with him.  My wife won't permit it, though.

Monday, February 27, 2012

The scope of for loop variables

What is the output of the following code?
procs = []
for lang in ["Ruby", "Scala", "Haskell"]
  procs << lambda { p lang }
end
procs.each(&:call)
Do you expect the following output?
"Ruby"
"Scala"
"Haskell"
In Ruby 1.9.3, the actual output is as follows:
"Haskell"
"Haskell"
"Haskell"
This is because a for expression doesn't introduce a new variable scope. So all Proc objects closes the same variable lang, whose value is "Haskell" after the evaluation of the for expression. If you use a block instead of the for expression, you can see the expected output, because the block introduces a new variable scope, and each Proc object closes a distinct variable.
procs = []
["Ruby", "Scala", "Haskell"].each do |lang|
  procs << lambda { p lang }
end
procs.each(&:call)
This behavior of for expressions is sometimes harmful, so I have filed a ticket to fix it.
Ruby was originally designed as an imperative language (of course, it is an imperative language even now), so it was reasonable to modify for loop variables by side effects.  However, people prefer functional styles now, so it's time to reconsider the behavior of for expressions.

Tuesday, February 21, 2012

Avoiding the CPU consumption of ETDCtrl.exe

Recently I bought ASUS Zenbook UX31E, which is a good-looking Ultrabook with the 1600x900 display, and I like it.

However, I had one problem that ETDCtrl.exe, which is software to control the touchpad, sometimes remains at 25% CPU usage.  It can be disabled using msconfig, but without ETDCtrl.exe, the touchpad configuration is reverted to default values when resuming from sleep, which means you can't disable tapping.  I hate tapping because it's annoying when typing.

So I wrote ETDCtrlKiller to automatically start ETDCtrl.exe and terminate it one minute later so that it doesn't spend CPU.  You can download it at the Downloads page, but use it AT YOUR OWN RISK!