Object.seal, read references, and code reliability
alexkodat at gmail.com
Tue Aug 15 17:48:24 UTC 2017
Of course, testing is absolutely critical. Programmers rereading their own code, code reviews, hiring good programmers, coding standards. All good things. I'm under no illusions that Object.guard would be sufficient to keep the world safe from bad code. It would just be another arrow in the quiver.
Object.guard would augment tests by making sure the an if (foo.bah) (should be foo.bar) throws rather than simply bypasses the if condition. Yes, of course you should make sure your tests would detect that the if condition wasn't exercised when it should be but well... heat of battle.. etc... Coverage tools are also, of course a good thing though they might not help if your mistake was if (!foo.bah). Coding's complicated and the more weapons you have the better as long as you're not forced to use them and as long as they don't needlessly complicate the language.
From: Jordan Harband [mailto:ljharb at gmail.com]
Sent: Tuesday, August 15, 2017 12:22 PM
To: T.J. Crowder <tj.crowder at farsightsoftware.com>
Cc: Alex Kodat <alexkodat at gmail.com>; es-discuss at mozilla.org
Subject: Re: Object.seal, read references, and code reliability
An alternative suggestion to catch mistyped properties is "automated tests", which hopefully you have anyways.
On Tue, Aug 15, 2017 at 8:38 AM, T.J. Crowder <mailto:tj.crowder at farsightsoftware.com> wrote:
On Tue, Aug 15, 2017 at 4:10 PM, Alex Kodat <mailto:alexkodat at gmail.com> wrote:
> But, now that I think about it, we might Object.guard them as it
> would catch the occasional boo-boo where one forgets to put the
> () on a function call
How would `Object.guard` catch that? My understanding of your suggestion was that reading a property from a "guarded" object that it didn't have (`"propname" in obj` would be false) would throw. If you do `foo.bar` where you meant `foo.bar()`, the `bar` property still exists on `foo`.
-- T.J. Crowder
More information about the es-discuss