Live data from Hacker News

Learning Rust with ChatGPT, Copilot and Advent of Code

simonwillison.net

31–40 of 43 posts

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

#31
post #11

Earlier quoted context omitted.

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…

I recently stumbled on this video [1], where the host and an expert used diffusion models to generate art, had viewers blindly rank them. The tl:dw is that at the hands of an expert, it can be a massive productivity boost, while at the hands of a newbie, it reduces the skill floor.

I think that is very similar to what we are observing, but while it drops the skill floor a bit, meaning that it's easy to make stuff, it also acts as a multiplier for rate of improvement, where people with pre-existing knowledge can quickly adapt to a particular domain by probing further. The pre-existing knowledge serves as the backbone on which new info is added and filled in. Funnily enough this is the same idea as pretraining a model e.g. through self-supervision, hah!

> A skill floor is the counterpart to a skill ceiling. A skill ceiling is the level of play that’s possible with training and mastery. A skill floor is a way of describing how difficult it is to begin the process of mastery. [2]

[1] https://www.youtube.com/watch?v=NiJeB2NJy1A

[2] https://esportsedition.com/general/skill-ceiling-skill-floor...

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

#32
post #21

ChatGPT finally told me the solution for question: "How do you force borrow checker in rust to allow reusing mutable reference when self is borrowed by a function call, but not returned back, using unsafe is okay"

If you do this, make sure you find a way to test your code under Miri. Unsafe workarounds to this problem might appear to work in practice but are often unsound according to the (likely, future) formal memory model. The situation is similar to a strict aliasing violation in C/C++, where trivial-seeming changes to surrounding code (or flags, or the compiler version) can turn a "benign" or "latent" violation into observable UB.

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

#33

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 re…

Note that for AoC, it will often be a good idea to say you want bytes, not chars, and of course a slice of bytes is just trivially indexable. You can make "byte string literals" and "byte literals" very easily in Rust, just with a b-prefix and the obvious restriction that only ASCII works since the multi-byte characters are not single bytes. The type of a "byte literal" is u8, a byte, and the type of a "byte string literal" is &'static [u8; N] a reference to an array of bytes which lives forever.

  let s1 = "[[..]]";
  // Rats, indexing into s1 doesn't work †

  let s2 = b"[[..]]";
  // s2 is just an array of bytes
  assert_eq!(s2[4], b']');
† Technically it works fine, it's just probably not what you wanted

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

#34

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 re…

Unicode/text is complicated, and there's a lot of terminology. Describing Rust strings as "a series of grapheme clusters" is maybe confusing, and `chars()` doesn't allow iterating over grapheme clusters.

As the docs point out, they are simply types that either borrow or own some memory (i.e. bytes), and the types/operations guarantee those bytes are valid UTF-8/Unicode code points (aka. characters). A code point is one to four bytes when encoded with UTF-8.

Grapheme clusters are more complicated. Roughly speaking they are a collection of code points that match more what humans expect (and depend on the language/script), e.g. `ü` can actually be two code points `u` + `¨`, and splitting after `u` could be nonsensical. AFAIK, Rust's standard library doesn't really provide a way to deal with grapheme clusters? EDIT: it used to, but it got deprecated and removed [0]

So TL;DR: 1-4 bytes => 1 character, 2+ characters => maybe 1 grapheme cluster. Hope that helps either you, or someone else reading this.

[0] https://github.com/rust-lang/rust/pull/24428

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

#35
post #16

Earlier quoted context omitted.

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 si…

Yeah, but does seem to function bit different than chunks. Plus it's unstable and as expected has perf issues.

It being nightly doesn't mean it will be stabilized.

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

#36
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.

If you use it on a project “True intelligence” is not the word I would use to describe it. I have spent 2-8 hours using it every day since launch as a dev tool. It is very good for learning stuff, scaffolding solutions etc. but it is very bad when you try to do something obscure. For example, I was learning Bazel using it and I spent 2-3 hours trying to debug an issue going back and forth with it. Eventually I went t…

Yeah I'm surprised you're the first person I've seen mentioning that it makes up libraries. I asked it to create a Clojure function to render the mandelbrot set as ascii art, which apparently someone got to work in Erlang with only minimal modifications to the code. For Clojure it seemingly invented the clojure.math.complex namespace and functions it thought should belong there.

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

#37
post #21

ChatGPT finally told me the solution for question: "How do you force borrow checker in rust to allow reusing mutable reference when self is borrowed by a function call, but not returned back, using unsafe is okay"

If you do this, make sure you find a way to test your code under Miri. Unsafe workarounds to this problem might appear to work in practice but are often unsound according to the (likely, future) formal memory model. The situation is similar to a strict aliasing violation in C/C++, where trivial-seeming changes to surrounding code (or flags, or the compiler version) can turn a "benign" or "latent" violation into obser…

One doesnt always have to care about async / future / threading. Especially if its store once, read after data.

Unless you are saying rust can do whatever it wants with its memory without clear specification nor way for you to force it to certain direction, then my answer is that rust has failed as a low level language at that point.

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

#38
post #37

Earlier quoted context omitted.

If you do this, make sure you find a way to test your code under Miri. Unsafe workarounds to this problem might appear to work in practice but are often unsound according to the (likely, future) formal memory model. The situation is similar to a strict aliasing violation in C/C++, where trivial-seeming changes to surrounding code (or flags, or the compiler version) can turn a "benign" or "latent" violation into obser…

One doesnt always have to care about async / future / threading. Especially if its store once, read after data. Unless you are saying rust can do whatever it wants with its memory without clear specification nor way for you to force it to certain direction, then my answer is that rust has failed as a low level language at that point.

It's really the exact same situation with strict aliasing violations in C and C++. If you break the rules (which are different depending on the language but in any case kind of complicated) all bets are off, even in totally single-threaded code, even if all you're doing is integer arithmetic, and in fact even if your code passes ASan and UBSan. If you'll pardon some shameless self-promotion, I have a talk about this that goes into a lot of examples: https://www.youtube.com/watch?v=DG-VLezRkYQ

The nice thing about Rust is that you mostly don't have to worry about any of this if you don't write the "unsafe" keyword. Folks with previous C and C++ experience often come in with understandable but mistaken assumptions about how unsafe code works in Rust, and I think it's important to study the rules carefully before you start writing unsafe code for production use.

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

#39
I just tried something similar to generate a bunch of boilerplate for parsing some deeply nested & complex JSON using Rust/Serde. It gave me a handful of errors, but it was ~90% correct. Which, to be fair, is still shockingly good.

I was already very optimistic about Copilot by itself being able to basically eliminate the need to check StackOverflow/Docs for basic questions. Combined with ChatGPT I can essentially offload all boilerplate I would ever need to write (provided I'm still able to identify & correct the few errors it spits out from time to time).

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

#40
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.

If you use it on a project “True intelligence” is not the word I would use to describe it. I have spent 2-8 hours using it every day since launch as a dev tool. It is very good for learning stuff, scaffolding solutions etc. but it is very bad when you try to do something obscure. For example, I was learning Bazel using it and I spent 2-3 hours trying to debug an issue going back and forth with it. Eventually I went t…

ChatGPT is a doctor's secretary, isn't it? It knows the answers to things like what prescription to get for some illness, but doesn't have the models to actually be a doctor.

Which will come...

Post reply on HN