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


Groups > comp.lang.javascript > #32145 > unrolled thread

Re: How bad is my hack?

Started byScott Sauyet <scott@sauyet.com>
First post2017-01-08 23:02 +0000
Last post2017-01-08 23:02 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.javascript

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#32145 — Re: How bad is my hack?

FromScott Sauyet <scott@sauyet.com>
Date2017-01-08 23:02 +0000
SubjectRe: How bad is my hack?
Message-ID<o4ugdo$rr5$1@dont-email.me>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web