-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foo Bar (ad nauseam) #403
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In src/anti_patterns/deref.md:
I've skipped the code, and it goes on like that in the following paragraphs.
There's a tendency for people to abuse the Foo/Bar to avoid looking for an educational example, especially in Rust. It saves the writer time and effort, but reading this really makes little sense. Using evocative names will make it much easier for the reader to understand and memorize the concept, because that's how our brain works. 🙂
Why not use a wrapper around, say,
HashMap
, and useDeref
to override a method likeinsert
that checks a requirement, modifies the data, or stores a complement of information?I'd also argue that it's not such an antipattern. The idea of
Deref
is giving some transparency to a wrapper, which is what we're doing here, andDeref
isn't more of a suprising idiom when used with this idea in mind than when using it for other wrappers in general, like smart pointers. If one argument had to play against this practice, it would be point 2 of the "shouldn't" part in the Deref documentation: method name collision — which would be better illustrated with a practical case likeHashMap::insert()
than random foobarness.The text was updated successfully, but these errors were encountered: