Live data from Hacker News

TypeScript is surprisingly ok for compilers

matklad.github.io

141–150 of 245 posts

Re: TypeScript is surprisingly ok for compilers

#141
post #30

Earlier quoted context omitted.

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 programm…

If you’re going to use C# for a compiler, why not go the whole hog & use F#?

I was going to mention F#. The parent and grandparent comments mention C# and ML, and the intersection of the two is... F#.

Re: TypeScript is surprisingly ok for compilers

#142
post #109

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)…

I mean I get what Daniel's saying, but I kinda doubt there wouldn't be _some_ speedup. And hey, what if type checking for small programs went from half a second to 100 ms? That would be nice!

That's a five times speedup. I wouldn't expect a typical 'compiled' language to run five times faster than JavaScript on the kind of code you find in a compiler.

Re: TypeScript is surprisingly ok for compilers

#143
post #46

Very much apropos: Going between Rust and TS it is painfully obvious how much sth like tagged enums are missing, which can also be seen in this post. I know of this [1] proposal for ADT enums which looks like it has stalled. Anyone know of other efforts? [1] https://github.com/Jack-Works/proposal-enum/discussions/19

I find discriminated unions work ok for similar use cases.

Re: TypeScript is surprisingly ok for compilers

#144
post #140

TypeScript 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…

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

#145
post #84
post #69

Earlier quoted context omitted.

I actually argue JS was a better language before all of the changes made, starting with const/let. The only thing I'd say makes sense are classes but the fact they aren't syntax sugar over prototypes was a mistake. People wanted a different language, they should have gotten more scripting languages in the browser. Not changing JavaScript so much that it's no longer JavaScript.

> aren't syntax sugar They aren't syntactic sugar? Pretty sure `class Foo { blah() {} }` is equivalent to `function Foo() {}; Foo.prototype.blah = function() {}`.

They are not, no.

Re: TypeScript is surprisingly ok for compilers

#146
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.

Lack of pattern matching is annoying, but Typescript's tagged unions and type narrowing from if-statements are a good substitude and make for a very pleasent time traversing ASTs. C# has it's own way to express similar data structures (with subclasses and interfaces), but I find unions+narrowing much more natural in Typescript.

Re: TypeScript is surprisingly ok for compilers

#147
post #102

Earlier quoted context omitted.

> IMHO typescript could just cut loose from its javascript compatibility. Why not compile it to wasm instead of transpiling it to javascript? My fantasy for the past year has been, if I could magically program anything, bringing a compiler and spec wholesale into the world out of the void, I would create a new language (call it WebScript as a placeholder) that - featured an ML style type system, ADTs, a type syntax n…

Go has exceptions: you can use `panic` to throw/catch just fine. The community will bring out the torch and pitchforks because it’s “not idiomatic” but if you’re programming solo or with other pragmatists don’t let it stop you.

Or just pass pointers because you need optionality, and get null pointer exceptions for free :)

Re: TypeScript is surprisingly ok for compilers

#148

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

And, JS engine's whims change frequently enough that yesterdays micro-optimisation is today's deopt.

Much better to just write ideomatic code.

Re: TypeScript is surprisingly ok for compilers

#149

TypeScript 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…

This looks like plain JavaScript.

What does TypeScript add in this scenario?

Does the example above even pass typecheck?

Re: TypeScript is surprisingly ok for compilers

#150

Earlier quoted context omitted.

> This is why once WebAssembly more polished and more common, languages like JS and TS could become obsolete since proper, more powerful languages will suddenly become a valid choice for Web. JavaScript and TypeScript are not "proper" languages? Different languages are powerful in different use case dimensions (tradeoffs), and the typical client-side web programming has a very very strong UI angle, which many "more p…

JavaScript's redeeming quality is that it is ubiquitous due to being used by browsers. I don't think anybody credibly claims it to be a language we would want to use if we were to redesign web programming from scratch today

Outside of the "everyone hates javascript" circle jerk, I really enjoy writing Typescript. I find its type system to be very natural and pleasent to use. It's my go-to for any generic task.
Post reply on HN