Hacker News new | past | comments | ask | show | jobs | submit login

In my Rust code I go back and forth. Coming from JavaScript, I started out trying to do everything in functional expressions - which Rust does as good a job of accommodating as it can - but Rust often requires so much more verbosity (.expect().unwrap().clone()...) that I found myself using local variables again.

And what I realized was that, as fashionable as it is to say these days that imperative code is the devil, Rust's (deeply) const-by-default local variables remove one of the main reasons people have for nesting their expressions inline: avoiding the creation of state that has the chance to be mutated. And I also found that giving names to those intermediate steps can really help improve legibility. For me, Rust has made imperative code cool again, while also allowing for maximally expressions-based code (even more than JS in some ways!) where it makes sense.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: