Fwd: Proposal: Static Typing

guest271314 guest271314 at gmail.com
Thu Mar 28 00:20:06 UTC 2019


---------- Forwarded message ---------
From: guest271314 <guest271314 at gmail.com>
Date: Thu, Mar 28, 2019 at 12:19 AM
Subject: Re: Proposal: Static Typing
To: Claude Pache <claude.pache at gmail.com>



> `a = object[Math.random() < 0.5 ? "method_returning_number" :
"method_returning_string"]()`

Interesting case. See also

How do I check if a JavaScript function returns a Promise?
> <https://stackoverflow.com/q/43416214>

Say I have two functions:
> ```function f1() {
>     return new Promise<any>((resolve, reject) => {
>         resolve(true);
>     });
> }
> function f2() {
> }```
> How do I know if f1 will return Promise and f2 will not?


Can a regular expression be crafted which determines the return type of a
function? <https://stackoverflow.com/q/43417236>

Has it been mathematically proven that antivirus can't detect all viruses?
<https://security.stackexchange.com/q/201992>

On Wed, Mar 27, 2019 at 6:10 PM Claude Pache <claude.pache at gmail.com> wrote:

>
>
> Le 27 mars 2019 à 18:26, Michael Theriot <michael.lee.theriot at gmail.com>
> a écrit :
>
> Would an error at runtime or compiletime occur here?
>
>
> The check cannot be reliably done at compile time in general; it must be a
> runtime check. (Tools may provide partial static analysis, but that’s an
> extra.)
>
> The simplest reason is that statically typed code must run together with
> non-statically typed code.
>
> And even ignoring legacy code, it is not desirable to have static types
> everywhere; for instance, `Array.prototype.sort()` must continue to work
> with both arrays of strings and arrays of numbers, and even with arrays of
> mixed types.
>
> And even if everything everywhere was statically typed, you still cannot
> statically analyse situations like: `a = object[Math.random() < 0.5 ?
> "method_returning_number" : "method_returning_string"]()`.
>
> If it is a runtime error, is it optimal for the engine to keep track of
> typed variables vs regular for the same value?
>
>
> Today’s JS engines typically do already clever speculative optimisations
> based on expected types. For example: https://stackoverflow.com/a/46144917.
> So, I guess, it depends...
>
> —Claude
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190328/7d3ec175/attachment-0001.html>


More information about the es-discuss mailing list