Third, by being declarative, functional programming is said to be closer to Human (mathematical) reasoning and thus easier to reason about.
This last point can be debated because most programmers learn imperative and Object-Oriented programming during their training, and thus functional programming kind of require them to re-learn how to code.
I disagree that it can be debated. Human reasoning is sometimes functional and sometimes imperative, and Rust is as comfortable as it is because, as a multi-paradigm language, it enables you to use the right tool for the job.
A classic example would be implementing iteration using recursion. The most intuitive way is just to say "do this, then this, then this"... not to re-conceptualize it as a nested sequence of "head, tail" operations... and that's before you account for the transformation that's often needed to make functions tail-recursive. I didn't get that one until the trick was explained to me.
That's not just a matter of "What were you taught first?" One way is closer to intuitive human reasoning outside the world of the computer than the other is.
// you can't longer use v
Correction: The phrasing is "you can no longer use v".
First, because "[can] [no longer]" is the tokenization, not "[can no] [longer]". "no longer" is a single semantic token distributed across two words.
Second, because "can't" is a contraction of cannot rather than "can no". That's where the t in can't comes from. can[no]t. (It's cannot rather than can not because we've grown so used to cannot that writing can not implies an attempt to say "capable of choosing not to..." rather than "incapable of choosing to..." ...a subtle distinction in spelling that's much more recognizable in spoken communication since it's something you emphasize using pacing and tone of voice.)
map is used to convert an the items of an iterator from one type to another:
Remove the "an"
Here from &str to String.
You want a comma after "Here" because the natural ordering for the sentence puts "here" at the end and you use a comma to denote transitions where you've pulled a clause or interjection out of its natural order. (eg. "As a programmer, I enjoy it" as opposed to "I enjoy it as a programmer".)
Otherwise, you run the risk of people getting knocked out of the flow while reading because their brain mis-guessed the correct parse and had to backtrack and try again based on information revealed later in the sentence.
Enums are certainly the favorite Rust's feature of new Rustaceans because they are the foundations of Result and Option.
And with good reason beyond that. Sum types (data-bearing enums) are just as fundamental as product types (structs), but they've been brushed under the rug for decades by popular programming languages... likely no thanks to C only having untagged unions and so many languages taking inspiration a little too directly from C.
Worker pools are commonly used to process jobs concurrently, such as HTTP requests, file hashing, and so on. But in Rust, they are an anti-pattern because their APIs often favor imperative programming, mutable variables (to accumulate the result of computation) and thus may introduce subtle bugs.
Maybe say "But in Rust, using them directly is an anti-pattern"? After all, pools of worker threads are what libraries like Rayon are using under the hood.
Also, even worker pools are less of a concern in Rust, thanks to Rust's ownership model encouraging use of message passing via channels rather than shared state.
1
u/ssokolow Mar 09 '22 edited Mar 09 '22
I disagree that it can be debated. Human reasoning is sometimes functional and sometimes imperative, and Rust is as comfortable as it is because, as a multi-paradigm language, it enables you to use the right tool for the job.
A classic example would be implementing iteration using recursion. The most intuitive way is just to say "do this, then this, then this"... not to re-conceptualize it as a nested sequence of "head, tail" operations... and that's before you account for the transformation that's often needed to make functions tail-recursive. I didn't get that one until the trick was explained to me.
That's not just a matter of "What were you taught first?" One way is closer to intuitive human reasoning outside the world of the computer than the other is.
Correction: The phrasing is "you can no longer use v".
First, because "[can] [no longer]" is the tokenization, not "[can no] [longer]". "no longer" is a single semantic token distributed across two words.
Second, because "can't" is a contraction of
cannotrather than "can no". That's where thetincan'tcomes from.can[no]t. (It'scannotrather thancan notbecause we've grown so used tocannotthat writingcan notimplies an attempt to say "capable of choosing not to..." rather than "incapable of choosing to..." ...a subtle distinction in spelling that's much more recognizable in spoken communication since it's something you emphasize using pacing and tone of voice.)Remove the "an"
You want a comma after "Here" because the natural ordering for the sentence puts "here" at the end and you use a comma to denote transitions where you've pulled a clause or interjection out of its natural order. (eg. "As a programmer, I enjoy it" as opposed to "I enjoy it as a programmer".)
Otherwise, you run the risk of people getting knocked out of the flow while reading because their brain mis-guessed the correct parse and had to backtrack and try again based on information revealed later in the sentence.
And with good reason beyond that. Sum types (data-bearing
enums) are just as fundamental as product types (structs), but they've been brushed under the rug for decades by popular programming languages... likely no thanks to C only having untagged unions and so many languages taking inspiration a little too directly from C.Maybe say "But in Rust, using them directly is an anti-pattern"? After all, pools of worker threads are what libraries like Rayon are using under the hood.
Also, even worker pools are less of a concern in Rust, thanks to Rust's ownership model encouraging use of message passing via channels rather than shared state.