Status/Thoughts on Guards?
See also disnetdev.com/blog/2011/08/23/Contracts.coffee-Contracts-For-JavaScript-and-CoffeeScript and research.microsoft.com/apps/pubs/default.aspx?id=224900
I am a fan of making it notationally easier to inject runtime validation of some sort, whether starting from guards or from either of the approaches above.
From discussions at TC39, it is clear that any such proposal would be a long fight. I don't know that anyone is willing to invest the time needed to lead that fight. I know I'm not -- it is unlikely to bubble to the top of my priority queue.
+1 for research.microsoft.com/pubs/224900/safets.pdf ... some really good research. As Mark said, though, it's more likely we'll get a fight than anything productive from such a conversation, which is quite unfortunate :( .
Jonathan Barronville wrote:
+1 for research.microsoft.com/pubs/224900/safets.pdf ... some really good research.
Yes, it's good.
As Mark said, though, it's more likely we'll get a fight than anything productive from such a conversation, which is quite unfortunate :( .
Best thing already happening is TypeScript with its embrace-and-extend approach to JS. I'm sure Anders et al. are tracking TS* and Safe TypeScript, so I expect we'll see fruits of the MSR work in product soon enough.
This then has a shot of making a cowpath for TC39 to pave. It's not as long as a shot, done via TypeScript + JS evolution, as the alternative you and Mark point to: a big a priori type systems fight in TC39. Who wants that?
Alternatives include pluggable annotation syntax, or an evolution of Dart (Ecma TC52) + JS, but these look less likely to me to go into Harmony-era JS at the moment. Dart diverged too much, and pluggable syntax is a cop-out.
Just to throw another example out there, here's a Design by Contract library which squeezes itself within existing ES syntax - codemix/contractual
These are all great examples and resources. Thanks everyone.
Not exactly the same but the Closure Compiler has a "runtime type check" mode that inject type checks. If you write jsdoc type annotations already this can be an low resistance path but its usefulness depends on the accuracy of those annotations.
I've been spending time lately writing a lot of repeated validation code for function parameters and using popular object schema validation libraries like Joi (hapijs/joi) which led me to re-reading and thinking about strawman:guards ( strawman:guards.
I'm curious what TC39 and the es-discuss' current thoughts and attitudes towards guards is at the moment.
They seem to come up every once in a while in TC39 notes, but usually only through a tangential mention followed by a mix of "that would eliminate the possibility of guards," "guards could work," "let's talk about something else (not guards)."
I see that Dave Herman seems to have some opinions on guards and obviously Waldemar has ideas (given his activity on the straw man). Anyone else?