PROPOSAL: Return 'this'

Stefan Schulz schulz at e-spirit.de
Thu Mar 26 14:55:51 PDT 2009


As it happens, I have written about some "with" a while ago, that might 
have advantages to returning this (and surely pitfalls and 
disadvantages). The main idea is to have a block on an object that 
shifts the binding of this to the object itself (as the with being 
proposed here). There is also an alternative by Howard Lovatt, which is 
referenced in my post at:
http://jroller.com/jadda/entry/support_for_operating_on_a

My idea reuses the "do" keyword:

object do {
   method1();
   method2();
   method3();
};

It also proposes the block to result in the object itself:

String str = new StringBuilder() do {
   append(person.getName());
   if (person.isMarried()) {
     append("(married)");
   }
}.toString();

Instead of blocks, one could think of using expressions as proposed by 
Neal Gafter in an earlier post.
Though, I think this might be too big for Coin.

Stefan

Reinier Zwitserloot schrieb:
> That argument makes no sense. If you're concerned about lines, try:
> 
> with (object) { method1(); method2(); method3(); }
> 
> 
> If your coding style guide says that you must neccessarily newline 
> after braces and semicolons, then you should question why that rule 
> exists, and why it would not exist for the builder pattern.
> 
> Incidentally, I like a return this proposal more, because I think it's 
> lower impact (no new keyword, we're already familiar with methods that 
> return themselves, a complete proposal would just enshrine this 
> practice into canon), and looks better. Just saying that 'number of 
> lines' is not a valid argument against.
> 
>   --Reinier Zwitserloot
> 
> 
> 



More information about the coin-dev mailing list