Hacker News new | ask | show | jobs
by Sammi 2384 days ago
Twice I've been part of a move from Javascript to Typescript that worked much the same. Both projects were large applications with several developers working on them. Both had been ongoing for a few years before the port started. In both projects we decided to write all new code in Typescript and convert JS to TS when we made any largish change to an existing JS file. In both cases it took around a year for us to hit > 90% all code being converted this way, and at that time we decided to actually make issues in our issue tracker for porting the rest, and then had the rest converted in a couple of months after that.

The big difference is however that JS and TS can live side by side on a file by file basis out of the box with the Typescript compiler, which makes it super easy to convert. You don't have this luxury with C and Rust of of the box, but serious kudos to the author for finding a way to do something very similar.

When converting C to Rust you usually have to do things on a module by module or compile artifact by compile artifact basis, which makes it much more challenging. You can however employ some sort of strangler pattern: https://docs.microsoft.com/en-us/azure/architecture/patterns...

2 comments

> When converting C to Rust you have to do things on a module by module or compile artifact by compile artifact basis, which makes it much more challenging.

OP is essentially about proving the opposite. It does take a bit of setup to get there, but you can ultimately translate C to Rust on a function-by-function basis, and Rustify interfaces, data structures, etc. only gradually after nothing on the C side is relying on the older defs.

C++ would be more of a challenge - you need to forgo quite a few C++-exclusive features to end up with interfaces that Rust can work with. That's where an "artifact by artifact" approach might work better. Other languages would be roughly similar, with their heavyweight C FFI's.

> you need to forgo quite a few C++-exclusive features to end up with interfaces that Rust can work with

Luckily, many C++ projects do this already so they can be called from C.

Sorry for the ninja edit. I've updated my comment. I meant to discuss how it works out of the box with Typescript, but takes more work with Rust. Seriously impressive that it can be done though.
I did something similar for a large-ish C# project and F#. The company I worked for was mostly an F# place, but we had a fairly large legacy codebase written in C#; typically we had the pattern of "if you had downtime or need to fix a bug in the C#, just rewrite the C# code into F#".

Annoyingly, at least with the typical msbuild pattern, you have to be using the same language at the project level, but you can have as many projects as you want per solution (it's weird). So it's not as seamless as the JS/TS system, but overall it's not too bad, since you still can mix and match somewhat.

MSBuild assumes you want a 1-to-1 relation between projects and assemblies, so assemblies and projects are interchangeable. There is no hybrid C#/F# compiler than can produce one assembly out of source code from both languages, so you’ll always need at least 2 compilers to be involved, hence the need to have a csproj and an fsproj side by side in your code base.

Regardless, major kudos for your rewrite!

Yeah, I knew that actually; it's still annoying :), but after awhile you kind of get used to figuring out how to split up the stuff you're going to rewrite.

It wasn't just me; it was everyone on my team, and probably everyone in the company; I'm pretty glad they did that though; F# ain't perfect, but I like it a lot better than C#.