this post was submitted on 12 Oct 2024
73 points (95.1% liked)
Programming
17484 readers
104 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
What helped me a lot with pushing deeper down into the language innards is to have people to explain things to.
Last week, for example, one of our students asked what closures are.
Explaining that was no problem, I was also able to differentiate them from function pointers, but then she asked what in Rust the traits/interfaces
Fn
,FnMut
andFnOnce
did (which are implemented by different closures).And yep, she struck right into a blank spot of my knowledge with that.
I have enough of an idea of them to just fill in something and let the compiler tell me off when I did it wrong.
Even when designing an API, I've worked out that you should start with an
FnOnce
and only progress toFnMut
, thenFn
and then a function pointer, as the compiler shouts at you (basically they're more specific and more restrictive for what the implementer of the closure is allowed to do).But yeah, these rules of thumb just don't suffice for an actual explanation.
I couldn't tell you why these different traits are necessary or what the precise differences are.
So, we've been learning about them together and I have a much better understanding now.
Even in terms of closures in general (independent of the language), where I thought I had a pretty good idea, I had the epiphany that closures have two ways of providing parameters, one for the implementer (captured out of the context) and one for the caller (parameter list).
Obviously, I was aware of that on some level, as I had been using it plenty times, but I never had as clear of an idea of it before.
I work in a small start-up where I am the only one doing what I do, so my epiphanies come from the struggles I have.
Other people I work with often have a blank look in their eyes when I try to explain some issues or what the code does because they don't have the skillset to comprehend what I am doing. So this isn't a path for me (yet, hopefully we can grow enough where we need more people in my field).
But I appreciate your experience. I will certainly think about a way to play in the innards of my language so that I can understand it better.