Using `this` as a return value.

1 view
Skip to first unread message

Samuel Lebeau

unread,
Dec 14, 2008, 11:21:25 AM12/14/08
to PDoc
What do you guys think of using `this` as return value for methods
which actually returns their receiver.
It could avoid confusion with methods returning an instance of the
same class.
i.e. `Array#clear() -> this` vs. `Array#without(value...) -> Array`

Tobie Langel

unread,
Dec 14, 2008, 12:43:09 PM12/14/08
to pd...@googlegroups.com

Sounds like avoid idea.


On Dec 14, 2008, at 17:21, Samuel Lebeau <samuel...@gmail.com>
wrote:

Tobie Langel

unread,
Dec 14, 2008, 3:52:44 PM12/14/08
to pd...@googlegroups.com
Sorry for the iPhone-induced typo. This should have of course read:

Sounds like a good idea.

On Dec 14, 2008, at 18:43, Tobie Langel <tobie....@gmail.com> wrote:

>
> Sounds like avoid idea.
>>
>>

dandean

unread,
Feb 7, 2009, 12:23:39 AM2/7/09
to PDoc
In away, this seems more clear to me:

Array#clear() -> self

Since "this" is context-specific and can theoretically be thrown
around at will through binding. Also, "self" sounds (to me!)
semantically more accurate, as it is returning itself.

I'd be fine with either; they're both more clear than the current
implementation.




On Dec 14 2008, 12:52 pm, Tobie Langel <tobie.lan...@gmail.com> wrote:
> Sorry for the iPhone-induced typo. This should have of course read:
>
> Sounds like a good idea.
>

Tobie Langel

unread,
Feb 7, 2009, 8:35:53 AM2/7/09
to pd...@googlegroups.com
The problem with self is that it's also a global alias for the window
object.

dandean

unread,
Feb 7, 2009, 7:59:40 PM2/7/09
to PDoc
Good point! I had totally forgotten about that.



On Feb 7, 5:35 am, Tobie Langel <tobie.lan...@gmail.com> wrote:
> The problem with self is that it's also a global alias for the window  
> object.
>
Reply all
Reply to author
Forward
0 new messages