Earlier quoted context omitted.
There's an answer from TypeScript team for your question :) https://twitter.com/drosenwasser/status/1260723846534979584 Basically, > Let's say TypeScript takes over 20 seconds to type-check a medium-sized program. That's not usually because it's JS, it's often because of types that cause a combinatorial explosion. Also > A different runtime can afford a lot (it sounds like parallelism and start-up time in this case)…
Both swc and esbuild claim to be much faster typescript compilers in part because they're written natively, but are actually just "cheating" and not doing any type-checking at all. That's not to say they're useless though, they're good for fast hot-reload as you can have type-checking running in parallel.
TypeScript is surprisingly ok for compilers
151–160 of 245 posts
Re: TypeScript is surprisingly ok for compilers
#152Is that really suprising? Typescript is yet another language that has, kicking and screaming, picked up most of the ML featureset. I'd expect it to be, well, fine; the lack of real pattern matching is a pain, so it's going to be inferior to OCaml, but fine, no different from using C# or Swift or Dart or Kotlin or something of that ilk.
-- a parser function that matches on { ... } returning ...
-- can be combined with other parsers
braces = (symbol "{") `between` (symbol "}")
...
-- a statement is a controlFlow or a declaration or an assignment
statement = controlFlow declaration assignment
-- a block is either 1 or more statements surrounded by { ... }
-- or a single statement.
block = (braces $ many statement) statement
...
-- An expression is a number, or a variable, or a binary operation
-- derive functionality to print and test equality of these values.
data Expr =
Num Int
| Var Variable
| DualOp Op Expr Expr
...
deriving (Show, Eq)
...
foldConstants (DualOp Add (Num a) (Num b)) = Num (a + b)
...
Parser combinators (parser functions that take other parser functions and return more complex combined parser functions) with enough syntactic sugar can express BNF-like grammars directly as code. And ML-style list and pattern matching operations are very expressive for operating on the intermediate representation.Re: TypeScript is surprisingly ok for compilers
#153Earlier quoted context omitted.
I never ever use try/catch in my code. The only time its really necessary is to wrap JSON.parse on use of untrusted input. For everything else it just feels sloppy as through there is insufficient logic in place for handling primary conditions versus edge cases. Also, try/catch will never compile in the JIT.
> Also, try/catch will never compile in the JIT Changing the way you program to fit what a JS compiler does or doesn't do is a fool's errand, IMO. The performance benefits are likely to be minimal, confusion for anyone else who has to touch the codebase is high.
> The performance benefits are likely to be minimal
This makes me cry, but not a cry of joy or ecstasy. People guessing about performance is perhaps the most frequent anti-pattern in all programming. Please read the following document, you can skip to the end but it may not make much sense if you do.
https://github.com/prettydiff/wisdom/blob/master/JavaScript_...
When developers make random performance assumptions, defensive assumptions are worse, it immediately identifies a lack of professional maturity. Its like small children playing games that expand their imagination, which is great for small children but less great for developers pretending to be adults.
Re: TypeScript is surprisingly ok for compilers
#154TypeScript is an incredible language in general. The fact that Functions are Objects that can have properties/methods is supremely undervalued. Are there other languages that do this so nicely? It's the perfect blend of OO and functional. Programming is mostly about gradually figuring out the right design I find. JS/TS let's me evolve things naturally without big rewrites. function foo() {} function bar() {} function…
Everything is an object in Ruby as well
Re: TypeScript is surprisingly ok for compilers
#155Earlier quoted context omitted.
I never ever use try/catch in my code. The only time its really necessary is to wrap JSON.parse on use of untrusted input. For everything else it just feels sloppy as through there is insufficient logic in place for handling primary conditions versus edge cases. Also, try/catch will never compile in the JIT.
For everything with the slightest bit of I/O it is quite practical if you have even the most trivial assumptions about its form. Sure, you can check for everything. It often is more effective, but not prettier or easier to read and of course you also will miss cases.
In that case a message from a network either sends or fails and in the case of sending try/catch does nothing for you but provide an error object, and you don't need try/catch to capture the error. In the case of receiving a network message the message comes in or it doesn't. If the message does come in and is malformed your application should be mature enough to handle that appropriately to the benefit of the user instead of crapping out some error messaging to the console. You don't need try/catch to do any of this. A simple if condition is more than sufficient.
> check for everything
You should check for everything. You only need to check for one thing and if you check for it you are already at 100% of everything. Did you get what you expected: Yes/No?
Re: TypeScript is surprisingly ok for compilers
#156Earlier quoted context omitted.
The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do const c = try { … }
I never ever use try/catch in my code. The only time its really necessary is to wrap JSON.parse on use of untrusted input. For everything else it just feels sloppy as through there is insufficient logic in place for handling primary conditions versus edge cases. Also, try/catch will never compile in the JIT.
If this is an actual concern (as in you have measured and try/catch is actually affecting something performance sensitive): you can most likely mitigate the impact by isolating the try/catch bodies in separate functions.
I haven’t verified this in every JIT, but I saw meaningful perf improvement in V8 for real world degenerate cases where the performance did actually matter and make a significant difference. But seriously, as always, measure before optimizing stuff like this! It might matter, but it seldom will for anything more than academic curiosity.
Re: TypeScript is surprisingly ok for compilers
#157Re: TypeScript is surprisingly ok for compilers
#158Earlier quoted context omitted.
Yeah, having just jumped into ts after a long js hiatus since back when The Good Parts was still surprising, it's quite awesome to see how much of what I assumed to be "ts stuff" is actually just postdeluvian js. Makes ts more attractive, not less. I do wonder however of it was possible to identify parts of that language superset that are fully redundant (as in not even required for exotic edge cases) and let loose s…
You already can kinda do that using ESLint and rules like https://eslint.org/docs/latest/rules/no-restricted-syntax , https://eslint.org/docs/latest/rules/no-restricted-propertie... or https://eslint.org/docs/latest/rules/no-restricted-imports .
Re: TypeScript is surprisingly ok for compilers
#159Earlier quoted context omitted.
>>> Are there other languages that do this so nicely? It's the perfect blend of OO and functional. Python, where everything is an object.
In Python, can typings define a property added to a function? Example, I have some Redux helpers that are functions, but those functions also define a `.actionType` property. TypeScript handles that. edit: accidentally wrote "object" instead of "function"
Re: TypeScript is surprisingly ok for compilers
#160TypeScript is an incredible language in general. The fact that Functions are Objects that can have properties/methods is supremely undervalued. Are there other languages that do this so nicely? It's the perfect blend of OO and functional. Programming is mostly about gradually figuring out the right design I find. JS/TS let's me evolve things naturally without big rewrites. function foo() {} function bar() {} function…