this post was submitted on 24 Oct 2023
51 points (100.0% liked)
Chat
7498 readers
2 users here now
Relaxed section for discussion and debate that doesn't fit anywhere else. Whether it's advice, how your week is going, a link that's at the back of your mind, or something like that, it can likely go here.
Subcommunities on Beehaw:
This community's icon was made by Aaron Schneider, under the CC-BY-NC-SA 4.0 license.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
About your specific example I find the Rust code to be much simpler to understand than your equivalent Golang code..
To understand the Rust code I just have to understand each case. 0..1 returns false. Ok. 2..n returns true iff no divider was found between 2 and n-1. Ok the function is primality test
The Golang code is much harder. I do not take into account the division by 2 because its not part of the original Rust code.
A for loop starting at 2 that look for divisors. Then the return value > 1. Why is it OK to just return
value > 1
? Oh that's because the loop did not return. Why did it not? Either no dividor was found or we did not get into the loop at all. If value > 1 we have the guarantee the loop was executed so it's really a primal number. If value <= 1 it is either 0 or 1 which are not primal. Ok, so we return value > 1.I think people dislike Rust because it has a lot of functional languages constructs and people are not used to code in functional languages.
Whatever you fight in Rust you end up saving time by avoiding runtime bugs that would have plagued your productivity anyway. I'd much rather have a language with a hard entry but with solid and maintainable code rather than fast-written spaghetti that no one knows what it is supposed to do 2 years after.