Live data from Hacker News

TypeScript is surprisingly ok for compilers

matklad.github.io

11–20 of 245 posts

Re: TypeScript is surprisingly ok for compilers

#11
post #9

it isn't, i have codebase in golang that is much larger than typescript and it is pleasant to work with lsp and compiles smoothly. With typescript i have to turn off lsp and even after that it takes long time too compile. There is a reason why people are writing typescript compiler in rust.

He's talking about compilers for small languages. The Typescript LSP works fine on very big projects like VSCode so I think you'd need an enormous language like C++ or Rust before you'd run into those limits. But still, I think I'd rather use Rust. I'm pretty sure the code would be nicer (e.g. no need for the explicit tag field or for the visitor hack).

The author is no stranger to rust (he’s creator of rust-analyser). The reason why he’s pitching typescript here is due to its high level nature and doesnt have to deal with memory management, low level integer types etc.

Re: TypeScript is surprisingly ok for compilers

#12
post #2

Is 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.

That's some very high level view - in reality even tough those languages are in similar categories the experience would be vastly different :

TypeScript - powerful type system but shit underlying stdlib and language (no pattern matching/switch expressions)

Dart - worse than TS because the object model is closed - so no dynamic freedom, but the type system and expressions are weaker then the rest. Also 0 meta programming facilities - Java level of boilerplate and code generators

C# - closest to ML featureset out of the mentioned, but unlike TS doesn't have sum types which will make a lot of things more tedious.

Re: TypeScript is surprisingly ok for compilers

#13
But to what end? For a compiler, there is no need for all the overhead of npm (usually), ts, tsconfig, package.json bundler and bundler configuration, to get something usable, unless one really wants a JS thing at the end to run in the browser. I imagine even some webassembly tool chains may be shorter.

Re: TypeScript is surprisingly ok for compilers

#14

But to what end? For a compiler, there is no need for all the overhead of npm (usually), ts, tsconfig, package.json bundler and bundler configuration, to get something usable, unless one really wants a JS thing at the end to run in the browser. I imagine even some webassembly tool chains may be shorter.

[deleted]

Re: TypeScript is surprisingly ok for compilers

#15

But to what end? For a compiler, there is no need for all the overhead of npm (usually), ts, tsconfig, package.json bundler and bundler configuration, to get something usable, unless one really wants a JS thing at the end to run in the browser. I imagine even some webassembly tool chains may be shorter.

The article answers this question. The author is using deno which is a single binary that uses TypeScript without all of that.

Re: TypeScript is surprisingly ok for compilers

#16

it isn't, i have codebase in golang that is much larger than typescript and it is pleasant to work with lsp and compiles smoothly. With typescript i have to turn off lsp and even after that it takes long time too compile. There is a reason why people are writing typescript compiler in rust.

[deleted]

Re: TypeScript is surprisingly ok for compilers

#17
post #2

Is 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.

The biggest expressivity pain point in practice for me is try/catch not being an expression, so I can’t do

   const c = try { … }

Re: TypeScript is surprisingly ok for compilers

#18
post #2

Is 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.

> picked up most of the ML featureset It really hasn't. In this very post he had to use a visitor to work around the fact that switch isn't an expression. JavaScript's support for iterators is also weirdly shit. It has `.map()` but that only works on arrays. You can't map an iterator!

I think there’s an iterator proposal out there for JS with generic map, filter, etc.

Re: TypeScript is surprisingly ok for compilers

#19
post #9

it isn't, i have codebase in golang that is much larger than typescript and it is pleasant to work with lsp and compiles smoothly. With typescript i have to turn off lsp and even after that it takes long time too compile. There is a reason why people are writing typescript compiler in rust.

He's talking about compilers for small languages. The Typescript LSP works fine on very big projects like VSCode so I think you'd need an enormous language like C++ or Rust before you'd run into those limits. But still, I think I'd rather use Rust. I'm pretty sure the code would be nicer (e.g. no need for the explicit tag field or for the visitor hack).

I see ‘TS server has been restarted 5 times in 5 minutes’ daily.

Re: TypeScript is surprisingly ok for compilers

#20
post #2

Is 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.

I'm quite fond of this library for pattern matching; it's a staple in all my new projects.

https://github.com/gvergnaud/ts-pattern

Post reply on HN