all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: [Emacs-diffs] master 6354e3c: Handle indentation of nested ternary operators in JS
       [not found] ` <20170413005146.2054022EE8@vcs0.savannah.gnu.org>
@ 2017-04-13 19:24   ` Stefan Monnier
  2017-04-13 21:36     ` Davis Herring
  2017-04-13 22:01     ` Dmitry Gutov
  0 siblings, 2 replies; 3+ messages in thread
From: Stefan Monnier @ 2017-04-13 19:24 UTC (permalink / raw)
  To: emacs-devel; +Cc: Dmitry Gutov

> +  isSet
> +    ? (isEmpty ? 2 : 3)
> +    : 4

Not sure about JS, but at least in C, those parentheses are not needed
(so the indentation code should ideally DTRT even in the absence of
parentheses).


        Stefan



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Emacs-diffs] master 6354e3c: Handle indentation of nested ternary operators in JS
  2017-04-13 19:24   ` [Emacs-diffs] master 6354e3c: Handle indentation of nested ternary operators in JS Stefan Monnier
@ 2017-04-13 21:36     ` Davis Herring
  2017-04-13 22:01     ` Dmitry Gutov
  1 sibling, 0 replies; 3+ messages in thread
From: Davis Herring @ 2017-04-13 21:36 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Dmitry Gutov, emacs-devel

>> +  isSet
>> +    ? (isEmpty ? 2 : 3)
>> +    : 4
>
> Not sure about JS, but at least in C, those parentheses are not needed

JavaScript and C have the same ?: parsing.  Moreover, I think even PHP 
would get that one right without parentheses, because grouping the first 
? and : and the second ? and : would be self-intersecting.

(What PHP gets wrong is

   !isSet ? 4 : isEmpty ? 2 : 3

which it, unlike all sane languages, parses as

   (!isSet ? 4 : isEmpty) ? 2 : 3

aka

   !isSet || isEmpty ? 2 : 3

which is rarely what was intended.)

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or 
too sparse, it is because mass-energy conversion has occurred during 
shipping.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Emacs-diffs] master 6354e3c: Handle indentation of nested ternary operators in JS
  2017-04-13 19:24   ` [Emacs-diffs] master 6354e3c: Handle indentation of nested ternary operators in JS Stefan Monnier
  2017-04-13 21:36     ` Davis Herring
@ 2017-04-13 22:01     ` Dmitry Gutov
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Gutov @ 2017-04-13 22:01 UTC (permalink / raw)
  To: Stefan Monnier, emacs-devel

On 13.04.2017 22:24, Stefan Monnier wrote:
>> +  isSet
>> +    ? (isEmpty ? 2 : 3)
>> +    : 4
> 
> Not sure about JS, but at least in C, those parentheses are not needed
> (so the indentation code should ideally DTRT even in the absence of
> parentheses).

You're right, it's the same in JS. Luckily, most programmers don't feel 
comfortable leaving the inner group without parentheses (so the reporter 
went away satisfied).

Not exactly sure what logic to use to support the paren-less case, so 
patch welcome!



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-13 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20170413005145.27131.34535@vcs0.savannah.gnu.org>
     [not found] ` <20170413005146.2054022EE8@vcs0.savannah.gnu.org>
2017-04-13 19:24   ` [Emacs-diffs] master 6354e3c: Handle indentation of nested ternary operators in JS Stefan Monnier
2017-04-13 21:36     ` Davis Herring
2017-04-13 22:01     ` Dmitry Gutov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.