Kip

The little things in Firefox 3

Written by Kip on Tuesday, March 18, 2008 at 4:56 pm (EDT)
Tagged as:

A few weeks ago I installed Firefox 3 Beta onto my work laptop, in order to test if two add-ins I wrote would need any tweaking to work.  (These add-ins are simple search bars for people in my company to use to search our source code and our bug-tracking database.)  They worked fine, once I jumped through the necessary hoops to convince Firefox that they weren’t viruses.  But that’s irrelevant; this post is about two small “it’s about friggin time” improvements in Firefox 3.  You can read about the big changes elsewhere.

The first of these changes is the way Firefox handles hyphens in text wrapping.  After a long period of bickering, they finally decided that Firefox (like every other piece of software which displays text) can insert a line break after a hyphen character.  This is something that is particularly annoying to me, since I sometimes use long, hyphenated phrases.  (I’m sure there is a proper name for such a phrase, but I don’t know it.  I guess that’s what I get for not being an English professor.)

Take for example this post from a few weeks ago in, as viewed in FF2 and FF3:

Word-breaking in Firefox 2 Word-breaking in Firefox 3

See how FF2 treats the long line as a single word, rather than breaking the words on hyphens?  In Firefox 3 this has been corrected, which I think is super.

The other small thing is that tooltip text (usually from an object’s “title” attribute) is no longer truncated.  This is mainly a nuisance to me on webcomics xkcd and Dinosaur Comics, where the tooltip text is usually kind of a second punchline.  To demonstrate, here is a screenshot from a recent xkcd comic:

Title tooltips in Firefox 2 Title tooltips in Firefox 3

Much better in Firefox 3.  These two improvements (and the new address bar features) make me excited to use Firefox 3.  Of course, I won’t switch to it full-time until the final release, since most of my favorite add-ons don’t support FF3 yet.

Kip

Macrolicious

Written by Kip on Thursday, March 6, 2008 at 4:03 pm (EST)
Tagged as:

I recently came across a clever way of writing preprocessor macros, and I figured that I would share.

Let’s say that for some reason you need to write a macro: MACRO(X,Y)1.  You want this macro to emulate a function call in every way2.

Example 1: This should work as expected.
if (x > y)
  MACRO(x, y);
do_something();

Example 2: This should not result in a compiler error.
if (x > y)
  MACRO(x, y);
else
  MACRO(y - x, x - y);

Example 3: This should not compile.
do_something();
MACRO(x, y)
do_something();

The naïve way to write the macro is like this:

#define MACRO(X,Y)                       \
cout << "1st arg is:" << (X) << endl;    \
cout << "2nd arg is:" << (Y) << endl;    \
cout << "Sum is:" << ((X)+(Y)) << endl;

This is a very bad solution which fails all three examples, and I shouldn’t need to explain why.

Now, the way I most often see macros written is to enclose them in curly braces, like this:

#define MACRO(X,Y)                         \
{                                          \
  cout << "1st arg is:" << (X) << endl;    \
  cout << "2nd arg is:" << (Y) << endl;    \
  cout << "Sum is:" << ((X)+(Y)) << endl;  \
}

This solves example 1, because the macro is in one statement block.  But example 2 is broken because we put a semicolon after the call to the macro.  This makes the compiler think the semicolon is a statement by itself, which means the else statement doesn’t correspond to any if statement!  And lastly, example 3 compiles OK, even though there is no semicolon, because a code block doesn’t need a semicolon.

The solution is kind of clever, I thought:

#define MACRO(X,Y)                         \
do {                                       \
  cout << "1st arg is:" << (X) << endl;    \
  cout << "2nd arg is:" << (Y) << endl;    \
  cout << "Sum is:" << ((X)+(Y)) << endl;  \
} while (0)

Now you have a single block-level statement, which must be followed by a semicolon.  This behaves as expected and desired in all three examples.  I have noticed this macro pattern before, but I never really thought about why it was written this way.  Mainly because I don’t often write macros to begin with.

1 You should first ask yourself why you can’t just write a regular function and declare it inline, so that the compiler will do the work for you.  I’m going to assume there is some good reason why you must use a macro.
2 Every way, that is, except that it can’t return a value.  That gets much trickier and involves heavy abuse of the ?: operator, if it is even possible at all.
No Comments
Kip

