Self-returning methods

August 15, 2006

I was reading a post titled Avoid a void at http://codeforfun.wordpress.com/ on the subject of using self-returning methods in an API. A very good and informative read (the author has quite a humorous writing style too).

There was a comment on the post linking to an article called Java theory and practice: Enable initialization atomicity at IBM developer works. This is a more detailed article on self-returning methods or ‘the self-return idiom’ complete with examples and is very well written.

Something to consider when designing methods as not only can it improve your own readability it can also be very productive as represented by the single statement examples (no temporary variables).

Advertisements

2 Responses to “Self-returning methods”

  1. Cliff Says:

    Careful because there’s also a good reason why you shouldn’t avoid a void:
    http://codeforfun.wordpress.com/2006/08/14/why-you-shouldnt-avoid-a-void/

  2. elevate Says:

    Interesting, thanks for the tip!


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: