Conversation
Edited 9 months ago

one thing about #Rust that I wish people would emphasize to programmers who are interested in learning it is: you absolutely need an IDE (edit: or LSP-capable editor!) - and need to know how to use its features well - in order to learn Rust

because here’s the thing. for every single variable, argument, return value, etc. in Rust, you have to keep all of the following in mind:

  • lifetimes
  • mutability
  • monads
  • references
  • ownership
  • sometimes trait bounds
  • probably even more stuff that I’m not thinking about right now

and in my experience this is an impossible amount of cognitive load, even for very simple programs, unless you have an IDE/LSP to help you with it - by E.G. showing you a function’s signature as you’re supplying it with arguments, and giving you inlay type hints to keep track of the nuances of each variable

and because of this huge jump in complexity compared to most languages, that means you have tons of methods that all do almost the same thing, but with some Rust-specific nuances to keep in mind. like consider the difference between .iter(), .iter_mut(), and .into_iter(). in most other languages, these would all be the same method, because most other languages don’t have a concept of “returning an immutable value” or “returning an owned value”

but of course an IDE/LSP will let you just type .iter and show you every method that has iter in the name, which tells you which options are available to you and helps a lot with considering what you want

also, the Rust compiler is incredibly picky (which is a good thing! kinda). without an IDE it will feel like rustc is expecting you to keep track of every single detail of every single variable at all times (again, impossible cognitive load) and is just waiting for you to make a mistake. sometimes it’s not even clear what it wants from you

after a while of trying to use Rust without an LSP I ended up creating superstitions around the compiler. “trying to pass information between threads has angered the gods. nothing seems to calm their ire. this will be a single-threaded program to appease them”

but if you get live feedback from your IDE - in real-time as you’re typing your code - it’s much easier to build an intuition around what Rust expects from you and what will make it angry

so yeah don’t try to use Rust if you don’t have an IDE, or you don’t know all of your IDE’s features yet. you will go insane

9
5
16

@kasdeya
An lsp capable editor suffices.

1
0
1

@apublicimage true! to be honest I’m not totally clear on the difference - I thought that they were both considered IDEs. I’ve actually been using neovim with a Rust LSP

1
0
1

@kasdeya 🤷 I learned Rust without an IDE. Definitely wasn't easy, but it's possible.

FWIW some people I've worked with have been hamstrung by compiler errors being malformed/truncated by the IDE, but they showed up as intended on a command line.

0
0
1

@kasdeya it’s definitely much easier with inline type hints but it’s not impossible. I first started with a standard text editor, the compiler errors are pretty good and docs.rs is a godsend.

0
0
1

@algebraicterror Rust probably has another name for them, but I’m talking about Ok and Err and Some and None - types that exist to wrap data in order to give them more context, functionality, etc.

0
0
1

@kasdeya I agree it’s helpful. I disagree that it’s necessary. The error messages are so good from rustc that I feel like it obviates the need for an IDE. I do recommend bacon though for incremental feedback. I use Emacs with lsp turned off because it felt, I don’t know, too slow.

0
0
1

@kasdeya Yeah, I too have wondered if people who say that Rust is too difficult have tried learning it without an IDE or something.

1
0
0

@kasdeya Although now IDEs ship with “AI autocompletion” or other generative nonsense, which may make them less helpful than they usually have been. I like RustRover but had to turn some autocomplete features off because I was constantly fighting against its verbose, often nonsensical completions.

0
0
0

@algebraicterror @kasdeya Option and Result are technically Monads, so I guess those are what was meant.

However, you can also define a Monad trait in Rust (e.g. https://github.com/bodil/higher), but afaik nobody in their right mind uses this for production code.

(I am still occasionally working on a Visual Novel player that does use the Monad trait - together with a Free Monad, and a State Monad. https://www.grois.info/posts/2023-03/2023-03-11-adventures-with-free-monads-and-higher.xhtml https://www.grois.info/posts/2023-11/2023-11-19-writer-and-state-monad-in-rust-based-on-higher.xhtml)

0
0
1

@mattesilver that’s exactly what I use! I haven’t tried any others, but it seems to be pretty fully-featured and helpful

0
0
0

@kasdeya

Same here, using Emacs with lsp. I just never thought that this is considered an IDE. There are tons of stack overflow questions "how do I turn my emacs into an IDE" but it might be the case that lsps changed that game. In any case, rust analyzer is great and helps a lot to understand what you are doing.

0
0
1

@kasdeya
I did learn rust using vim, with no rust plugin or anything. Yes, rust is picky. But it's not an inhuman task to learn without an IDE. You keep track of scope and lifetimes and so on in every language (yes, badly, imperfectly - which is why rust is an improvement).

I think perhaps this is related to how much you use an IDE in general; if you learned programming using IDEs and rely on them day to day then learning rust may be a larger mental adjustment than if you normally don't.

0
0
0

@kasdeya I disagree on this one. When I first learned Rust, I used a plain editor (geany in fact). Rust-Analyzer didn't exist back then, and the best we had was racer (which the first rust-lsp actually used, though it also added its own slower and memory hungrier implementation).

So no, you don't need to keep all the lifetime and ownership information in your head. You simply code until the compiler tells you something's wrong, then you find out how to make that work, and off you go. And yes, that works better with Rust-Analyzer, and now that I have enough cores and RAM, I use it regularly (via the helix editor). But it worked without it back then, thank you very much.

0
0
0