On Sun, Jun 11, 2017 at 1:29 AM, Martin Schreiber <mse00...@gmail.com> wrote:
>> You need to have a return. If you have a object with a method "exec",
>> eg, why not return the object itself? Just return something.
>
> Why?

Because you could write a more elegant code.
If you return "self" even in methods that don't need to specify a
return, you can codify using a style more declarative instead of a
procedural style.

Instead of this:
---
obj.exec;
obj.foo;
obj.bar;
---

We can do this:
---
obj.exec.foo.bar;
---

Looks nothing, but imagine that you give a instance from another object.
If these methods (exec, foo, and bar) do not return "self", you need
to declarate a variable — or use "with".

So:
---
obj := x.getAnObject;
obj.exec;
obj.foo;
obj.bar;
---

But if you return "self":
---
x.getAnObject
  .exec
  .foo
  .bar;
---

Best regards,
Marcos Douglas

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk

Reply via email to