Locale

Awesome Adium Time Zone plugin: good (or, well, awesome).

PBGContactTimeZonePlugin.m, line 95 (time = [[NSAttributedString alloc] initWithString:[localTime descriptionWithCalendarFormat:@"%1I:%M %p, %A"]];): bad.

time = [[NSAttributedString alloc] initWithString:[localTime descriptionWithCalendarFormat:@"%X" locale:nil]]; returns the time following the current locale and matching any format changes you may have done in the System Preferences. For a plugin with no configurability, my recommendation is to use the default locale representation.

Update: Clarification: On 10.0 through 10.3 (Panther), use NSCalendarDate methods like above. (localTime is an NSCalendarDate instance.) On 10.4 and forward, use NSDateFormatter. For NSCalendarDate, you can use %c for a date and time composite, and %x (lowercase x) for the date component, in addition to the %X for the time component.

Out of courtesy, I will refrain from pointing out that the Edit Time Zone menu item is not run through AILocalizedString.

(Yes, I am aware of the abysmal state of localization in some of my products, notably Monocle. I am working hard on getting it right - including things like correctly detecting and storing string encodings for discovering search engines - which is why I couldn’t make it into 1.0 due to the self-imposed deadline. I intend to write an entry where I beat myself up over Monocle’s code too. Do not worry. )

Super Happy Pun Time

Sometimes I think some readers are not aware of exactly how lucky they are to not be within instant messaging distance of yours truly. To wit:

Jesper
it is insanely ironic how Bill Gates, and not Steve Ballmer, is the Chairman of Microsoft
Shawn Medero
oh?
Jesper
chairs.
Shawn Medero
heh
do you just sit around thinking up puns all day?
i like that about you
Jesper
see, that’s why you put the tics in politics

Mac SVN Server

M. Uli Kusterer has done it again: a standalone Subversion server. Everything bundled. For something practically requiring Apache 2 for decent operation, this is awesome.

Selectors vs named arguments

Some people claim that Objective-C’s selectors (function names with parameters infixed) are just functions with named arguments.

Here’s a very simple proof that selectors aren’t named arguments:

- (void)fooThis:(int)firstArgument andThis:(int)secondArgument andThis:(int)thirdArgument

That’s the signature of an Objective-C instance method with the fooThis:andThis:andThis: selector. Treating the selector parts as named arguments would be impossible - would the argument whose name is ‘andThis’ correspond to the second or third argument?

Not to mention that you actually don’t need names in all places, or even any place. This is a perfectly valid method specification:

- (NSArray *)arrayWithThreeObjects:(id)object :(id)object :(id)object

Update: This is another: - (void):(id)object :(id)object :(id)object. (See also: AEVTBuilder.) Thanks to Jens Ayton in the comments.

Update: Special DVD extra material follows!

Lastly, I’ve used the terms ’selector’, ‘method’ and ’signature’ here. What’s the difference?

The selector is simply this: fooThis:andThis:andThat:. This is the parallel to the C function name (sayHello), and they both compile down to ’symbols’ - this is why the selector segments are non-reorderable, by the way, because actually, somewhere in the dank annals of the Objective-C runtime and compiler tag team, the selector is turned into a function name.

The signature is this: (void)fooThis:(int)firstArgument andThis:(int)secondArgument andThis:(int)thirdArgument. This is parallel to the C signature (void sayHello(char *string)), in that it includes type information and the variables the arguments are assigned to. Strictly speaking, the variable names are not part of the method’s signature. (In C# and Java, methods can have multiple definitions with the same function name, as long as they have different signatures - aka you can have both void sayFoo() and void sayFoo(String why, int howManyTimes).)

The method is the pair of method specification - which is a + for a class method or a - for an instance method, followed by the signature and all inside a class @interface block - and the method implementation, which is the method specification followed by a block, inside a class @implementation block.

« Newer posts · Older posts »