The first key to programming is to type, not to think
I remember vividly this scene from Finding Forrester, which, in my memory, goes something like this: Jamal is stuck. Forrester grabs the typewriter and proceeds to type furiously. Jamal reads what Forrester has written, amazed. Forrester says, “No thinking – that comes later. You must write your first draft with your heart. You rewrite with your head. The first key to writing is … to write, not to think!”
I have just realized that I tend to be struck by analysis paralysis nowadays. When I first started out, it never happened to me: I simply hooked up UI events to SQL statements, and I was done. Then I read up about design patterns and worked with experienced developers who would separate different concerns into layers. As a result I would think and think before writing a single class declaration – and get absolutely nowhere.
One day I noticed, especially at the architecture and design stage, that I would start a little bit, then I would look something up, and then I would get lost reading for two hours. The truth is that I’ve been so scared of making a mistake that I don’t dare start.
So from now on I resolve to just type. If I’m not clacking away at the keyboard then I’m not programming. This doesn’t negate the Big Design Up Front philosophy; I will try to produce a couple of paragraphs of functional specs as far as I possibly can. But stopping to think too much is definitely not progress.
You might have heard that Fred Brooks once said, when building something, plan to throw the first version away; you will anyway. He has actually retracted that: he says we should plan to continually iterate on it.
And you can’t continually iterate if you’re not typing.
PHP whitespace fail
I had a problem with header('Location: http://example.com') not redirecting as it should. After fiddling a bit, I discovered that it worked before, but not after, this line:
$x = $this->foo($bar);
So what was in function foo()?
private function foo($val)
{
include_once 'baz.php';
$baz = new Baz();
return $baz->get_value($val);
}
I then proceeded to examine every nook and cranny of baz.php to see if there were any instances of echo or print or any other form of output. Nope, Baz was a straightforward class with straightforward methods.
I don’t know where these thoughts come from, but I certainly wish they’d come often: it suddenly occurred to me to check for spaces and new lines after the end processing instruction ?> in baz.php. There were indeed a couple of newlines after ?>, and the removal of said newlines solved the problem.
PHP foreach
The PHP foreach construct is very convenient, except that it creates a copy of the array. This is undesirable in the case of very large arrays. The following is a drop-in replacement for foreach, which operates directly on the array:
$arr = array("one", "two", "three");
reset($arr);
while (list(, $value) = each($arr))
{
echo "Value: $value<br />\n";
}
Or
$arr = array("one", "two", "three");
reset($arr);
while (list($key, $value) = each($arr))
{
echo "Key: $key; Value: $value<br />\n";
}
Code examples lifted straight off the PHP manual.
Vimperator vs Vimium
Update 15 January 2012
I have switched from Vimperator to Pentadactyl for quite some time. Pentadactyl allows letters to be used as hints out of the box; add the following line in your .pentadactylrc:
set hintkeys=sadfjklewcmpgh
For more Vimium-like highlighting:
highlight -a Hint text-transform: uppercase; padding: 0 2px 0 1px; background-color: yellow; font: bold 11px “Droid Sans Mono”;
highlight -a HintElem background-color: transparent;
Tab numbering:
set go+=n
Update 15 November 2010
Vimperator does in fact allow letters to be used as hints, via the char-hints-mod2 Vimperator plugin. Just drop the .js file into your ~/vimperator/plugin folder and add the following line in .vimperatorrc:
let g:hintsio="iO"
Therefore this leaves no fundamental difference between Vimperator and Vimium.
Original post
Vimperator and Vimium are extensions for Firefox and Chrome, respectively, that allow you to perform actions using Vim keyboard bindings. I’ve been using FF + Vimperator for about two or three months and I’ve recently switched to Chrome + Vimium. My verdict? Chrome + Vimium is better, for the following reasons:
- Vimium uses alphabets whereas Vimperator uses numbers. From a touch typist’s perspective, alphabets are faster to type than numbers. For me this makes the biggest difference.
- Vimium is easier to install and to configure.
Unrelated to Vimperator/Vimium: what I miss on Chrome is FF’s numbered tabs (via NumExt) and the ability to go to a tab by typing [number]b. Of course, both FF and Chrome support Ctrl + [number] by default, but I like to avoid using the Ctrl key if possible.
Tolstoy for bedtime
Last night I read Tolstoy to my four-year-old.
No, it wasn’t Leo Tolstoy’s War and Peace; it was Alexei Tolstoy’s The Enormous Turnip.