2008-01-14

Fun with Firebug: Error Messages!

When working in the Firebug console, you might have noticed that syntax errors and the like show up in red on executing the command line. Great success! Exceptions thrown by the DOM, however, for some reason don't, so there is no telling whether your document.getElementById() call happily returned undefined or threw an exception on you.

If you go to about:config and type firebug.showChromeErrors into the Filter: field, and double-click that line to read true -- presto! You can suddenly see where you and the DOM disagree, and when you made some XPath syntax error, so you can tell apart cases like $X('//div[@class="post"') and $X('//div[@class="post"]') and the like.

I've filed a ticket on this weird default behaviour, but am glad I finally found this trivial cure. (I really don't want to know how many times I've wrapped a statement on the command line into a try{ ... }catch(e){e} block to figure out just if or what went wrong.)

2008-01-06

Unbreak the scrollbar

This is a post on visitor centric design and usability, which first and foremost applies to popular blogs: don't break the native window scrollbar. It's in a way related to the advice don't reinvent native browser scrollbars, and boils down to this short tip:

If visitor comments on your posts or articles add up to more than a single-digit percentage of your page height, don't show them by default.

To get nice order-of-magnitude measures of page sizes, try this bookmarklet which shows how many pagefuls, at present window dimensions, your document fills; drag it to your bookmark toolbar, if you want to measure other pages than the one you are presently reading (visit the post, if you read this by feed reader, as feeds and feed readers try to save you from badness by stripping away potentially harmful bookmarklets).

If you visit some interesting post which does not heed this tip, perhaps Steve Yegge on size being code's worst enemy, or perhaps the sci-fi writer Charles Stross about why space colonization might not be such a great prospect, you might find that it's 300 pagefuls tall. Without its 825 comments, it comes down to about five pages, making visitor commentary a whopping 98% of the document's size, which by a margin breaks the sub-ten-percent bound.

The reason this is bad is that it breaks two important functions of the document / scrollbar symbiosis: first, it prevents a visitor from the size overview offered by the scrollbar size to scrollbar height ratio -- "How long is this document, and how far into it have I scrolled?" -- and second, it prevents you from quickly scrolling to the bottom of the document using browser native "Page end" bindings, as there is no snapping to where the post ends and comments start.

See Joe Hewitt's blog for an excellent example of showing comments only after having clicked the number of comments hidden. (If you hide comments, by default, it's a very good measure to show how many.)

I've whipped up a quick'n'dirty user script to turn a few blogs I frequently frequent into click-to-unfold-comments reading mode, as I care for the author's view first, and reader reaction only second, if at all. I didn't go the extra mile to come up with a good UI for making it extend to any blog you might encounter, but XPath geeks and Hoodwink'd dialers will probably find themselves right at home to extend it for their own reading habits, and perhaps post their own additions to the script homepage. Enjoy!

2007-12-25

Code smaller

Ladies and gentlemen of the class of '07: code smaller!

If I could offer you only one tip for the future, slim code would be it.

The long-term benefits of small code bases have been proved by scientists, whereas the rest of my advice has no basis more reliable than my own meandering experience.

Enjoy the power and beauty of your language.

Oh, never mind. You will not understand the power and beauty of your language until you have been forced into adopting a less powerful and beautiful language.

But trust me, in 20 years, you'll look back at and recall in a way you can't grasp now how much possibility lay before you and how fabulous that language really was.

You do not have to write as bloated software as you imagine.

Don't worry about the future.

Or do, but know that trying to design future-proof software is as effective as trying to solve an algebra equation by chewing bubble gum.

The real troubles in your code are apt to be things that never crossed your worried mind, the kind that blindside you at 4 am on some idle Tuesday.

Do one thing every day that scares you.

Think.

Don't be reckless with other people's projects.

Don't put up with people who are reckless with yours.

Refactor.

Don't waste your time on jealousy.

Sometimes you're ahead, sometimes you're behind.

The race is long and, in the end, it's only with yourself.

Remember compliments you receive. Forget the insults.

If you succeed in doing this, tell me how.

Keep your old fan mail. Throw away your old time reports.

Eat.

Don't feel guilty if you don't know what you want to do with your life.

The most interesting people I know didn't know at 22 what they wanted to do with their lives.

Some of the most interesting 40-year-olds I know still don't.

Get plenty of sleep. Be kind to your wrists. You'll miss them when they're gone.

Maybe you'll gain a following, maybe you won't.

Maybe you'll spawn sub projects, maybe you won't.

Maybe you'll leave the field at 40, maybe you'll release The Next Big Thing on your 75th wedding anniversary.

Whatever you do, don't congratulate yourself too much, or berate yourself either.

Your choices are half chance. So are everybody else's.

Enjoy your craft.

Use it every way you can. Don't be afraid of it or of what other people think of it.

It's the greatest instrument you'll ever own.

Hack, even if you have nowhere to do it but your living room.

Read the manuals, even if you don't follow them.

Do not read industry best practices. They will only make you feel inferior.


Get to know your ancestors. You never know when they'll be gone for good.

Be nice to your competitors. They're your best link to your past and the players most likely to stick with you in the future.

Understand that peers come and go, but with a precious few you should hold on.

Work hard to bridge the gaps in geography and lifestyle, because the older you get, the more you need the people who knew you when you were young.

Live in New York City once, but leave before it makes you hard.

Live in Silicon Valley once, but leave before it makes you soft. Travel.

Accept certain inalienable truths:

Codebases will grow. Heroes will change alliances. You, too, will get old.

And when you do, you'll fantasize that when you were young, code sizes were reasonable, heroes were noble, and newcomers respected their elders.

Respect your elders.

Don't expect anyone else to support you.

Maybe you have a day job. Maybe you're funded by wealthy investors. But you never know when either one might run out.

Don't turn a blind eye towards ergonomics, or by the time you're 40 you will feel 85.

Be careful whose advice you buy, but be patient with those who supply it.

Advice is a form of nostalgia. Dispensing it is a way of fishing the past from the disposal, wiping it off, painting over the ugly parts and recycling it for more than it's worth.

But trust me on the small code bases.

With thanks to Steve Yegge (via Jeff Atwood via Simon Willison), Joel Spolsky, Paul Graham et al, and apologies to Baz Luhrmann.