←back to thread

22 points ninocan | 3 comments | | HN request time: 0.466s | source

Context: I was tasked with migrating a legacy workflow system (Broadcom CA Workflow Automation) to Airflow.

There are some jobs that contain rather simple JavaScript snippets, and I was trying to design a first prototype that simply takes the JS parts and runs them in a transpiler.

In this respect, I found a couple of packages that could be leveraged: - js2py: https://github.com/PiotrDabkowski/Js2Py - mini-racer: https://github.com/bpcreech/PyMiniRacer Yet, both seem to be abandoned packages that might not be suitable for usage in production.

Therefore, I was thinking about parsing and translating Javascript's abstract syntax trees to Python. Whereas a colleague suggested I bring up an LLM pipeline.

How much of an overkill that might be? Has anyone else ever dealt with a JavaScript-to-Python migration and could share heads-ups on strategies or pitfalls to avoid?

Show context
barrkel ◴[] No.43377932[source]
I did a reasonably big rewrite from JavaScript (Nashorn, long story) to Kotlin/JVM recently (with 60x speedup and elimination of huge variance in runtime).

Keys to success in a larger scale translation:

- don't redesign anything, do a port (see also, Typescript compiler to Go port)

- leverage LLMs interactively: per chunk (e.g. function), copy the old code into a comment in the new code, then use LLM completion to quickly fill out the translation

- get something basic up and running ASAP that you can test, ideally data-driven (inputs, expectations) tuples, that you can write scaffolds for execution of the old and the new code

- for every method / control flow ported, add tests that target the newly added code, validating it does the same as the old code

Some of this may be less applicable to scripts or harder to apply to imperative code, for which you might want to spend time converting side-effecting actions into data that can be asserted on (e.g. instead of performing commands, emit a list of commands); do this refactoring on the old code before porting.

Don't get tempted into doing refactorings as you go. When you notice an opportunity to refactor, create a bug for it. What you don't want to do is build up a list of transformations that increases the more code you port, and makes finishing everything harder and harder.

replies(2): >>43378286 #>>43387714 #
1. anonzzzies ◴[] No.43378286[source]
> - don't redesign anything, do a port (see also, Typescript compiler to Go port)

> Don't get tempted into doing refactorings as you go.

I would say those are the most important. We did so many migrations in the past 30 years and the only ones that went ok were the ones that held to these rules. If you don't, you are rapidly stuck in a lot of pain and probably you won't be able to get out.

replies(2): >>43378348 #>>43391057 #
2. nailer ◴[] No.43378348[source]
Do add TODO comments about proposed refactorings for later though.
3. datadrivenangel ◴[] No.43391057[source]
110% this. Resist the urge to make changes until everything is moved over. Any system 'enhancements' may also be viewed as bugs/defects, and reduces trust, requiring lengthier validation.