nrxus / faux

Struct mocking library for Rust
https://nrxus.github.io/faux/
MIT License
411 stars 14 forks source link

fix typo #25

Closed pickfire closed 4 years ago

pickfire commented 4 years ago

INetworkClient supposed to be NetworkClient

nrxus commented 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 (:

pickfire commented 4 years ago

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.

nrxus commented 4 years ago

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.

audunhalland commented 4 years ago

Naming the trait after its (only) function is a Rust pattern. FetchIdMatching?

nrxus commented 4 years ago

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.

pickfire commented 4 years ago

@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.

nrxus commented 4 years ago

Could renaming it to TNetworkingClient be enough? I can then explain why I named it that.

pickfire commented 4 years ago

Ah, that would be great. The first thing that came into my mind was Type but after second thought I think it is Trait.