Overloading == to return a non-boolean

Were you aware that you could overload == to return types other than boolean? I certainly wasn’t until I started reading through the lifted operators part of the C# 2 specification. It’s quite bizarre – here it is in action:

using System;

class Test
    public static string operator== (Test t1, Test t2)
        return "Fish?";
    public static string operator!= (Test t1, Test t2)
        return "Not a fish?";

    static void Main()
        Test a = new Test();
        Test b = new Test();
        Console.WriteLine (a==b);

That ends up printing “Fish?” to the console. Strange but true. When I asked about this on the newsgroup, one poster said that he did use this functionality for an ORM type of system – his == operator on two expressions would return another expression which represented the test for equality between the other two expressions. I can’t say I much like this idea, although I could see where he was coming from. (The C# spec does specifically discourage this sort of thing, which is at least a start).

So, dear readers, have any of you done this, and if so, why?

Who do the “stars” look up to?

I follow a reasonable number of blogs. Not a vast number, but most of the ones I read (about computing, anyway) are written by people who are way out of my league. I mean, I can just about peer into the league of people like Simon Tatham who I’m proud to have as a friend even while I generally gape at his grasp of algorithms (verging on the obsessive at times, I have to say). Such people I regard as in a league above my own, and that’s fine – but then there are people like Don Box and Joe Duffy. If ever I’m tempted to start regarding myself as an “expert” in threading because some very kind people occasionally label me that way, all I need to do is think of Joe to come back to reality.

So my question is: who do these people look up to? Each other? I mean, I’m sure Don wouldn’t want to go head-to-head with Joe about detailed concurrency issues, and Joe probably wouldn’t try to bluff about web services around Don (which isn’t to say they couldn’t stimulate interesting discussion in each other’s area, of course). But there must be some recognition that they’re playing in the same league, just with slightly different equipment. Who do they regard with the sort of awe I have for them? Is there some uber-elite which us mere mortals don’t even hear about?

I think it’s healthy to be able to see people who are smarter than you. It can be a bit scary when you see just how wide the gap is (or at least appears to be) but it’s generally a good thing. The web has made this much easier – and simultaneously made it harder to be “big fish” because everyone gets to see how big the pond is.

If I get delusions of grandeur (well, more of them) I hope my friends will kick me back down to the right league. And if they don’t, I sincerely hope I’ll still be able to read the works of people like the ones listed above, and shrink back to Ronnie Corbert size again. Disclaimer: this doesn’t for one minute mean that I’ll avoid plugging my book like crazy when it’s nearer the release date.

Why hasn’t Microsoft bought JetBrains yet?

For those of you who aren’t aware, JetBrains is the company behind IntelliJ IDEA, the Java IDE which I’ve heard amazing things about (I’ve tried it a couple of times but never got into it – I think I need an expert sitting beside me to point out the cool stuff as I go) and ReSharper, the incredibly useful (although somewhat resource hungry) add-in to Visual Studio that turns it into a respectable IDE.

What would happen if Microsoft bought JetBrains?

I’m sure that killing off the reportedly best Java IDE would do .NET no harm (even if it would be a fairly cruel thing to do, and still leave other perfectly good IDEs in the Java space), and surely they could use the ideas and experience of the company to improve Visual Studio significantly. I strongly suspect that tighter integration could make all the ReSharper goodness available with less performance overhead, and while it’s no doubt too late now, wouldn’t it have been wonderful for all of those features to be available in Orcas?

Anyway, just a thought.

Implementing Ruby on .NET, and the importance of specifications

This morning, when following links to Jamie Cansdale’s ongoing tiff with Microsoft (best of luck, Jamie) I came across Martin Fowler’s concerns about Ruby on .NET. Most of the responses I’ve seen have – entirely reasonably – been about Microsoft’s relationship with open source and with the community as a whole. All of that is fine, but two points particularly caught my attention in Martin’s post:

Soon-to-be-ThoughtWorker Ola Bini, a JRuby committer, reckons that it’s almost impossible to figure out how to implement a Ruby runtime without looking at source code of the MRI – but Microsoft imposes drastic limitations on its employees’ ability to download open source software, let alone look at the source.


The overwhelming sense I heard in the community was not “Ruby will kill evil Microsoft” but “how can we overcome the problems to get Ruby on Microsoft.”

Now, as a disclaimer, I’ve done virtually no Ruby. I reviewed some early drafts of Ruby For Rails, and I’ve heard wonderful things about it from my ThoughtWorker friend Stuart, but I haven’t used it. As such, I certainly am in no position to judge it as a language in terms of elegance, power etc.

However, the first quote above raises a concern. My reading of it is that unless you look at the MRI, you don’t know how Ruby is meant to behave, and thus can’t implement it. Frankly, that puts me off the language a bit. I’m all for the agile idea of only documenting when it really adds a benefit, but surely specifying how a language is meant to behave is a real benefit. Now, I know there will always be kinks in languages where sane developers wouldn’t use the corner cases, but those developers who have used them really want them to work on every implementation, but I would hope those can be documented at the same time. Heck, there are plenty of details like that in C#, for instance.

This also answers the second quote I’ve included – what the community can do to overcome the problem of getting Ruby onto the .NET platform. If one of the main problems is that the team can’t look at the MRI source code, and currently the MRI source code is the only way of understanding how an implementation should behave, then surely changing the latter state of affairs would overcome the problem and help the rest of the community at the same time. Microsoft changing its interaction with the open source world would also overcome the problem, but in some ways that’s irrelevant – it in no way stops the community from writing a fully-fledged Ruby spec.

My concern when writing this is that this world is full of very smart people, and Martin’s obviously one of them, so I guess I’ve missed something. I’ve seen that there are some projects to specify Ruby’s behaviour, but if these projects are going well then that should make John Lam’s task more feasible, and if they aren’t then that would call into question either the Ruby community’s desire to see Ruby on .NET or its competence to actually get a spec together. Having watched a small part of the process of getting Groovy adequately specified, I know it’s a lot easier said than done, but even so…

So, what am I missing?