3 ms·
Thanks to LLMs, we are quite close to achieving this. I can write code in Python (sometimes even plain english), and GPT can convert it to Go or even Haskell if
by rthnbgrredf 2y ago
Thanks to LLMs, we are quite close to achieving this. I can write code in Python (sometimes even plain english), and GPT can convert it to Go or even Haskell if I like. The conversion is accurate 95% of the time on the first attempt in my use cases, and I expect this to improve further with more powerful models in the near future.
- 12_throw_away 2y ago[flagged]
- rthnbgrredf 2y agoI think it is not so much surprising that large language models are particularly good at languages, including programming languages.
- randomtoast 2y agoI can confirm that it is a suitable use case for GPTs. I do GPT-assisted programming language design and experimentation. In some cases, GPT-4 can even generate a basic interpreter that allows me to test my new language. Here is an example of GPT's output for Python with braces that was generated after just spending 10 seconds for the prompt: def preprocess_braces(code: str) -> str: lines = code.split('\n') processed_lines = [] indent_level = 0 indent_str = ' ' # 4 spaces for indentation for line in lines: stripped_line = line.strip() # Check for opening brace if stripped_line.endswith('{'): processed_lines.append(indent_str * indent_level + stripped_line[:-1].strip() + ':') indent_level += 1 # Check for closing brace elif stripped_line == '}': indent_level -= 1 else: processed_lines.append(indent_str * indent_level + stripped_line) return '\n'.join(processed_lines) # Example usage: code_with_braces = """ def example_function() { if True { print("Hello, world!") } for i in range(5) { print(i) } } """ processed_code = preprocess_braces(code_with_braces) exec(processed_code) # This will execute the transformed Python code print("Processed Code:\n", processed_code)
- im3w1l 2y agoThis code is incorrect though, as it doesn't account for braces in strings and comments. There are other issues too, but that is the big one.
- AdieuToLogic 2y ago> This code is incorrect though, as it doesn't account for ... Isn't this the fundamental problem with code generated by a statistical text generation algorithm? In other words, "code" is short for encoding a solution. And to have a solution to encode is to understand the problem to solve. Without understanding, statistical code generation is little more than a popularity contest.
- roywiggins 2y agoThe model doesn't "understand" anything, but if you, the programmer, understands it well enough, that can be enough to direct it to find a solution. You can do a lot with ChatGPT or Claude if wrong code is easy to spot (which will obviously depend on what you're working on). If you can easily spot mistakes these things can often come up with a fix once you point it out. I've had some real success converting small-scale production C++ code into Python using Claude. Stuff that isn't really deep or complicated, but it's still faster and less annoying using an LLM to assist. I am sure there are large domains where it's crap, but for relatively simple stuff (CRUD logic, simple file parsing) it does remarkably well.
- AdieuToLogic 2y ago> The model doesn't "understand" anything, but if you, the programmer, understands it well enough, that can be enough to direct it to find a solution. This is exactly my point. Whether a programmer uses past experience exclusively to author source code or a statistical code generator (LLM) and then their learned ability is orthogonal to my original premise. Without understanding, statistical code generation is little more than a popularity contest.
- 2y ago
- lgas 2y agoYou can take it a step further, LLMs can already "execute" arbitrary non-existent languages, with non-existent data. Here are a couple of examples using a tool I wrote[1]: % echo "nums 1 10 | filter even | to_words | map uppercase" | refab imagine TWO FOUR SIX EIGHT TEN % echo "with file '/tmp/top-ten-most-populous-cities.txt' do; cities = read; cities.each { |city| (city.name, city.utc_offset) }" | refab imagine Tokyo, 9 Delhi, 5.5 Shanghai, 8 São Paulo, -3 Mumbai, 5.5 Mexico City, -6 Beijing, 8 Osaka, 9 Cairo, 2 New York, -5 For what it's worth, the tool isn't specialized for this, 'imagine' is just one of many prompts it can execute. Of course the execution is non deterministic and at the moment only works for simple things, but you can imagine as LLMs get more capable and more integrated with tools this will matter less and less. [1] https://github.com/lgastako/refab https://github.com/lgastako/refab
- hsbauauvhabzb 2y agoI hope we never work together. 95% accurate will cause problems that you won’t notice when you inevitably get lazy.
- dotancohen 2y agoThis is how I feel about cars that can drive themselves 99.9% of the time. The remaining 0.1%, the most difficult of corner cases, are to be handled by the human who has no experience driving even in good conditions.
- rthnbgrredf 2y agoI'm a strong advocate for writing tests first, maintaining a robust QA process, and ensuring all merge requests undergo peer review. Since I started using GPT-4 for coding, the quality of my merge requests has remained the same. The difference is that I can now produce about twice as many merge requests, as GPT-4 handles the boilerplate writing, Stack Overflow searches and helps to start get going in case of a mental blockade or missing idea.
- hsbauauvhabzb 2y agoBy what metric do you measure quality? Plenty of gpt users were dumping low qualify contributions prior to gpt, now their contributions are the same idiotic trash but appear more competent…
- digging 2y agoI largely agree, but I don't think the current experience is the right one. I recently started writing a game in Godot. I don't know GodotScript, and I've found I don't like it very much in trying to learn. I turned to aider.chat to see if I could describe the functions, data structures, and systems I wanted and have it write them. I also tried writing in a more familiar language (...one with braces...) and having it translate those files. It does pretty well, but it doesn't feel like software engineering. It's too hands-off and doesn't activate the same neurons. All the problem-solving and puzzle-solving is gone, and the successes are quite boring, and the failure modes are more irritating even if they're necessarily quicker to solve. It's a weird experience. I'm moving so, so much faster than I would have on my own, but I don't enjoy it. It feels like cheating - I'm not actually ashamed of what I'm doing but I also won't take credit for writing the code. However, what I'm getting at is this: If I could write the code in a syntax or even language that I prefer and have copilot or whatever translate it in near-real-time (without active prompting), that would be the best of both worlds. I'd still be a little sad at myself if I didn't learn the new language, but I also think this method would facilitate learning better than what I'm doing with aider (because I could see what my code turns into as I'm writing it, and learn that "translation").