Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #32145

Re: How bad is my hack?

From Scott Sauyet <scott@sauyet.com>
Newsgroups comp.lang.javascript
Subject Re: How bad is my hack?
Date 2017-01-08 23:02 +0000
Organization A noiseless patient Spider
Message-ID <o4ugdo$rr5$1@dont-email.me> (permalink)
References <hack-20170108182735@ram.dialup.fu-berlin.de>

Show all headers | View raw


Stefan Ram wrote:

> event => alert( event.cancelable, event.preventDefault() )
> 
>   Explanation: I want to show the value of »event.cancelable«, and
>   prevent the default handling for the event, but was too lazy to open a
>   block and write
> 
> event => { alert( event.cancelable ); event.preventDefault(); }
> [ ... ]
>
>   How bad is this hack?
> 
>   [X] The maintenance programmer will not understand your
>       intentions.

Perhaps this comes from my perspective on a large team with a 
heterogeneous mix of developer abilities, but that strikes me as a silly 
way to save a few characters at the expense of readability.

Especially because the first parameters is a property of `event`, it 
could easily be difficult to notice that the second one involves a tiny 
little pair of parentheses to actually *call* the function referred to by 
a second property.  So we have one possible confusion.

A second one is that if the maintainer *does* notice this, her first 
inclination might be to try to figure out what `preventDefault` returns 
(nothing, IIRC) and how that second parameter would then affect the 
behavior of `alert`.

In other words, unless the maintainer immediately recognizes this for a 
ridiculous bit of cleverness, which might or might not be worth her time 
to refactor out, you've wasted her time trying to understand it.  She 
hasn't learned anything useful from it, and you've done no more than save 
a handful of characters.

I am not opposed to somewhat tricky constructs in general.  If they 
manage to express something useful in a concise way, it might be worth 
the time for the maintainer to figure them out and learn from them, but 
there is nothing useful to learn from here.

  -- Scott

Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread


Thread

Re: How bad is my hack? Scott Sauyet <scott@sauyet.com> - 2017-01-08 23:02 +0000

csiph-web