4 ms·
IMHO, the "turbofish" syntax (popularized by Rust) is ugly and should not be used. The reasoning of syntax ambiguity is also a lame one because C# manages just
by colejohnson66 4y ago
IMHO, the "turbofish" syntax (popularized by Rust) is ugly and should not be used. The reasoning of syntax ambiguity is also a lame one because C# manages just fine without it. But to then say that:
> The above syntax is already valid JavaScript that users may rely on, so we cannot use this syntax as-is.
What users would be using said syntax? Why would one compare a function to a type? If we're making a backwards incompatible change, just say that `func < type` is a syntax error unless immediately followed by the rest of a call. IMO, in any spec committee, if a naysayer says that "someone may be using that syntax", they should be required to prove it. Prove that someone is comparing a function to be less than a type, and why they'd do such a thing.
Honestly, I don't see how this can be done in a backwards compatible way short of type annotations in comments. Just rip the bandaid off and have WHATWG say that TypeScript is a valid runtime and allow `<script src="..." type="typescript">`. Deno manages to have a TypeScript runtime just fine.
- codethief 4y ago> What users would be using said syntax? Why would one compare a function to a type? Possibly the people behind JSFuck and derivatives. :)
- crooked-v 4y ago> Why would one compare a function to a type? Aggressively minified and optimized JS code results in all sorts of weird things.
- colejohnson66 4y agoSure, but if a minifier/optimizer wants a “truthy” value, they can just use “1”. It’d be a pretty bad minifier if it turned something needing a truthy value into anything more than that. Unless one can find some minifier producing said example, it’s a bad argument.
- jffry 4y agoIt's essentially unknowable if anybody has produced code out there that is like this, but the point still stands that it is valid code. If you want to uphold a commitment to backwards compatibility, you simply cannot extend your language in a way that might possibly change the behavior of valid-but-nonsensical code in the wild.
- runarberg 4y agonumber is a type but also a valid identifier, so you can do things like: const number = 5; function fn(number: number): number That means that we can’t always know whether we mean the type or the constant when we type: a<number>(b)
- dnsco 4y agoThe turbofish resolves a bunch of syntax ambiguities[1]. Apparently C++ parsing is undecidable, so building an AST requires arbitrary template instantiation (and C++ templates are turing complete). The turbofish is a compromise that allows the parser to stay simple. I know there were efforts to remove it, but it appears to be here to stay. https://github.com/rust-lang/rust/blob/master/src/test/ui/parser/bastion-of-the-turbofish.rs https://github.com/rust-lang/rust/blob/master/src/test/ui/pa...