Back from holiday

I went on holiday to Stockholm this week. Of the ~1.5GB I downloaded from the camera, this was the photo I thought most apt to describe the experience on this blog:

Ubuntu

Posted in pictures | 1 Comment

Cocoa#, Mono and Me

My great application:

Currency Converter.net

Yeah, OK, not so great. But this Inverse Hoffman is the result of a couple of hours hacking in Mono, with Cocoa#. My app’s largely based on the Stupid Word Counter tutorial, though it’s a from-scratch implementation of the famous Apple/NeXT sample application in C#.

Firstly, a little history. My first encounter with .NET was back in about 2003 at a Microsoft Developer Roadshow in the car park (and later lecture theatre) in Oxford’s comlab. I was particularly interested in their discussions of cross-platform capability, Project Rotor (I kept in touch with one of the Rotor developers) and so on, but really didn’t see much exciting in .NET. Nonetheless, being a fair man, I took my beta CDs of Windows 2003 and Visual Studio .NET and gave them a whirl. Unfortunately, still not much interesting. Largely due to buggy betas and a lack of beta documentation.

Now accessing Cocoa from non-ObjC languages is nothing new, we’ve been doing it from Perl, Python, Ruby and Java for ages and partcularly old farts might even remember Objective-Tcl. Why should I care about Cocoa#? Well for a start, there are likely to be a lot Windows developers out there with some (language that boils down to MS IL eventually) skills who are wanting to produce Mac applications, and it’d be interesting to see what we’ll end up with when they do. And it’s always fun to learn a new language, anyway ;-)

Good points

  • Real NIB files. No really, that interface is genuinely an IB 3.x NIB based on the Cocoa Application template. The objects inside it are Objective-C objects, and there are good old outlets and actions (I haven’t yet investigated whether Cocoa Bindings would work).
  • macpack. A command-line tool which takes your IL executable and wraps it up in a Cocoa application bundle, ready for drag-deployment.
  • Good inline bridging information. Unlike, say, PyObjC the language bridge isn’t completely dynamic, but unlike the Java bridge or JIGS you don’t have to keep a separate manual mapping of real classes onto ObjC shams. For instance, here’s the controller from Currency Converter.net, complete with class, ivar and method exports:

namespace info.thaesofereode.CurrencyConverter
{
[Cocoa.Register("CurrencyConverterController")]
public partial class CurrencyConverterController : Cocoa.Object
{
public CurrencyConverterController(System.IntPtr native_object) : base(native_object) {}

//Cocoa IBOutlets
[Cocoa.Connect]
private Cocoa.TextField inputCurrency;
[Cocoa.Connect]
private Cocoa.TextField outputCurrency;
[Cocoa.Connect]
private Cocoa.TextField conversionRate;

//Cocoa IBAction
[Cocoa.Export("calculate:")]
public void calculate(Cocoa.Object sender)
{
//get the rate from the view
System.String rate = conversionRate.Value;
CurrencyConverterModel.Rate = System.Convert.ToDouble(rate);
//get the currency
System.String input = inputCurrency.Value;
System.Double output = CurrencyConverterModel.convert(System.Convert.ToDouble(input));
//update the UI
outputCurrency.Value = System.Convert.ToString(output);
}
}
}

Bad points

  • Not very Cocoa-like wrapper classes. I think this is deliberate; they’ve gone for making the Cocoa shim look like a .NET interface because after all, we’re programming from .NET. This is a bit disappointing as I’m more familiar with PyObjC and the Perl-ObjC-Bridge where the APIs are left pointedly alone, but given the target audience of Cocoa# it’s unsurprising.
  • MonoDevelop. Luckily, using it isn’t mandated.

So, overall, one more good point than bad (and a tentative two, if you overlook MonoDevelop); a pretty good initial evaluation and I might give this a deeper scrape.

Posted in cocoa, mono | 1 Comment

Microblogging

For a long time, I deliberately avoided microblogs like twitter. I thought that they were simply an acknowledgement that people want to be published more than they want to have something to say. However, it would be rude of me to completely disavow the medium without actually giving it a go.