Array-casting in Java

Written by Kip on Friday, October 19, 2007 at 1:23 pm (EDT)
Tagged as:

Since I haven’t posted anything this week, I figured I’d share something annoying I discovered in Java: you can’t assume that you can put an object of type T into a T array (unless you happen to know that T is declared as a final class).

Take for example this code, which tries to put an Integer (which is an Object) into an array of Objects:

  public static void main(String[] args)
  {
    Object[] objects = new String[2];
    objects[0] = "ABC";
    objects[1] = new Integer(5);
  }

This code compiles with no problem but when run it gives a runtime error on the objects[1]= line.  But if the array were declared as new Object[2]; it would run with no complaints.

The problem is that you’re allowed to cast an array of type T to an array of a super-type of T, but you don’t really have an array of the super-type.  I imagine they decided to allow this because of the usefulness of casting arrays to super-types for reading the data.  But it opens up a whole new set of bugs that most of the time you wouldn’t even think to check for (especially if the array is declared in someone else’s code).

Apparently C# has controversially included the same feature.

Kip

Should you sell all your Google stock before 2010?

Written by Kip on Wednesday, September 19, 2007 at 5:12 pm (EDT)
Tagged as:

Joel (as in, on software) made some predictions on his blog yesterday as to where the state of development on the web is going and why he thinks Google’s AJAX-y apps could be troublesome for the company if they don’t adapt well.  I’m not so sure about all that, especially since it is easier to adapt on the web than it was for off-the-shelf business software written in 1989.  Plus I don’t see any web/JavaScript platform becoming as ubiquitous as C++.  But he makes his point well and it’s an interesting read.  Maybe in three or four years we’ll realize he was right.  And if he is right, could this be a second coming of Yahoo?  YUI currently seems to be the most financially backed JavaScript/CSS “platform” of the type that Joel is mentioning, even if it isn’t the most popular right now.  Something interesting to ponder.

No Comments
Kip

Safari-Schmafari

Written by Kip on Thursday, June 14, 2007 at 8:57 am (EDT)
Tagged as:

You may have heard that Apple is bringing the Safari web browser to the Windows platform.  In fact, you can download the beta now.  I wanted to see how compatible my own website is, since Safari is not a browser I’ve ever tested.  Unfortunately, proxy support seems to be broken right now.  Whenever I try to go to a website, I get prompted for my name and password to get through the proxy (this is on my PC at work).  After entering this information, Safari immediately crashes.  This is beta code, so I won’t fault them for having bugs.  I do, however, question the validity of this chart:

Browser speed chart?

From my own experience, this is completely backwards.  Opera is much faster than IE, which is faster than Firefox (when I say IE, I mean IE 6, whereas the chart says IE 7; maybe IE 7 is slower).  I’m not sure what kind of HTML they used to conduct this test, but it must have been much more complex than your typical webpage, in some way that made Safari look good.  Of course, I still use Firefox, the browser that feels slowest to me, because 1) I need my precious extensions, 2) IE is teh suck, 3) Opera cheats with overzealous caching, 4) the speed difference is not really significant, and 5) Opera doesn’t support ctrl+enter, which I rely on to type URLs.

The other thing I noticed in my brief time with Safari is the font smoothing technique, which must have required a lot of work to port over.  I’m not going to get into a discussion of whether it is better than the Windows technique or not; if you’re interested, Joel Spolsky has already done a pretty decent job of covering that topic on his excellent blog.  The problem I had is that my monitor at work is a little unusual in that its sub-pixels are aligned backwards (BGR instead of RGB).  You can fix font rendering in Windows to account for this, but I couldn’t find any such option in Safari.  For an illustration of the problem look at this image:

Font smoothing comparison

If you are on a CRT monitor, both probably look OK to you.  If you are on an LCD monitor, one of them probably looks significantly easier to read.  For most people it is the text on the left; for me, it is the text on the right.  This means that the text in Safari will be really difficult for me to read.  Again, they are in beta right now; they might fix this issue by the time the final version ships.

My screen at home is normal, and I don’t go through a proxy there, so maybe I will actually get to try it out tonight.

Kip

Video game pricing

