Closed pickfire closed 4 years ago
It's actually INetworkClient
on purpose. NetworkClient
is the name of the struct, and INetworkClient
is the trait created to be able to test it in that example. I picked the dumb name INetworkClient
because it's the interface to NetworkClient
. It's a "pattern" in Java/C# (that I actually really dislike) but I used here because there wasn't a better name for it.
Thanks for reading over the blog post though, I hope the rest all made sense (:
Interface? But there are no interface in rust though, if it is a trait, why not name it something else like TheNetworkClient
or something clearer? I think I have seen something like that in javascript and it is an anti-pattern for angular.
I think part of the point is that there is no good name for it. I agree that in general the IFoo
"pattern" is less than ideal and not recommended but that's the point in this case.
It cannot be NetworkClient
because that's the name of the struct. TheNetworkClient
does not make sense either because it is not THE network client, it is a trait for anyone that can implement a NetworkClient
. While I agree that INetworkClient
is not ideal, part of the point is that there is no good name for this trait because it doesn't add anything new of value, it just adds abstraction purely for test-sake.
Naming the trait after its (only) function is a Rust pattern. FetchIdMatching
?
That's slightly better but I think for the point that the blog is trying to make it doesn't help since in reality this struct (and therefore the trait) would have a lot of methods. The example is showing a very simplified view of it, and I don't think that renaming it to match the only method helps in the clarity of the post.
I understand that it was confusing for you, @pickfire but I am wondering if there is a way to make my intention more clear without renaming the trait, or renaming it to something that still conveys the point of the post clearly. It is not that I am opposed to editing the post, I just really do not think that TheNetworkClient
or FetchIdMatching
are particularly helpful to understanding what the example is tyring to convey, which is that the trait is unnecessary and in fact causes confusion.
@nrxus I think another solution is to explain I
, an interface which does not appear in Rust. Some languages IIRC have that, but not everyone came from those areas. Looking at C, Go, Python, Javascript and PHP, I don't see how I
fits in (maybe some of those did but from what I know it is an anti-practice), but of course it will be good if the blog is niche.
Could renaming it to TNetworkingClient
be enough? I can then explain why I named it that.
Ah, that would be great. The first thing that came into my mind was Type
but after second thought I think it is Trait
.
INetworkClient
supposed to beNetworkClient