Live data from Hacker News

Learning Rust with ChatGPT, Copilot and Advent of Code

simonwillison.net

11–20 of 43 posts

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#11

In a way of seeing it, ChatGPT can be a great teacher because it can both provide subject knowledge and force you to be very critical about content you consume.

Today I built the SSO flow for an application at work, and I learned a lot significantly faster than I could by just searching because it was guided. The generated code had issues, but it felt a lot like rustlings [1]. At many points I felt that my solution and approach was akin to doing gradient descent, with ChatGPT giving me the direction and me doing backtracking to avoid overshooting (glossing what it missed). […

This is something I find really interesting about it: I feel like if you have an intermediate-to-expert level of knowledge it can absolutely amplify that, and make you massively more productive.

The open question for me is how much it can benefit people with a novice level of understanding - that's one of the reasons I'm exploring Rust with Advent of Code using it.

I have 20+ years of non-Rust programming experience though, so I have no idea how well this would work for someone learning to program for the first time. I'd be fascinating to see how well it works (or doesn't) for complete programming newcomers.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#12
post #5

The way it explains code, the error, and then gives the solution to this particular error, i really don’t understand how someone could pretend we’re not witnessing at least a first hint of true intelligence.

On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator.

I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quickly verifiable.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#13
post #5

The way it explains code, the error, and then gives the solution to this particular error, i really don’t understand how someone could pretend we’re not witnessing at least a first hint of true intelligence.

"True intelligence" is a loaded term that needs a concrete definition to discuss meaningfully. Certainly, it is not an intelligence that at all resembles a human intelligence since language models don't actually understand the world, they understand relationships between lexemes and are optimized to produce voluble outputs constructed around that understanding. Language models aren't intelligent in the same way that a motion picture isn't really moving.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#14
post #12
post #5

The way it explains code, the error, and then gives the solution to this particular error, i really don’t understand how someone could pretend we’re not witnessing at least a first hint of true intelligence.

On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator. I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quic…

When I asked it how to undo an operation I had performed using "cargo add" it confidently showed me examples of using the "cargo remove" command... which it had entirely made up.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#15
post #7
post #5

The way it explains code, the error, and then gives the solution to this particular error, i really don’t understand how someone could pretend we’re not witnessing at least a first hint of true intelligence.

I still think it's the world's most impressive party trick. It turns out if you build a model that can predict what word comes next after a sequence of previous words, then train it on TBs (PBs?) of data, you get something that really does appear to be "intelligent". And which is absurdly useful, to boot! Until you trip it up, and the illusion shatters.

Okay, but then is Wikipedia no more than a big party trick? It's the most comprehensive knowledge base humankind has ever produced, made in collaboration of phylantropic people around the world.

Of course some info is sometimes false, but I don't find myself getting disillusioned of it all. It is what it is, and knowing the limitations doesn't ruin it for me, It is still incredibly valuable, and irreplacable, imo.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#16
post #12
post #5

The way it explains code, the error, and then gives the solution to this particular error, i really don’t understand how someone could pretend we’re not witnessing at least a first hint of true intelligence.

On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator. I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quic…

There is chunk operator on std::slice.

How would that work on general iterators? You can have an iterator that always returns 'y'. Or buffered iteration or whatever.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#17
I’ve been using copilot for advent of code as well, as well as in regular day to day coding. I have less luck with comment-based coding than the author, but in my usage it’s been handy for normal autocomplete.

There’s been a number of instances where I would write a comment describing a simple operation and it would struggle or generate a lot of noise, but if I just start writing an implementation it would give me a good suggestion pretty quickly. I guess the extra context helped.

I was disappointed that it wasn’t more useful as a discovery tool- when I’m not knowledgeable about a language or framework, it can be hard to judge whether its suggestions are subtly wrong. After a while, I started getting a sense for when suggestions are likely to be valuable, which is generally when I have a concrete idea of what I want and what it should look like. When i’m doing more exploratory development I often just ignore the completion. Using ChatGPT instead for learning new stuff is a great idea and i’ll definitely be trying that.

Something I wasn't expecting about copilot is that it actually has been giving me pretty good completions for emacs lisp. I think it’s going to be a very valuable tool in the long run and I recommend giving it a second thought if you’ve dismissed its utility.

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#18
This is so cool! I looked at the transcript for day 5 [1] and realized how I learned the same thing regarding Rust strings not being indexable with integers due to them being a series of grapheme clusters. I didn't use ChatGPT and had to dig through the crate documentation [2] and look at stackoverflow [3], but Simon was able to get an equally great explanation by simply asking "Why is this so hard?" which I could relate to very much coming from C++ land. Now, the ability to trust these explanations is another issue, but I think it's interesting to imagine a future where software documentation is context aware to an individual's situation. The Rust docs are amazing and you can see they bring up indexing in the "UTF-8" section, but it requires me reading a section of the doc which I may not have realized was the reason for my frustration with a compiler error regarding indexing. Even if ChatGPT is not "intelligent" (whatever that means), its ability to take a context and almost act like an expert who's read every page of documentation that can point to you into a productive direction is very helpful.

[1]: https://github.com/simonw/advent-of-code-2022-in-rust/issues... [2]: https://doc.rust-lang.org/std/string/struct.String.html#utf-... [3]: https://stackoverflow.com/a/24542502

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#19
post #14
post #12

Earlier quoted context omitted.

On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator. I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quic…

When I asked it how to undo an operation I had performed using "cargo add" it confidently showed me examples of using the "cargo remove" command... which it had entirely made up.

ChatGPT is on nightly of course, https://doc.rust-lang.org/nightly/cargo/commands/cargo-remov...

It should have told you `cargo +nightly remove `

Re: Learning Rust with ChatGPT, Copilot and Advent of Code

#20
post #16
post #12

Earlier quoted context omitted.

On the advent of code day three it would be useful to have a chunking iterator in rust. Having just implemented day 3 and looking for one, I knew rust stable doesn’t have a general purpose chunking iterator. I asked chatGPT about it and it very confidently said one existed and gave me a sample code which imported a nonexistent chunking iterator. I wonder about other outputs of chatGPT which are not as easily and quic…

There is chunk operator on std::slice. How would that work on general iterators? You can have an iterator that always returns 'y'. Or buffered iteration or whatever.

See for yourself:

https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...

As the parent said, it's not stable yet but it's right there so you can see how it works.

The most important ergonomic trick here is that Rust has type inference, it can see array_chunks needs to know how big the chunks should be, and of course you can just specify that but in most cases you'll use chunks which clearly have a defined size and the inference will go "Oh, that's how big the chunks are" just as e.g. if you put a bunch of chars in a Vec you made, the type inference goes, "Oh, it's a Vec of chars" and doesn't waste your time asking you what type of Vec it is.

You'll see the example expects Some(['l', 'o']) to be the first thing out of the Iterator, the type inference system can see that's an array of two chars, thus, the chunk size is 2.

Post reply on HN