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).

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

You must be logged in to post a comment.