10 ms·
Converting Codebases with LLMs
- JTyQZSnP3cQGa8B 2y ago> a recurring need in the software world for teams to convert a codebase from one language to another Really? I've only seen that twice in my career, and it was due to being written in the most obsolete tech ever. I have the same comment for the "patterns" that GPT-bros seem to be stuck in all the time. What kind of software are they writing that needs 80% of duplicated/useless code, and 20% of business code? They should first read Refactoring by Martin Fowler, and try to avoid those mistakes in the future because it's bad to rely on a AI for what should be their job, i.e. engineering software. > the database querying layer was quite verbose and greatly exceeded an LLM’s output token limit No technical details as usual, only high-level stories. And how is it possible nowadays to have that kind of issue where most languages have their own SQL or REST library to do everything in, at most, 500 lines of code (if the code is duplicated)? Last but not least, the main web site is a very pretty empty page if JS it disabled. They should fix that with an LLM and write a blog post, that would be more interesting.
- blowski 2y agoI've found it to be more common in organisations with an immature microservices culture, where developers seem to think there are awards for most number of languages used. At some point, sanity takes hold, and there is a process to standardise - involving lots of rewrites of small codebases.
- joshuanapoli 2y agoThe JavaScript ecosystem historically had a lot of turnover. Probably there are a lot of applications that repeatedly ported over the years: Ruby to JavaScript, to coffescript, to flow types (for React), to Typescript. I think that these language ports aren’t as disruptive as architecture changes (waffling on microservices), and they’re driven by availability of talent. Porting to follow the trend makes it easier and much more pleasant to onboard new developers. It usually has a practical benefit to users, because the latest tooling usually has a performance edge, but doesn’t support the old language.
- blowski 2y agoYes, good point. Even within React, there's been a big change from class components to functional components and hooks. I imagine LLMs could help with some of that.
- cjonas 2y agoI just ported 10k loc of react classes to function components using gpt-4o. The changes are mostly trivial, but would be fairly time consuming and tedious to make. It took me a few hours instead of a few days.
- bavell 2y agoIsn't this already possible with codemods?
- _f9cu 2y agoNo. Nobody can understand how to use code mods. I could not. But I'm not sure about others. My view is that those engineers in fb are no longer there to promote and support that project. Or they would have migrated to learning ai ml
- deleted 2y ago[deleted]
- bavell 2y agoFair enough, I've never used them either!
- _f9cu 2y agoHow much did it cost?
- JTyQZSnP3cQGa8B 2y agoI forget "JS and the web" all the time because I've been actively avoiding it for the past 20 years. It happens in other environments but the web seems to encourage "following the trend" and that would make me crazy if I had to do this every day.
- fhd2 2y agoThat's a concern I have: The pain of writing boilerplate used to make people improve their architecture and frameworks. If the Java ecosystem hadn't been so painful in the early 2000s, would better languages and frameworks have gained traction? Would good refactoring practices have gained traction? Sometimes refactoring doesn't even cut it, unfortunately. When stuck with a language and/or framework that simply requires lots of boilerplate, there's only two options: Migrate to something else or use/build code generation tools. I've done both with good success. Not sure I'd use a non-deterministic tool (like an LLM) for this, but since deterministic tools are harder to build, we might be looking at a future where a lot of working code is rewritten with automation that introduces subtle problems. I'm optimistic though. There's always been a lot of terrible software somehow kept under control with high development/testing resources. And then there's always been carefully built good software. I suspect we'll continue to have both. We'll probably have good software because some managers manage to hire good devs _and_ give them the right direction and support to do good work. We'll probably have lots of bad software for the same reasons as in the past: Incompetent management, competent management pragmatically sacrificing software quality and/or maintainability, incompetent (or really just impatient/rushed) developers. I don't think LLMs change the equation that much. Good devs will use them well (or perhaps not at all). Bad devs will use them badly. Good software can give startups an edge, bad (enough) software can bring down incumbents.
- onion2k 2y agoI've seen it a lot. Mostly things like moving from PHP 3 to PHP 5, or Python 2 to Python 3, or React 12 to React 17. A language change doesn't have to be between completely different languages to be a pain.
- zcbenz 2y agoA few months ago I ported ~15k lines of python code (10k are tests) to typescript, using GPT4. It cost me ~$70. The python project is https://github.com/ml-explore/mlx https://github.com/ml-explore/mlx and the converted project is https://github.com/frost-beta/node-mlx https://github.com/frost-beta/node-mlx I wrote a long prompt: https://github.com/frost-beta/node-mlx/blob/main/tests/prompt_test_py_to_js.txt https://github.com/frost-beta/node-mlx/blob/main/tests/promp... The first result was almost always bad, but after manually modifying the assistant's answer, following generation usually went much better.
- newzisforsukas 2y ago> Use () => instead of function() for defining functions. > Use const when possible, but use let if the same name is reused in the same scope. looks like some of that could have been handled with a linter autofixing afterwards. $70 seems like a lot for 15,000 lines?
- mmastrac 2y agoIn the absence of an AST based tool, that's probably an absolute minimum of 20-40 hours of dev time (likely more) at $100-200 hourly, no?
- _f9cu 2y agoThere is no AST tool nor anyone had solved cross language refactor. Direct me if I'm wrong
- iknowstuff 2y agoThey mean running it on typescript post conversion.
- newzisforsukas 2y agoI just meant for processing, not compared to skilled or mindless translation done by humans.
- puttycat 2y ago[flagged]
- blowski 2y agoFrom the guidelines: > Please don't post shallow dismissals, especially of other people's work. A good critical comment teaches us something. If you think people shouldn't do this, I'd be interested in hearing why not, and what you'd consider a better alternative.
- puttycat 2y agoI apologize. What I meant was: by this point in time there's a constantly growing pile of evidence that LLMs are highly unreliable, highly opaque reasoners and one shouldn't count blindly on them for critical missions or even non-critical ones.
- ukuina 2y ago"Blindly"? No. But the business value being created by the careful application of LLMs is growing steadily.
- newzisforsukas 2y agohttps://github.com/facebookresearch/CodeGen https://github.com/facebookresearch/CodeGen
- smusamashah 2y agoWhat is the current best LLM for coding? I am using Claude Sonnet 3.5 free and it's so good. I am not making anything serious and LLM is perfect for that. Which current models are better than sonnet for code (plain old html JS is my use case btw)?
- sa-code 2y agoI'm also using Sonnet to work on a library in Mojo and I've had pleasant experiences!
- Art9681 2y agoSonnet is the best at the moment. GPT-4o is within a margin of error in capability. Use both.
- smusamashah 2y agoIsn't GPT-4, rather than GPT-4o the general best one? I am not talking about benchmarks, but the personal experience instead. GPT-4 always seem more understanding, says no where it should more often, corrects and identifies errors more often. 4o seems to go with the flow without much notice/inspection and keeps blabbering the way it does instead of following the conversation style.
- bongodongobob 2y agoYup. I use 4o until it fails on something, pull in 4, then back to 4o. Rinse and repeat.
- kadir1234 2y agoIs there an architectural reason Sonnet beats 4o? Or is it simply a matter of training corpus?
- Tiberium 2y agoWe don't know what exact architecture and optimizations both of those models use, it's all proprietary nowadays :)
- deleted 2y ago[deleted]
- mspreij 2y agoThis should help porting all the old Cobol and Perl apps out there, no?
- homarp 2y agoIBM watsonx Code Assistant for Z: Transform COBOL services to Java™ by using an AI-assisted approach with IBM watsonx Code Assistant for Z and IBM Z Open Editor. https://www.ibm.com/docs/en/watsonx/watsonx-code-assistant-4z/2.0?topic=transform-transforming-cobol-java-by-using-generative-ai https://www.ibm.com/docs/en/watsonx/watsonx-code-assistant-4... HN discussion: https://news.ycombinator.com/item?id=38508250 https://news.ycombinator.com/item?id=38508250
- ktzar 2y agoI wonder how many subtle errors will make their way to the new codebase (decimal rounding, a library uses where a parameter is ignores and there's no tests for it...) only to be found in production and AI will be blamed.
- Deukhoofd 2y agoI did some converting with Copilot today. The answer is, quite a lot. It'd convert integer types wrong (whoops, lost an unsigned there, etc). And then of course there were some parts of the code that dealt with gender, and Copilot just completely refused to do anything with that, because for some reason it's hardcoded to do so.
- bloak 2y agoThat gender thing is interesting. Could you try renaming some of the variables and substituting words in the comments so that the code no longer obviously appears to be dealing with gender and see if Copilot behaves differently? If it does behave differently, I'd find that a bit worrying because conversion of a correct program into a different programming language should not depend on how the variables are named or what's in the comments. For example, assuming this is a line from a program written in C that works "correctly", how should it be converted into Go or Rust or whatever? int product = a + b; // multiply the numbers
- Deukhoofd 2y agoEverything works mostly fine as long as it's not obviously dealing with gender, but will fall over as soon as anything appears to refer to gender, either due to comments or due to variable naming. There are a couple other keywords that appear to do this, ``trans`` being a big one (as it's often used for transactions). It does also use assumptions from comments. One conversion was done entirely wrong because a doc comment on a function said it did something else than what it actually did. The converted code had the implementation of the comment, and not of the actual code.
- g-b-r 2y ago
- largbae 2y agoI wonder if LLM language conversions will lead to a consolidation of languages. Suppose that you could prototype in any language and autoconvert that resulting functionality to Rust or another language with the right runtime features, would that be an appealing dev model?
- binary132 2y agorust doesn’t have runtime features
- threecheese 2y agoI have the same suspicion; the current ecosystem of computing is very much a product of human constraints, and it may end up being more cost-efficient to have a single standard be used by AI models rather than having them need to match every unique code+libraries+hardware combination that exists or will exist. How this affects the computing ecosystem, this worries me.
- impure 2y agoI used an LLM to convert my XML parser from Dart to Go. It was mostly right but with some giant mistakes. This was when I was extremely new to Go, don’t know if I would do it again. It might be faster to manually write the code because that way I could spend less time reading it.
- Frieren 2y ago> There is a recurring need in the software world for teams to convert a codebase from one language to another. Sounds more like a sales pitch than a reality. I have seen many times developers excited to port code from one language to another, but just because it is an opportunity to learn something new, do something different for a change and even rewrite old code. What is the value if is done automatically, nobody learns anything and the code is just a transcript of the old one?
- _f9cu 2y agoI don't anyone have solved to do this automatically, in this community. Value it provides is for the business. If a tool can do it, there is no need to hire or keep an engineering team. Engineering team has a running cost. Where as, using a tool or if someone makes the tool, sells it at a price slightly lower than what's spent for engineering team, doesn't it add a value? First. It's a tool that does, so reliable more than a human. If it is a sales pitch, someone will get it done, as there is an opportunity
- TechDebtDevin 2y agoIt's not reliable and LLMs cannot create anything novel. Your hypothetical company is going to end up pulling a Crowdstrike with this method and then they definately won't need an engineering budget!
- nerdjon 2y ago> Value it provides is for the business. If a tool can do it, there is no need to hire or keep an engineering team. What exactly is the "value?". It worked before so what is the purpose of the change. > First. It's a tool that does, so reliable more than a human. Sorry but, are you new to LLM's? Have you seen the recent news? "Reliable" it is not. If your pitch is that an LLM will just write all of your code in the first place, there really isn't any need to migrate the code to another language when by your logic the LLM could just manage its existing language. The logic here quickly breaks down and doesn't make any sense.
- 2y ago
- miguelspizza 2y agoThis is a perfect use case for LLMs at the moment. I wrote a script to update and express code base to hono. I got Claude to write a regex that would match the handler to the route and called the Claude 3.5 api with an example conversion and some other relevant context. With the right prompt, it produced extremely clean and workable code. ~20 controller files and over 100 route handlers were converted in about 20 minutes and 5 dollars. The engineering cost of migrating code bases is trending to 0
- thesz 2y ago> The engineering cost of migrating code bases is trending to 0 I work with code base of >750K LOC C++ that is 12+ years old and would like to migrate it to something fashionable like Futhark or Python. So, please, tell me more about your wonderful regular expression.
- miguelspizza 2y agoI’m not sure why you would want to migrate a C++ codebase to an interpreted language?
- thesz 2y agoI want to migrate from C++ because these languages are fashionable and hip and have more developers available and because migration with regular expressions is easy, apparently. Actually, a colleague of mine asked me why people keep using bash for scripting instead of Python despite Python being obviously better in all regards. So I decided to joke around about this.
- redleggedfrog 2y agoHow maintainable the code for humans?
- gregors 2y agoI'm curious about the security implications and corporate policies about uploading your entire codebase to an LLM where others can access it (indirectly or directly). Other than that, I'm very interested to see how easily opensource libraries could be converted from ecosystem A to B.
- tbrownaw 2y ago> where others can access it (indirectly or directly). Anything sold specifically for corporate use should come with contract terms that prohibit this. (The few that try to not guarantee confidentiality won't survive very long.) I know that one of the things $employer looks for is an explicit ban on using our data for training. Or even against having humans in the loop for the abuse monitoring process; that one came with rules about us having certain controls in place.
- DarkContinent 2y agoIt's not clear to me from the article how Mantle was porting the build scripts, infrastructure config files, etc across languages. Typically these files don't cleanly translate from one framework to another. Was this considered as part of 20% of project for human engineering effort?
- pmarreck 2y agoThat's odd. I was discussing this very idea with ChatGPT just last night, in the context of coming up with a way to deterministically go from <example code> to <english language description of example code> and back again, and then thought that English might be a good intermediate language when converting logic to a different programming language... https://chatgpt.com/share/5d2245e8-135e-44f4-a204-401e62518342 https://chatgpt.com/share/5d2245e8-135e-44f4-a204-401e625183...
- _f9cu 2y agoThat's strange. Would be a right word. Great minds think alike. You are solving the problem using chatgpt, with right words on first hit. Author here is solving problem using chatgpt's usage syntax. You will not be convinced by either, because the problem is not solved.
- rock_artist 2y agoRecently I’ve converted some code to make an app from python to Swift. I’ve tried using Gemini and ChatGPT. The time I’ve spent afterwards debugging it in order to fix introduced bugs made it not worth it. IMHO, the way this could work is only if you have very good test coverage so you can run them. But without it this can easily go off the tracks.