Thursday, December 29, 2005

Fluent Interfaces

I'd like to add to Paul's and Mike's posts regarding fluent interfaces.

I very much agree with them that this kind of method chaining allows to create very readable and intuitive interfaces. The million dollar question is when to actually use this kind of programming style.

Of course there are no definitive answers but I suggest to consider the following points:
a) Use your intuition. If you don't feel this will address the 95% of common use-case for using your interface, then it's probably not the right solution for what you're trying to accomplish.
b) As Paul noted, if in the common use-case you don't have all the necessary data available to complete the task in one go, you should think twice about doing it.
c) Probably the most important point: It really has to read well in your language (e.g. English), preferably as a complete sentence. If you can't read the code out aloud then it's probably not what you want. This is a good example of what I think reads well:

$sms->to("1650939202")
->
from("14082924021")
->
message("Will meet you at 8pm")

->
send()
;

d) You will usually want some form of error handling for your code. This kind of syntax pretty much forces you to use exception based error handling. Make sure that this suits your needs and application architecture.

Do you have any other suggestions for guidelines? I'd be happy to hear them.

Wednesday, December 28, 2005

MAC OS X - Update

Quick update for those who were interested in a Windows clone of MAC OS X Expose .
Although I mentioned Winplosion in my previous blog entry, I found there are lots of different solutions out there. I ended up purchasing http://www.entbloess.com which isn't perfect, but it seemed to be the best and most stable of the bunch. It's only $8 so worth buying if you find it usefull.

Friday, December 23, 2005

MAC OS X - Am I ready to make the move?

I've pretty much always been using Windows (on the desktop), and never found a compelling reason to move to another operating system.
That said, over the past few years I have noticed an increasing number of MAC OS X notebooks present at PHP conferences, which intrigued me and has kept me interested in where the MACs are heading.
No doubt that there are some compelling reasons to move to a MAC.
For me as a developer, one of the biggest reasons would be having a UNIX development environment natively side-by-side to the desktop environment. Although VMWare is an amazing tool, and I'm a big fan of it, booting and running it, is not always natural, and half the time I actually prefer to SSH into a remote server on the Internet as opposed to powering up VMWare.
Another compelling reason for the MAC is the slick GUI. I have always been especially jelous of the cool F9 Expose feature. Yeah you could say it's a minor detail, but when you have lots of apps running, alt-tab is a real headache, especially when some of those apps are the same (like many firefox instances). I finally found a cure for that called WinPlosion (http://www.winplosion.com/). Although it's not quite as sexy as the MAC solution, it's pretty cool, very lightweight and slick. If you're a Windows user, give it a try.
So where does that leave me? I guess for me personally, the achilles heel of the MACT is that there's no chance in the world that I'll ever get used to a TouchPad. I just can't deal with it. The Thinkpad TrackPoint (a.k.a nipple) is probably the main reason why I'll continue using Thinkpad's. If/when Apple ever adopts it, then I believe I'll be ready to make the move. And as at that time, MACs will be running on x86, I believe there'll be even more of a reason to make the move.