Written by Kip on Tuesday, February 27, 2007 at 4:38 pm (EST)
Tagged as:

screenshotI don’t understand why WarioWare: Smooth Moves costs the same as Twilight Princess.  WarioWare is kinda fun when you have people over or something, but not fifty dollars worth of fun.  Plus, have you seen the graphics?  Seriously that game couldn’t have taken more than two months for a team of like two programmers an artist and a helper monkey to create, whereas Twilight Princess had a three year development cycle or something.  Why do the casual games cost the same as the serious games?

I may pick up WarioWare used in a year, when it’s like fifteen bucks.  But not new for fifty.  At least Wii Play is only ten dollars (kind of).

No Comments
Kip

Vista wallpaper images

Written by Kip on Tuesday, February 20, 2007 at 2:47 pm (EST)
Tagged as:

Vista WallpaperI think this is pretty cool:  Microsoft got some of the wallpaper images for Vista from amateurs they found by searching Flickr.  Read more here or maybe over here.

No Comments
Kip

Pirates beware!

Written by Kip on Friday, December 8, 2006 at 9:02 am (EST)
Tagged as:

Just a word of caution for the world:  if your installation of Windows XP is, shall we say, less than legal, and you get a popup while using Windows Media Player that says there is a security update to be installed... DO NOT INSTALL IT.  Although they don’t tell you this, the “security update” is actually Windows Media Player 11.  After you have installed WMP11, you will have to verify your Windows installation to use it (sure, they could have just as easily checked this beforehand, but that would be nice).  And if you have System Restore turned off (and what self-respecting geek doesn’t?), you won’t be able to go back to version 10.

I understand that a person who is using the software illegally has little room to claim that Microsoft is wronging him by doing this.  However, the method is pretty underhanded—they claim there is a security update, which is the one thing that Microsoft has said they won’t require Windows validation for, and something that they’ve been trying for the last six years to teach everyone to do automatically.  Not cool, Microsoft.  Not cool.

Kip

The best web browser is: Internet Explorer?

Written by Kip on Monday, October 23, 2006 at 9:57 am (EDT)
Tagged as:

Today I am going to review web browsers for Windows Mobile (formerly known as Pocket PC, formerly known as Windows CE).

Minimo
Mozilla’s attempt at a mobile web browser is in version 0.016, so I think it is more of a proof of concept than an actual, usable web browser.  The website claims that “Minimo has been focused on code-size and runtime footprint reduction, small screen usablity, and porting to small consumer devices.”  Well I think it fails, fails, and fails, respectively.  The install file is larger than the Opera install file (8MB vs. 6MB).  It takes a good 30-45 seconds to launch.  The browser takes forever to load pages.  Scalability to my 240-pixel-wide screen is handled poorly: fonts are left much too large, and God forbid there be an image on the page.  And worst of all, it will invariably crash after viewing about four or five pages.  I stopped using it after the second time it crashed and took down not just Minimo, but my whole OS (with no Control-Alt-Delete, I was forced to let the battery die in order to use it again).  On the plus side, it is the only browser that works with Google Maps (although it uses some kind of proxy site—it’s not actually connecting to Google Maps).

I give Minimo a rating of 0.016 out of 10.  Maybe in a few years it will be a usable piece of software.

Opera Mobile
Opera is the web browser known for running on lots of different devices (Wii and NDS included), so it’s no surprise that they have put together a nice little browser for Windows Mobile.  It is much faster than Minimo, although I can’t say that it’s faster than Internet Explorer (unlike its full-size cousin).  I have mixed feelings about this browser.  There is a weird thing where zooming to 100% causes the browser to go into a completely different rendering mode.  On the text-only version of my site, for example, putting the size to 90% shouldn’t change much, but it actually causes the margins and borders to be rendered completely differently.  It seems the default (100%) zoom level is going through some special optimization, while 90% just resizes the text and renders everything else as-is.  This makes 90% zoom-level better for sites that are designed with a mobile device in mind, and 100% is better for the rest of the web.

Other than that, I have a strong suspicion that images are cached in their full-sized form, rather than caching the resized version (which would generally have made the program faster).  In general Opera seems to do a slightly better job than Internet Explorer on most pages, but it is slower and has some rendering issues.  The real question is this:  will I pay $24 for it after the 30-day trial period is over?  Probably not at first, but if I miss it strongly enough after a while I might.

