(Map|Set|WeakMap)#set() returns `this` ?

Bill Frantz frantz at pwpconsult.com
Wed Dec 5 19:33:23 PST 2012


On 12/5/12 at 1:50 AM, jussi.kalliokoski at gmail.com (Jussi 
Kalliokoski) wrote:

>I personally think returning `this` in absence of any meaningful value (and
>chaining in general) is a bad pattern.

</lurk>

I have to agree with Jussi here. Whenever I consider chaining 
using the returned values from the various things called, my 
programming paranoia hair stands on end. Let me try to explain:

Whenever I program, I try to trust as little code as possible. 
With chaining, there are two possibilities for getting the wrong 
answer in the returned value:

   * I or someone else wrote it, but screwed up,
   * Someone hostile wrote it and is trying to trip me up.

If there is a language construct that allows chaining -- like 
the Pascal "with" construct -- then I am only trusting the 
language*, not other fragments of programs. If I depend on 
things I call returning the correct "this", then I am depending 
on them and my dependency set is a lot larger. A larger 
dependency set makes me nervous.

Cheers - Bill

* For the really paranoid, minimizing the parts of the language 
depended on is important. Not all JS implementations behave the 
same way in the corner cases.

<lurk>

-----------------------------------------------------------------------
Bill Frantz        |Security, like correctness, is| Periwinkle
(408)356-8506      |not an add-on feature. - Attr-| 16345 
Englewood Ave
www.pwpconsult.com |ibuted to Andrew Tanenbaum    | Los Gatos, 
CA 95032



More information about the es-discuss mailing list