-
Notifications
You must be signed in to change notification settings - Fork 966
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
Allow pluralization/singularization to be controlled by a boolean. #25
Conversation
Thanks for the contribution. I like it. I will check it out soon and will get back to you. |
On a second thought I just had a look and there are a bunch of other methods that look and behave like these two methods. I think having the condition on two methods and not on others makes the API inconsistent. So I guess I have to say no to this! If you need this on your code, you could obviously create a simple extension method that checks for the bool value and conditionally calls Humanizer's Pluralize etc. |
Would you be interested in me adding Regardless, I am still curious what you think of:
I seem to find myself implementing this sort of logic in nearly every web app I work on, or resorting to "x request(s)". |
Frankly I don't like I quite agree about the need for a smarter Pluralize though. Lets leave the existing method alone and create an overload with A separate PR? :) |
Happily. — On Mon, Nov 11, 2013 at 4:52 PM, Mehdi Khalili notifications@github.com
|
Using a count rather than a boolean is much more flexible. English is simple compared to other languages in that it only has two conjugations of a noun based on the number. Other languages vary - quite a bit, actually. Fortunately, there is a lot of work done on this already. Take a look at Quantity Strings in the Android documentation. It's very well thought out. Based on my experience on Android, I'd recommending keeping |
ToQuantity sounds subtly wrong to me as one as adjoining a quantity, rather than converting to a quantity. I wonder if WithQuantity(...) is more descriptive. ToQuantity is probably more discoverable. A quantity extension sounds better to me than a pair of pluralize/singularize overloads. — On Fri, Dec 20, 2013 at 11:03 PM, Mehdi Khalili notifications@github.com
|
I would prefer |
The convention in the .NET Framework is to use "As" when the result is another view into an existing object and "To" when the result is a new object. The extension methods on IEnumerable serve as good examples. Since the quantity method returns a new string object, per convention, the prefix should be "To". |
I think both As and To will work & happy with both. @breyed has a good point on .Net conventions tho so I vote for |
Although @breyed 's point is quite relevant in terms of consistency with .NET Framework's existing API design, I found |
The Humanizer methods are a conversion API. The By contrast, in conversion APIs, each operation is distinct, and order can be significant. For example, System.String is a conversion API. Humanizer is similar. Since Humanizer is a conversion API, I think it is better to model it after others like it such as |
Great tips @breyed. Now I see that |
@breyed has good points that are hard to argue with. So let's go with Thanks a lot everyone for your inputs & thoughts. |
I still feel that ToQuantity is not perfect. The behaviour of this method (that takes a string/noun and a integer/quantity) is less like Just because our method returns a new string doesn't mean it has to start with
|
I agree that |
I too agree An |
Oh, and thanks a lot everyone for your great inputs. I loved this thread. |
I realize we're talking hypothetical here, but I'd caution against redundant methods. I've thought so ever since I read Effective C++ by Scott Meyers many years ago. It contains a principle Strive for interfaces that are minimal and complete, which applies equally well to .NET. That said, it's no fun being saddled with legacy APIs (e.g. one of the few things I dislike about Python is how it borrowed so much of the baggage from the C standard library). So should a better idea come around, I'm all in favor into making it available. However, in general, I'd try to bundle a number of changes together into a version 2 of the API, and put the new API into a different namespace. This would keep compatibility with old code while allowing new code to use the new API, which would still be minimal and complete. |
I would like your thoughts on being able to control these extension methods with a bool like:
Maybe I should take it further to be: