Re: Exponentiation operator precedence

2015-08-27 Thread Nathan White
Anecdotal evidence via a quick github search
https://github.com/search?l=JavaScriptp=1q=Math.pow+language%3AJavaScript+extension%3Ajsref=advsearchtype=Codeutf8=%E2%9C%93

A significant number of the usages are unit tests. Many others are repeats
from popular libraries like D3.

The most extreme use case I could find:
y4ashida/ika/blob/master/js/culc_dence.js
https://github.com/y4ashida/ika/blob/master/js/culc_dence.js



On Thu, Aug 27, 2015 at 11:19 AM, Steve Fink sph...@gmail.com wrote:

 On 08/27/2015 09:25 AM, Dean Tribble wrote:

 Ideally syntax proposals should include some frequency information to
 motivate any change. Is there an easy search to estimate the frequency of
 Math.pow? In my application codebase (financial app with only modest JS
 use), there are very few uses, and there are as many uses of Math.sin as
 there are of Math.pow.


 Frequency relative to what, though? If code that does nontrivial math is a
 very small proportion of total JS code, and yet the exponentiation operator
 makes that code much more readable, then what is the conclusion? I would
 argue that ** precedence confusion is irrelevant to code that isn't going
 to use Math.pow in the first place. So it's a question of whether ** is a
 big enough readability win in code that computes exponents.


 Anecdotally, my eyes caught on: -Math.pow(2,-10*a/1) (from a charting
 library) which makes me not want to have to review code where I'm worried
 about the precedence of exponentiation.


 I'd have to write that out: -2**(-10*a/1). That doesn't seem too bad.

 For myself, I do very much prefer Math.sqrt(a**2 + b**2) to
 Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)). The verbosity and uneven
 density of notation is really bothersome -- for any equation like the
 second one, I guarantee that I'll rewrite it on paper to figure out what
 it's saying. (Ok, maybe not for that specific formula, but even there I'll
 mentally render it.) I would not need to do so with the first one. Jumping
 between prefix and infix is jarring.

 Then again, I could make the same argument for Math.sqrt(a**2 + b**2) vs
 (a**2 + b**2) ** 0.5. And I don't like the second one much. But people
 don't interchange those when handwriting formulas, either.

 Math.sqrt(a.pow(2) + b.pow(2)) is an interesting middle point. I initially
 thought it struck the right balance, but seeing it written out, it still
 looks far inferior to me.

 A more complex example might help:

   a * (b - a)**(x - 1/2 * (b - a)**2)

 vs

   a * Math.pow(b - a, x - 1/2 * Math.pow(b - a, 2))

 vs

   a * (b - a).pow(x - 1/2 * (b - a).pow(2))

 For me, the middle one is a mess. I can't make sense of it, and I can't
 spot the common (b - a) expression at all. The first one is as readable as
 such formulas ever are when written out with ASCII text. The third one is
 somewhere in between. I can see the common (b - a), and perhaps if I got
 more used to seeing .pow I could mentally make use of it without writing it
 on paper, but for now I cannot. Part of the problem is that I can easily
 translate x**2 into x squared, but x.pow(2) is raising x to the power
 of 2.


 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss


Re: Existential Operator / Null Propagation Operator

2015-04-07 Thread Nathan White
Am I crazy to think that Nil could allow the Existential Operator to be
used in assignments as well?

var a = undefined;
a?.b?.c?.d = 1;
console.log(a); // {b: {c: {d: 1}}}

Too powerful / abusive?



Day dreaming, use U+02D9 (DOT ABOVE) as the operator.

a˙b˙c.d



On Tue, Apr 7, 2015 at 1:09 PM, Herby Vojčík he...@mailbox.sk wrote:



 Kevin Smith wrote:


   Plus, it can be used for normalizing null/undefined to undefined:
  
var normalizedFoo = ?foo;
  
   Seems sort of nice that it is separated and there are no special
 operations for ?., ?(, ?[.

 I agree, that is nice.  But how does Nil get transformed into undefined?


 While you do operations like call, construct, get on the reference
 (obtaining another reference), it shortcuts to return Nil. Whenever you are
 not in position to shortcut ref-to-ref (end of expression, for example),
 and you actually needs a value, it just converts to undefined.

 ?a.b()['foo'] = smalltalk-like
   'a' asRefIn: env) nilRefIfValueNullOrUndefined ref, may be nil
   at: 'b') returns ref, may be Nil
   callWithArguments: #()) returns ref, may be Nil
   at: 'foo') returns ref, may be Nil)
   value now, value is needed, ref needs to dereference

 Hopefully this sheds some light. If not, then I don't know how to explain
 it someone with better pedagogy skill must weight in.

 ___
 es-discuss mailing list
 es-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es-discuss

___
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss