News for hackers. Stuff that matters.
Re:I’m porting the TypeScript type checker tsc to Go by scottlamb on Tuesday January 25, 2022 @02:43PM (#30076972)
> This reminds me of when people try to make a new Ruby implementation. They get the basics down and think "this isn't so bad! I can do this!". Fast forward a few months and they're stuck on some nasty little edge case around eval and method_missing that they need to run Rails. Or some weird aspect of C extensions.

I think that's exactly why the author wrote this:

> Eventually, I realized that rewriting a massive project such as tsc would be extremely difficult to continue. But the performance gains were exciting. This led me to try another route: porting instead of a complete rewrite. So, I started looking at the TypeScript source code.

It will require ongoing work to keep up with changes to upstream, but by matching upstream's structure as closely as possible (given the language difference), the path to supporting these nasty little edge cases should be relatively clear.

Re:I’m porting the TypeScript type checker tsc to Go by ludamad on Tuesday January 25, 2022 @03:03PM (#30077239)
Interesting, in theory you could make a rough js to golang compiler given the relatively strict subset of typescript that I recall the typescript compiler using (not that the strictness means a fully sound implementation is easy, but that you can use the regularity to cheat text transforms)
Re:I’m porting the TypeScript type checker tsc to Go by mrkentutbabi on Tuesday January 25, 2022 @04:20PM (#30078212)
What is the difference between porting and complete rewrite? I thought they are the same?
Re:I’m porting the TypeScript type checker tsc to Go by scottlamb on Tuesday January 25, 2022 @04:28PM (#30078326)
> What is the difference between porting and complete rewrite? I thought they are the same?

As with so many terms in computing, there aren't universally agreed definitions. But in the author's post, I read "porting" as switching languages while changing as little as possible vs "complete rewrite" as redesigning/rearchitecting it along the way.

Re:I’m porting the TypeScript type checker tsc to Go by azakai on Tuesday January 25, 2022 @07:07PM (#30079961)
To add to that, I would say that simple forms of "porting" can be done without really understanding the overall architecture. You just need to understand each line (or a few lines around it) at a time. I understood the post to mean something like that, which sounds like a good plan here, to minimize the risk of adding bugs.

And in comparison, a "complete rewrite" would require a full understanding of the big picture design of the original code, come up with a perhaps different one in the rewrite, and keep the differences in your head as you go (or, forget about the original design entirely and solve it from scratch - and keep that in your head as you go). Far more work and risk, and it would have been a bad choice here.

Re:I’m porting the TypeScript type checker tsc to Go by cwalv on Wednesday January 26, 2022 @01:02AM (#30082306)
If that's the case, it seems unlikely that they'll be able to get the hoped for performance improvements
Re:I’m porting the TypeScript type checker tsc to Go by jacobr1 on Tuesday January 25, 2022 @04:33PM (#30078403)
Porting can involve a spectrum of changes. If you are porting to a different language, often for bug-for-bug compatibility you try to maintain the same rough code and class/object structure as the source codebase. This might give you some non-idiomatic code at first, but once you have good test coverage you can refactor. In this case you might maintain some of the upstream code structure to better match future changes.
Re:I’m porting the TypeScript type checker tsc to Go by travisd on Tuesday January 25, 2022 @04:32PM (#30078381)
I think here “rewrite” means completely changing the internal structure of the code (while preserving the functionality) whereas “port” means copy the structure of the internal code with as little modification as possible. And it’s hard to do the latter in Rust since Rust is not garbage collected.