• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Fluent Interface"?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "Fluent Interface"?


  • Subject: Re: "Fluent Interface"?
  • From: Marcel Weiher <email@hidden>
  • Date: Sat, 4 Aug 2007 14:48:50 -0700


On Aug 3, 2007, at 9:06 AM, Bill Bumgarner wrote:

And, now, what I believe to be the Gem in all of this:

Be explicit when writing Cocoa -- or any other -- code.

Absolutely! But be very choosy about what you are explicit about.

Don't use character saving shortcuts -- they'll just create extra work in debugging.

Don't think you can write a hard to read expression that'll somehow compile down to faster code. More likely than not, the compiler's optimizer will do something far faster -- and far more perverse -- than you can and any efforts to do otherwise just makes the compiler's job harder while complicating later debugging and maintenance efforts.

-> actually, gcc can do next to nothing with Objective-C code, at least with the parts that are actually costly.


Complexity, obscurity, subtlety, and brevity are not a signs of 733t k0ding skillz!!1!!one!

Fluent interfaces are not (at all / in the least / in any way, shape or form) about:


- character savings
- being clever
- faster-to-type code
- faster-to-run code
- complexity, obscurity, subtlety

They are about the exact opposite: achieving simplicity and clarity by being explicit about the things you care about, the point of the code, and implicit about as much chaff that distracts from what the code is about as possible. This is called expressiveness, and generally considered A Good Thing™ (it's also the end-result of good factoring and why we have higher level programming languages in the first place)

Piers Crawly has a very good writeup at:

	http://www.bofh.org.uk/articles/2005/12/21/fluent-interfaces

Three highlights:

1. creating fluent interfaces is really, really hard
2. if you get it right, you can make your API look like syntax (best example: Smalltalk's #to:do: ) -> 1 to:10 do: [ :i | stdout println:i].
3. good names are absolutely crucial


This certainly reflects my experience with Higher Order Messaging: it is a struggle, but when you get it 'right', it's gold.

For example, I'd much rather write:

		[[self async] runInteractiveLoop];

than

[NSThread detachNewThreadSelector:@selector(runInteractiveLoop) toTarget:self withObject:nil];

despite that both are just one line of code. I do not think the HOM example is more obscure, quite the opposite, it makes it much clearer what the intent is, whereas you have to dig for it otherwise, just like with the next example:

		[[delegate ifResponds] windowDidBecomeMain:self];

vs.

		if ( [delegate respondsToSelector:@selector(windowDidBecomeKey:)] ) {
			[delegate windowDidBecomeMain:self];
		}


Your mileage may vary,

Marcel

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >RE: [OT] "Fluent Interface"? Welcome to NeXT (From: Jeff Laing <email@hidden>)
 >Re: [OT] "Fluent Interface"? Welcome to NeXT (From: Bill Bumgarner <email@hidden>)

  • Prev by Date: Secure-Text-Field-Like Field Editor Initialization
  • Next by Date: offtopic: best way of plainng overall structure of programs/functions etc.
  • Previous by thread: Re: [OT] "Fluent Interface"? Welcome to NeXT
  • Next by thread: Re: [OT] "Fluent Interface"? Welcome to NeXT
  • Index(es):
    • Date
    • Thread