Live data from Hacker News

TypeScript is surprisingly ok for compilers

matklad.github.io

201–210 of 245 posts

Re: TypeScript is surprisingly ok for compilers

#201

Earlier quoted context omitted.

This blend of functional and oo programming was pioneered by scala.

Lisp of course supported both decades earlier though :)

Sure. Everything is reducible to lisp. But even though lisp had the same capabilities decades earlier, scala is the language that brought them to the mainstream (which may well because of the historical accident that twitter's backend was rewritten in scala). I don't love scala but it has been hugely impactful.

Re: TypeScript is surprisingly ok for compilers

#202

It sure is. For anyone looking into Compilers and just starting out, I recommend this book: https://keleshev.com/compiling-to-assembly-from-scratch/ The author uses a TypeScript subset to write a compiler to 32bit ARM assembly and explains that it almost looks like Pseudocode, so it is very accessible. A sentiment I can get behind, despite avoiding it in any case possible.

Anecdotally, I love the reference to the classic "Dragon Book" that this cover makes.

Re: TypeScript is surprisingly ok for compilers

#203

Earlier quoted context omitted.

> Don't feel bad, most developers have no idea Some advice I know you’ll ignore: your tone in the comments here is deeply patronising. You know absolutely nothing about me and yet are entirely comfortable dismissing my perspective as wrong simply because yours must be correct. It’s not an interesting or rewarding way to converse, it makes me want to stop talking to you as soon as I can. Which I’ll be doing here. Have…

Yes, I work in a language where junior developers and people deeply unaware of the language advocate anti-patterns and bad practice as matters of law, often for personal defensive reasons. Its hard to not feel patronized. You are correct in that I do not know you, but I have been doing this work long enough to see when people hide behind abstractions they don't understand as necessary to mask their level of confidenc…

This is exactly what I’m talking about. You are assuming I am inexperienced and have no idea what I’m talking about because I have a different view to you.

For what it’s worth, I’ve spent years working with the innards of various JS engines, managed deployments of JavaScriptCore inside iOS apps (fun fact: no JIT) and using QuickJS in low resource environments (no JIT there either). There’s an interesting conversation to be had around optimising your code for JIT, given the different environments we’ve both worked in. But your ego won’t allow it to take place. A shame for all concerned but in my years of development I’ve met plenty like you and I’m well aware that I’m not about to change your mind so I’ll just leave it there.

Re: TypeScript is surprisingly ok for compilers

#204
post #94

Earlier quoted context omitted.

I've done a bit of typescript and kotlin-js. It always strikes me how close those two languages are. Yes there are lots of differences but they aren't that different and you can transition from one to the other pretty easily. I have my preferences (kotlin) but I can work with both. IMHO typescript could just cut loose from its javascript compatibility. Why not compile it to wasm instead of transpiling it to javascrip…

Typescript is defined to run exactly as the equivalent Javascript you get when all the type declarations are stripped out of the source. There's no benefit in compiling it to WASM unless you had a WASM JS engine (or JS->WASM converter) that executed the JS faster than the browser's built-in JS engine (or created WASM binaries that were smaller than compressed minified JS, which seems extra unlikely when you'd have to…

[deleted]

Re: TypeScript is surprisingly ok for compilers

#205

Earlier quoted context omitted.

FP in python is painful without tail call elimination and the higher-order function syntax is so clunky

JS also doesn't have TCE, but for Python even just the lambda limitations are surprisingly annoying. I can't tell you how many times i've been frustrated because it's nearly impossible to put a print statement into a python lambda

JS technically does have TCE (specified in ES6[1]), but only the JavaScriptCore runtime used by Safari/WebKit implements it[2].

[1]: https://webkit.org/blog/6240/ecmascript-6-proper-tail-calls-... [2]: https://kangax.github.io/compat-table/es6/#test-proper_tail_...

Re: TypeScript is surprisingly ok for compilers

#206

Earlier quoted context omitted.

Lisp of course supported both decades earlier though :)

Sure. Everything is reducible to lisp. But even though lisp had the same capabilities decades earlier, scala is the language that brought them to the mainstream (which may well because of the historical accident that twitter's backend was rewritten in scala). I don't love scala but it has been hugely impactful.

The meaning of "mainstream" changes throughout the years. Remember that Common Lisp started as quite literally the XKCD joke of "14 competing standards", except it actually worked -- in the sense that this 15th competing standard killed all the other ones and gained widespread adoption in the Lisp community. Tons of vendors threw money and effort at the situation, and it all started as an ARPA manager's idea. Of course, we live in different times now... But Zetalisp is one fairly popular Lisp I can think of that had funcallable objects. Whether the idea was appreciated or preferred over alternatives is a separate thing entirely, of course. I would assume most people would use a simple let-over-lambda to achieve the same effect as funcallable objects.

Re: TypeScript is surprisingly ok for compilers

#207

Earlier quoted context omitted.

I've done a bit of typescript and kotlin-js. It always strikes me how close those two languages are. Yes there are lots of differences but they aren't that different and you can transition from one to the other pretty easily. I have my preferences (kotlin) but I can work with both. IMHO typescript could just cut loose from its javascript compatibility. Why not compile it to wasm instead of transpiling it to javascrip…

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

I've been hoping to see alternative targets to JS for TS as well. WASM makes a lot of sense but TypeScriptToLua¹ also looks interesting.

1: https://typescripttolua.github.io

Re: TypeScript is surprisingly ok for compilers

#208
post #84

Earlier quoted context omitted.

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

There are a few very specific differences. In a subclass, 'this' doesn't exist until you call "super" for example, and the constructor will throw an error of invoked without the "new" keyword. [O] These differences let you extend built-in things that simply can't be done with old prototype constructor syntax. [1] [O] I should probably be using a more recent reference like MDN, but the 2ality series always sticks out…

Thanks. It sounds like subclassing built-ins is where transpilers hit a hard wall. Other syntactic features of es6 can be transpiled.

Re: TypeScript is surprisingly ok for compilers

#209
post #145
post #84

Earlier quoted context omitted.

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

My example is incorrect because it doesn’t cover all the edge cases but you can desugar es6 to es5, except in es5 you can’t subclass builtins.

Re: TypeScript is surprisingly ok for compilers

#210

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…

The same is achieved with Java's use of single-method-interfaces. It doesn't matter what the method is called, it can be used in function contexts without referencing the specific method name. I'm not sure I'd like my functions to have properties (which gives them state and can alter what calling it does with the same arguments). A big benefit of FP is getting away from OO states. Perhaps the problems I work on aren'…

To be clear, since "can be used in function contexts without referencing the specific method name" might be ambiguous to some- in Java you still call the "function" as if it was a class implementing the interface. IE: `interface Foo { String bar(); }` is still called as foo.bar().

It's just that there's now syntactic sugar for creating anonymous classes: `Foo foo = () -> "baz"` that automatically expands to an anonymous class that conforms to `Foo`. The compiler automatically assigns the method name for you.

Post reply on HN