Firefox goodness

June 12, 2005 at 11:18 pm (PT) in Rants/Raves

Cool Firefox extensions I’ve recently discovered:

  • Password Composer (video demo). Generates passwords based on a master password and on the domain name of a website, so you get a unique password for each site without having to remember each one. This is a really slick, simple, and effective solution to my complaint about e-commerce sites requiring accounts. Unlike other password generators, even though it generates strong passwords, they aren’t random, so you always can derive your passwords as needed, even if you don’t have the extension installed. (My friend Lior points out that a weaker, low-tech alternative is simply to incorporate the website name directly into your password, e.g. swordfish_gmail. If you do that, though, you should make it less obvious; perhaps use only every third letter of the site name.)
  • Document Map (screenshot). Creates a nifty, navigatable outline of the current page’s headings in the sidebar. Works really well for wiki-generated pages, WordPress weblogs, and programming reference documents (such as w3.org’s HTML and CSS specs).
  • Web Developer Extension. If I still were attempting to do web development, I’d be all over this. View tag and style hierarchies, make live CSS edits, and more.
  • Keyconfig. Modify Firefox’s keybindings. I can’t count the number of times that I’ve accidentally hit backspace outside of a textbox and lost something I was in the middle of writing.

Another cool trick I discovered was how to run multiple Firefox profiles simultaneously. This can be useful if you want to have separate profiles for web development and for normal browsing and want different sets of extensions installed for each. It’s also useful if you want to try out new extensions and themes without screwing up your default profile. To do this on Windows, make a firefox.cmd script:

@echo off
setlocal
set MOZ_NO_REMOTE=1

:: Adjust the path to firefox.exe as appropriate. start "" "C:\Program Files\Mozilla Firefox\firefox.exe" -p %* endlocal

Create a new profile by running the script with no arguments. Thereafter, you can load that profile by running firefox.cmd profile-name.

Recently in a programming forum I frequent, someone posted some sample code he had written and asked for a critique. He would be providing this code to prospective employers.

If you’re trying to get a job programming, providing sample code is good. However, it’s a little surprising what some people consider to be good sample code.

Your goal should be not only to demonstrate that you can write code, but that you can write maintainable code. Write-once, read-never code is worse than useless; it’s fragile and wastes the time of anyone else who ever tries to modify it.

Quick and easy things you can do to improve your code samples:

  • Make your code readable. More whitespace is better than less. More braces are better than fewer. People judge books by covers; make your code look good.
  • Document your code. Document your functions’ contracts; what are their inputs? what are their outputs?
  • Use defensive programming techniques. Aggressively use assertions to check that inputs are valid. Enforce functions’ contracts.
  • Handle errors. (Okay, this one is neither quick nor easy.) In my opinion, handling errors well is probably one of the hardest things about programming. It complicates resource management, it makes code ugly, it’s tedious, no one wants to do it, but it has to be done. If you’re going to submit sample code, take the time to handle errors. Use SESE patterns in C and RAII patterns in C++. At the very least, use comments to acknowledge where you ignore errors.

(Of course, only do the above if you also intend to continue doing them in practice. Misrepresenting yourself is dishonest, okay?)

Revenge of the Sith impressions

May 28, 2005 at 1:11 pm (PT) in Rants/Raves, Reviews

VMware took us all to see Revenge of the Sith on opening day last week. Woo! Overall I thought it was okay; it was way better than The Phantom Menace and Attack of the Clones, and it could have been a lot worse.

Impressions (spoilers ahead):

(more…)

I am such a sucker for girls wearing glasses.

May 27, 2005 at 11:13 pm (PT) in Personal

Sigh.

Back into Palm OS programming?

April 25, 2005 at 1:10 am (PT) in Personal, Programming

I bought a Treo 650 this week, and it’s awesome. It’s even inspiring me to do some programming for Palm OS again. Unfortunately, getting back into that groove is really hard.

I wrote a lot of great code while I was at Sony, but of course all that code is Sony-owned and outside of my grasp. To do any Palm OS development work again, I’d need to rewrite everything from scratch, which is demotivating because I’d be redoing work that I had done already and—since I’m now rusty at this—work that I had done better. It makes me feel like my life is progressing backwards.

The Many Depictions of Suckitude

April 10, 2005 at 10:24 pm (PT) in Art

A themed collection of various pencil doodlings:

(Don’t forget to scroll to the right.)

I am feeling better than I was a few weeks ago, though.

I suck again.

March 17, 2005 at 8:51 pm (PT) in Personal
>_<

I am completely inept.

I guess that’s what I deserve for deluding myself into being hopeful about something.

The downward spiral

March 5, 2005 at 2:38 pm (PT) in Personal

A few days ago I had my first swig of an alcoholic drink. My coworkers and I all went to a bar to celebrate someone’s birthday. One of them ordered some mango drink, couldn’t finish it, and not wanting to see it go to waste, I drank a bit of it. It wasn’t much, but it’s probably the most alcohol I’ve ever had in my life.

Sigh. Did I sell out my (admittedly useless) principles?

This has been a landmark week of firsts for me. I wonder if I’m going through some kind of mild identity crisis due to some impending doom I’m expecting.

First time to a club

February 27, 2005 at 12:35 pm (PT) in Personal

I went to San Francisco with a few friends last night and went to a club for the first time. I think I have too many inhibitions for clubbing to be an enjoyable experience. The rod up my butt must have a rod up its butt.

Maybe I should start drinking.

I am amazed that programming languages (well, the typical ones, at least) don’t make it easier to manipulate files.

A common way files are read in C is to create a struct that matches the file format and to call fread to read the file into it. Isn’t that easy enough?

Not really. This approach is fine in isolation, but it’s non-portable:

  • Different architectures or compilers may lay out structs differently. Your compiler sometimes can choose to add padding bytes to guarantee alignment requirements. Luckily compilers aren’t allowed to do it willy-nilly, and some compilers offer #pragmas to control this.
  • Different architectures have different integer sizes. Appropriate typedefs often can mitigate this, but it’s still imperfect since it requires a small porting effort.
  • Different architectures use different endianness. If a file format is defined to store integers in big-endian byte order but your architecture is little-endian, then if you read the bytes out of the struct without first swapping the bytes you’ll end up with the wrong value.

The typical way to solve these problems is to read a file a byte at a time, copying each byte into the appropriate location within the struct. This is tedious.

Programming languages should provide a mechanism for programmers to declare a struct that must conform to some external format requirement. Programmers should be able to attribute the struct, prohibiting implicit padding bytes and specifying what the size and endian requirements are for each field. For example:

file_struct myFileFormat
{
    uint8 version;
    uint8[3]; // Reserved.
    uint32BE numElements;
    uint32BE dataOffset;
};

When retrieving fields from such a struct, the compiler should generate code that automatically performs the necessary byte swaps and internal type promotions.