4 ms·
Another step in getting proficient with ampersand (or rather immutable refs), is pulling stuff from enums and structs, in an immutable way. I.e. Option<SomeStru
by kjuulh 4y ago
Another step in getting proficient with ampersand (or rather immutable refs), is pulling stuff from enums and structs, in an immutable way. I.e. Option<SomeStruct>, or Result<SomeStruct, ErrorKind>. Using as_ref and friends.
There was a great post the other day about the "Register of rust", and getting to know all the different variants of these features to be proficient and being able to build whatever you want.
The same goes for async features as well. Async especially requires that you understand lambdas, borrow checking and so on. As it can be quite tricky to send a value to a tokio::task::spawn!(...) if you don't have some mastery over the borrow checker.
When you get to taking lambda in a func, that should be async then you begin to get into the weeds of rust, and where some of the nasty compilers errors show up, some of the unhelpful variants, where you are expected to know the intricacies of how lifetimes work, and how rust handles generics vs impl vs enums etc.
In the beginning I just recommend using a good old Arc<Mutex<...>> if you need to pass stuff to functions, you can still shoot yourself in the foot, but you can take the optimizations piecemeal.
- PaulHoule 4y agoI’m not sure I like the word ‘register’ in that if you are singing a song you might choose to switch registers from time to time to hit all the notes whereas a song is going to have certain music features consistent throughout the song. In programming you might use different ‘registers’ in different parts of a program, but for all of the lower teachings about ‘encapsulation’, ‘information hiding’, and such programs as a whole have to have certain global invariants respected if they are going to work correctly…. Particularly when it comes to memory management! Garbage collection is a great facilitator for encapsulation because it means you can just allocate and not think at all about deallocation. A strength of C is that each program can implement a custom optimal memory handling strategy but that’s a roadblock to reuse with libraries because any library has to adapt to the memory allocation strategy of the program as a whole. Superficially it looks as if objects, inheritance, and polymorphism are the key features for code reuse in Java but I’d make the case that the garbage collector is more fundamental - you certainly lose some performance but neither C nor Rust has managed the feat that LISP and Java has of encapsulating memory management in a way that allows arbitrary code to work in the same runtime together.
- nerpderp82 4y agoArticle is worth a read, isn't referring to musical registers. https://without.boats/blog/the-registers-of-rust/ https://without.boats/blog/the-registers-of-rust/ https://en.wikipedia.org/wiki/Register_(sociolinguistics) https://en.wikipedia.org/wiki/Register_(sociolinguistics)
- PaulHoule 4y ago(1) I read that article, (2) I think the sociolinguistic term is derivative of the musical term or the other way around and it is the same in that you can change registers in the same document.
- JohnFen 4y agoI know this is a personal issue, but I find the use of "registers" in that article to be very confusing, because to me, a "register" is a slot in the CPU that holds a value to be operated on, or is the result of an operation. That's so deeply ingrained into my mind that I really struggle to interpret it differently.
- nerpderp82 4y agoHow about using Register Renaming to have a different set for different domains. Business registers, scientific registers, lolcat, etc? :)