Pocket IE
Internet Explorer for Windows Mobile is actually pretty good at what it does.  It has some rendering problems, just like any Internet Explorer, but I’ll take those over the stability problems of Minimo any day.  The best thing about Pocket IE is that it is much faster than the other options.  I guess working in the same building as the people who designed the OS will help you stay a little bit ahead of the game.  However, the browser does have some real problems dealing with long pages (Wikipedia is almost unusable on Pocket IE).  In the past I have avoid this by using Google’s mobile proxy, which basically strips sites down to just text.  Overall though I haven’t had too many problems.

So to conclude all this, the ideal would be to have both Opera and IE available, as they have different strengths.  But I’m not sure if Opera is enough better than IE to justify spending any money on it.  And if you value your life at all, stay away from Minimo, at least until the most significant digit of the version comes before the decimal.

Disclaimer: these tests were all conducted on a Dell Axim, running Windows Mobile 2003.

Kip

Kip rambles about programming

Written by Kip on Tuesday, September 26, 2006 at 7:08 pm (EDT)
Tagged as:

A few weeks ago, I had to explain inheritance to someone who has been working with software for over a decade.  Sure, he may not have learned about inheritance back when he got his degree, and he may have spent some of his career in sales traveling around the world without writing code.  But for the last three or four years, his job—you know, the thing that pays for his kids’ food—has been to write and maintain Java code.  I expected him to have picked up on this whole object-oriented thing by now.  Since it’s a fundamental concept of Java and all.

Here’s a very simplified version of the code in question, formatted to be as brief as possible:

class A {
  protected boolean isFooRequired() {  return true;  }
  public void doSomething() {
    if (isFooRequired())
      foo();
  }
}

I suggested he fix a bug by adding isFooRequired() to a subclass:

class B extends A {
  protected boolean isFooRequired() {  return false;  }
}

He didn’t understand how the line “if (isFooRequired())” would know to call the isFooRequired() method in class B for an instance of B.  It’s called polymorphism.  Look it up.

That got me thinking about my own software development knowledge.  I work in a field where half of my technical knowledge will be obsolete in five years, and I have probably learned almost as much since graduating as I did in school, so how much good did my degree really do me?  A lot of what I know I have learned from websites and blogs for developers.  I guess they are kinda filling the niche that industry magazines used to fill.  In ascending order of usefulness, the sites I visit most would be The Old New Thing, The Daily WTF, A List Apart, and especially Joel On Software.  And please let me know if I’m missing out on any good ones.  So anyway I’ve learned a lot of things that they just don’t teach you at school, or that you would never want to learn in a classroom (i.e. having a test where they ask if you should require developers to write code in the interview would be dumb).  But there are many things that I wasn’t really taught, or that I was taught only through an elective.  Regular expressions have been extremely useful in my two years of professional programming, yet I only learned them in a one-hour Perl course.  I was never taught closures, and I only learned a functional programming language (Lisp) in an elective (Artificial Intelligence).  Not that I have ever used Lisp in the real world, but closures are nice and allow programmers to do some powerful things very easily.  Java and PHP kinda have things that are sort of like closures, but not really.  Perl has them, but I never write any code in Perl complex enough to need them.  I was never taught databases—I strayed from the databases elective since I knew that if I took it, I would list it on my resume, and I was afraid that listing the course would land me a job as a database administrator.  And I did not want to be a DBA.  In my software engineering course, we went over some concepts that are very important, but don’t really make sense to be tested on—it might have been more effective as a required series of lectures or something, provided the lecturers did a half-decent job.  I know I would have payed more attention that way.  Design patterns were covered in that course very briefly, although knowledge of them has been invaluable to me in the real world, and I was asked about them on nearly every job interview I went through.

I guess where I’m going with this rant is that I make an effort keep up with the latest and greatest.  It is something I am interested in (which is one of the reasons I chose to major in Computer Science in the first place), and it is vital to me being good at what I do.  Shouldn’t I expect others in this field to make at least a minimal effort to do the same?

RSS feeds: Kip's - Stephanie's - Both
Admin