Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20041
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: !0 versus true |
| Date | 2013-05-29 17:33 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <labcq81vnpm51ide8rsq6he340s8ukpi28@4ax.com> (permalink) |
| References | (3 earlier) <ed180bb2-f6be-48dc-941a-adb647bd9b6c@h5g2000vbg.googlegroups.com> <5260436.L7RB4VL119@PointedEars.de> <eba22a46-75ad-4d8f-8cf3-e1dfbaa28743@c7g2000vbv.googlegroups.com> <uaf9q855bh9uri9q6o10oa2oqi7n6lp3r7@4ax.com> <025995e5-77c4-42e0-9c2d-60607ed970e9@2g2000yqr.googlegroups.com> |
On Tue, 28 May 2013 08:32:39 -0700 (PDT), Scott Sauyet <scott.sauyet@gmail.com> wrote: >John Harris wrote: >> Scott Sauyet wrote: >> <snip> >>> <http://scott.sauyet.com/Javascript/Demo/2013-05-27a/> >>> <http://scott.sauyet.com/Javascript/Demo/2013-05-27b/> >>> >>> In all browsers I tested, the programs displayed different behavior, >>> even though the two programs are identical except that one expression >>> has been replaced by an equivalent one in the second. >> <snip> >> >> Name the functions in the two examples f and g to lessen the >> confusion. > >That would only confuse the point. The point is that the only >difference between the two programs is the substitution of `0` in the >second for the equivalent `+!1` in the first. Nonetheless the two >programs have different behavior. Making an additional change by >changing the name of the function would muddy the waters. I'm surprised that you, "a mathematician by training", didn't realise that g is used as an alias for the purpose of this discussion. Alternatively, I'm surprised that you, as someone who knows something about javascript, hadn't assumed that var g = f; has been added in one of the examples. >> You are saying that when f() and g() are 'equivalent' expressions >> then f.toString() should be 'equivalent' to g.toString() for >> equivalence to be a useful concept. > >Not at all. > >The real point is that the equivalence of expressions is less useful >in Javascript than in many other languages. Automatic minification >based upon it can break programs that take advantage of this weird >quirk of the language. Perhaps the only answer is Thomas' assertion >that, "ECMAScript programs which rely on function serialization are >deeply flawed." But this does mean that automated minification can >possibly wreak havoc with certain code. Your argument applies to any language that can allow read access to the executing code : the .exe file or whatever. E.g programs that do a sumcheck of themselves at startup. Also, programs that have access to a stack trace. And for function calls, it applies to any functions that have externally visible side effects. This doesn't make "equivalent expressions" useless, merely that care is needed in using equivalence. E.g in ECMAScript you can't replace 1 by 0 + 1 in some circumstances, even if you can replace it by (0 + 1). >> Why? After all, you wouldn't expect the expressions f and g to be >> the same : they evaluate to references to different function objects. >> These objects can be given different properties by the program without >> changing the values returned by f() and g(). > >I'm of the opinion that there is no clear safe way to automatically >refactor arbitrary Javascript code. I believe that for any automated >mechanism, some clever coder could write a program that would be >broken by it. Yet people do modify functions to clean them up and expect there to be no change in the program's behaviour. Even people who know enough to be careful. I agree that automatic minifying/refactoring mustn't be done if the programmer(s) have written certain kinds of pathological code. But this is true in practically any programming language. >The ability to reach within the source code makes me >thing nasty things about Kurt Gödel. :-) <snip> Unfair to Kurt! John
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
!0 versus true Andrew Poulos <ap_prog@hotmail.com> - 2013-05-23 23:31 +1000
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-23 07:58 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-23 17:53 +0200
Re: !0 versus true Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-24 12:17 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-24 21:56 +0200
Re: !0 versus true Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-05-24 13:13 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-24 22:23 +0200
Re: !0 versus true Denis McMahon <denismfmcmahon@gmail.com> - 2013-05-24 22:08 +0000
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-25 07:00 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-25 20:04 -0700
Re: !0 versus true "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-05-26 11:07 +0200
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-26 13:11 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-26 13:28 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-27 12:07 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-27 11:27 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-27 23:30 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-27 17:12 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-28 02:40 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-27 20:29 -0700
Re: !0 versus true John Harris <niam@jghnorth.org.uk.invalid> - 2013-05-28 15:38 +0100
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-28 08:32 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-28 21:14 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-28 15:38 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-29 13:20 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-29 06:37 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-29 16:28 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-29 13:32 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-29 23:34 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-30 06:30 -0700
Re: !0 versus true John Harris <niam@jghnorth.org.uk.invalid> - 2013-05-29 17:33 +0100
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-29 11:34 -0700
Re: !0 versus true John Harris <niam@jghnorth.org.uk.invalid> - 2013-05-31 10:22 +0100
Re: !0 versus true Christoph Becker <cmbecker69@gmx.de> - 2013-05-31 13:04 +0200
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-31 18:13 +0200
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-31 18:16 +0200
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-05-31 07:25 -0700
Re: !0 versus true imma harper <immaterial_uk@yahoo.co.uk> - 2013-05-31 09:46 -0700
Re: !0 versus true Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-05-31 21:38 +0200
Re: !0 versus true John Harris <niam@jghnorth.org.uk.invalid> - 2013-06-01 17:37 +0100
Re: !0 versus true Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-06-02 21:03 +0100
Re: !0 versus true Scott Sauyet <scott.sauyet@gmail.com> - 2013-06-03 04:45 -0700
Re: !0 versus true Dr J R Stockton <reply1300@merlyn.demon.co.uk.invalid> - 2013-06-04 17:23 +0100
csiph-web