To that end, I may indeed be iamleeg on twitter, as soon as twitter actually finishes processing the signup form.

I’d like to point out that one problem I’m going to have is brevity – I have spent 650 characters telling you what my username is. Constraining myself to SMS-sized wibblings will indeed be tricksy.

Posted in crosspost, meta-interwebs | Leave a comment

Common sense writ large

Looking at the bottom of Apple’s Q3 results, as indeed with any similar publication from a US publicly-traded company, we see the following text.

This press release contains forward-looking statements including without limitation those about the Company’s estimated revenue and earnings per share. These statements involve risks and uncertainties, and actual results may differ. Risks and uncertainties include without limitation potential litigation from the matters investigated by the special committee of the board of directors and the restatement of the Company’s consolidated financial statements; unfavorable results of other legal proceedings; the effect of competitive and economic factors, and the Company’s reaction to those factors, on consumer and business buying decisions with respect to the Company’s products; war, terrorism, public health issues, and other circumstances that could disrupt supply, delivery, or demand of products; continued competitive pressures in the marketplace; the Company’s reliance on sole service providers for iPhone in certain countries; the continued availability on acceptable terms of certain components and services essential to the Company’s business currently obtained by the Company from sole or limited sources; the ability of the Company to deliver to the marketplace and stimulate customer demand for new programs, products, and technological innovations on a timely basis; the effect that product transitions, changes in product pricing or mix, and/or increases in component costs could have on the Company’s gross margin; the effect that product quality problems could have on the Company’s sales and operating profits; the inventory risk associated with the Company’s need to order or commit to order product components in advance of customer orders; the effect that the Company’s dependency on manufacturing and logistics services provided by third parties may have on the quality, quantity or cost of products manufactured or services rendered; the Company’s dependency on the performance of distributors and other resellers of the Company’s products; the Company’s reliance on the availability of third-party digital content; and the potential impact of a finding that the Company has infringed on the intellectual property rights of others. More information on potential factors that could affect the Company’s financial results is included from time to time in the Company’s public reports filed with the SEC, including the Company’s Form 10-K for the fiscal year ended September 29, 2007; its Forms 10-Q for the quarters ended December 29, 2007 and March 29, 2008; and its Form 10-Q for the quarter ended June 28, 2008, to be filed with the SEC. The Company assumes no obligation to update any forward-looking statements or information, which speak as of their respective dates.

Erm, like, duh. Stuff which we say might happen in the future, might not actually happen. Really? You’ve got to get out of the financial industry, there’s a lucrative career ahead of you in construction.

Posted in Business | Leave a comment

Designing a secure Cocoa application

That’s the title of next month’s CocoaHeads Swindon, and I’ll be leading the presentation/discussion. So if you want to learn a little about how to ensuring your Cocoa app doesn’t give away the keys to the kingdom, or have some experiences to share with the rest of the group, come along! We’ll be at the Glue Pot, which is nice and near the train station as well as reasonably close to a car park. We’ll be congregating at 7:00 but will wait for everyone to be settled with a beer in their hand before starting ;-).

Posted in cocoa, metadev, security | Leave a comment

Ah, the sweet sound of my own voice

The title is a linky to the press release regarding the edition of Sophos Podcasts I recorded with Carole, and which has now (clearly) gone live. In it we mainly talk about the data theft and Macs technical paper I’ve already posted about. This is the first podcast I’ve ever been involved in, so any feedback you have (apart from telling me that I sound drunk in my first sentence, I’m not sure what that’s all about) will be most welcome!

Posted in Business, security | 2 Comments

CocoaHeads Swindon

Just got back from the first meeting of Swindon CocoaHeads, featuring a bunch of people who live nowhere near Swindon, some good beer and the occasional discussion of Cocoa. Special mention to Scott who came all the way from sunny Warsaw to be with us!

Tonight’s event was an informal, “what do we want from Swindon CocoaHeads?” event, but it looks like being successful enough that we’ll be doing it again. The format will be a presentation or directed conversation, followed by general chit-chat about all things Cocoa. In fact, um, I may have volunteered to give the first presentation at the next meeting. The subject is: well, that would be telling, wouldn’t it… ;-). You’ll have to find out by coming along to the Glue Pot in Swindon at 8pm on Monday, August 4th. Look out for further announcements and a mailing list over at Scotty’s place in the forthcoming month!

Posted in whatevs | 1 Comment

Objective-C NAQs

Never-Asked Questions :-)

In Code Complete 2 §6.5, Steve McConnell presents a list of class-related design issues that "vary significantly depending on the language". So why don’t we look at them for Objective-C? Especially as I can’t find anyone else who’s done so based on a couple of Google searches… N.B. as ever, I’m really considering Cocoa + Objective-C here, as the language itself doesn’t provide enough policy for many of the issues to have an answer (only method resolution and the existence of isa are defined by the runtime and the compiler – ignoring details like static string instances, @protocol and so on).

Behaviour of overridden constructors and destructors in an inheritance tree. Constructors are simple. If you can initialise an object, return it. If you can’t, return nil. The -[NSObject init] method is documented as simply returning self.

For destructors, we have to split the discussion into twain; half for garbage collection and half for not. In the world of the Apple GC, destruction is best done automatically, but if you need to do any explicit cleanup then your object implements -finalize. The two rules are that you don’t know whether other objects have already been finalized or not, and that you must not resurrect your object. In the world of non-GC, an object is sent -dealloc when it has been released enough times not to stick around. The object should then free any memory claimed during its lifetime, and finally call [super dealloc]. Note that this means objects which use the voodoo cohesion of “OK, I’ll clean up all my resources in -dealloc” probably aren’t going to work too well if the garbage collection switch is flipped.

Behaviour of constructors and destructors under exception-handling conditions. Exceptions are a rarity in Cocoa code (we didn’t have language-level exceptions for the first decade, and then there was a feeling that they’re too expensive; C++ programmers like the Leopard 64-bit runtime because ObjC exceptions and C++ exceptions are compatible but that’s not the case in the NeXT runtime) but obviously a constructor is an atomic operation. You can either initialise an object or you can’t; there’s no half-object. Therefore if an -init… method catches, the thing to do is unwind the initialisation and return nil. The only thing I can think to say for having exceptions around destruction time is “don’t”, but maybe a commenter will have better ideas.

Importance of default constructors. All classes implement -init, except those that don’t ;-). Usually if there’s a parameterised initialiser (-initWithFoo:) then that will be the designated initialiser, and -init will just return [self initWithFoo: someReasonableDefaultValueForFoo];. If there’s no reasonable default, then there’s no -init. And sometimes you just shouldn’t use -init, for instance NSNull or NSWorkspace.

Time at which a destructor or finalizer is called. See How does reference counting work? for a discussion of when objects get dealloced. In the garbage-collected world, an object will be finalized at some time after it is no longer reachable in the object graph. When that is exactly really depends on the implementation of the collector and shouldn’t be relied on. Temporal cohesion (“B happens after A, therefore A has been done before B”) is usually bad.

Wisdom of overriding the language’s built-in operators, including assignment and equality. This is such a brain-damaged idea that the language doesn’t even let you do it.

How memory is handled as objects are created and destroyed or as they are declared and go out of scope. How does reference counting work? How do I start using the garbage collector?

Posted in cocoa, FAQ, gnustep, objc | Leave a comment

WWDC day crosspost

WWDC summary on SophosLabs blog, written by yours truly. I wonder how many Sophos readers (I should probably avoid the term sophist, shouldn’t I?) have an interest in Mac and iPhone stuff (and subequently how many comment via the e-mail address on the Labs blog).

Posted in whatevs | Leave a comment

Local KDC on Leopard

via Nigel Kersten, a great description of the operation of Leopard’s built-in local KDC. I think the most exciting thing about the local KDC is the Bonjour support; could we see simple cross-system trust in the near future? Could there be someone in the world who can actually make Kerberos simple?

Posted in darwin, leopard, sysadmin | Leave a comment