Python + AI = Rust

preview_player
Показать описание
A video showing the power of Python + AI (ChatGPT) for generating Rust code. BQN and Haskell solutions also shown.

Chapters:
0:00 Intro
0:14 Problem Description
0:52 BQN Solution
1:52 Haskell Solution
2:30 Python Solution 1 (ChatGPT Generated)
2:55 Python Solution 2 (ChatGPT Generated)
3:03 Python Solution 3 (mine) 3
3:44 Rust Solution (ChatGPT Converted from Rust)
4:14 Case for Rust
5:36 Live Demo of GPT Conversion from Python to Rust)
7:34 Outro

Рекомендации по теме
Комментарии
Автор

Sean Parent actually made a comment that LLMs seem to work better with strongly typed languages and proof verification languages, likely because the training data has fewer bugs and is of generally better quality.

remyclarke
Автор

I add this to all my ChatGPT questions to minimize the output "use as few characters as possible. no comments or explanations"

nixielee
Автор

Your microphone is kinda low, am I the only one? I played other videos just to make sure I wasn’t the issue and it seems your volume was low.

wondays
Автор

The generated rust solution isn't ideal since you're needlessly allocating a string. A zip on (String, char) is better IMO and it's still nearly as concise.

wrong
Автор

how do you even type those wierd characters in BQN or APL?

foobar
Автор

Your python solution is using O(len(words)) memory when you could use O(1) with this:
all(map(lambda a, b:a[0]==b, words, s))

It's a bit clunky because of "lambda"
So here is a bit different approach:
all(a[0]==b for a, b in zip(words, s))
An even more sophisticated approach:
all(a==b for (a, *_), b in zip(words, s))

norude
Автор

Audio is very low volume, isn't it?

thingsiplay
Автор

Your solution at 3:11 is incorrect, it should take the a[0], as the variable a will be each word in words. Naming the variables something more explanatory like word and char instead of a and b could have made that bug more apparent.

albertaillet
Автор

Mmm it can help but I’m not enthusiastic as you

giuliopn
Автор

You were using the poor's man GPT e.g. GPT-3.5 ? The GPT-4 is way better in generating code and prompting it just right is a art of itself ! I've found that if you ask it to generate python in a functional style it does much better in converting to other functional languages like Haskell for instance. When it comes to write Python code that makes use of a dozen or so of external modules GPT-4 is a killer App in my experience, you actually learn the frameworks faster as you can see code for it doing what you want right up!

freedom_aint_free
Автор

I like your videos a lot but this seems like you didn't think this through. You just imply that one would prefer writing python over writing rust directly and that it would be quicker to code something in python than in rust. For leetcode problems and half-assed throwaway scripts that's true. For actual software it's not. For everything that grows larger than one source file or that needs any amount of multithreading I think it's actually MUCH EASIER to develop in rust than in python. In these cases python becomes unmaintainable very quickly unless you're using extensive type hinting and type checkers, at which point you might as well just use rust directly.

Edit: Wow, the video gets even worse at the end! "I didn't check if the output rust code is actually correct, but LoOk At ThIs!"
I hope this is a joke xD

flyingsquirrel
Автор

You videos are mostly about improving code, or at least how to make code more concise--which I like. All this showed is transpiling code, not improving it. Every line of code generated, or written, is code that needs to be maintained. That's the whole point of DRY. There's a lot of redundancy in that rust code. Show us how these LLM's can improve code and I will pay more attention to them.

ctubo
Автор

Wow... so that is proof that Rust is good language :D More in-line verbose but still elegant.
Most seriously it also could be way for all the people trying to write compiler of python, maybe automatic transpilation to Rust is the way ?

AK-vxdy
Автор

I would use zip_longest() to no longer need the len() check, a string with a non-word character is required as a fillvalue.
If long lists are expected I'd leave the len() check in and use zip().

all(a[0] == b for a, b in zip_longest(words, s, fillvalue='\0'))

TigerWalts
Автор

hey great video!
Can you make a video about Cython? The whole idea is the same with the premise in this video: the python code is too slow, need to speedup things.
I experimented a bit with Cython and got crazy 10-100x speedup...even up to more than 2, 000x speedup in a mathematical function.
I want to hear opinion from someone more experienced about Cython and what's best way to use it.

Cheers!

pietraderdetective
Автор

that rust example isn't returning anything. (agree with the other comments on the unnecessary allocation too)

jereziah
Автор

What does it produce for the 100 lines python to C++23 ?

pmcgee
Автор

Just using Python as a pseudocode. I think it can do better than that.

TheReferrer
Автор

you dont even need to code it in python. Just write it in english, and have it generate rust directly.

serene_-fbns