-
Notifications
You must be signed in to change notification settings - Fork 967
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
ToQuantity without displaying the number #61
Comments
Checkout the above pull request. I called the enum Why a flags enum? I don't see a point in it? |
I was thinking a flags enum so that options could be combined. Off hand, I can think of one use case for combining: whether to include an indefinite article. Others may think of more. Here's an iteration that tries combines the best of the suggestions so far: [Flags] enum QuantityComponents { None=0, NumberAsWords=0x1, NumberAsDigits=0x02, IndefiniteArticle=0x04 }; "case".ToQuantity(3, QuantityComponents.None) -> cases |
I like the The contradiction is also apparent in In other words in What am I missing? |
The rule for the You're right that the flags overlap and sometimes have no effect. I see that as reflecting the non-linear nature of languages, just as |
"In English, an indefinite article is only permitted for a quantity of one.". I don't think that's accurate. AFAIK indefinite article is for when the object/article is unknown to the listener and could be about one or many of it and apparently "a", "an", "some" and "any" can be used for indefinite articles. More info on WikiPedia. |
The things you don't learn in the process of coding! I certainly didn't have plural indefinite articles in mind, nor can I think of any use cases for them, but if the term "indefinite article" includes plural, it would be confusing to give a different semantic. However, since the info came from Wikipedia, I thought I should check it. I looked in my personal favorite, the Oxford English Dictionary, and what do you know? It says that only singular is included. I flagged the Wikipedia article and posted on the talk page so that hopefully an expert will weigh in. |
Added ShowQuantityAs parameter to ToQuantity - #61
That makes sense. I like IndefiniteArticle and would like to add support for it to Humanizer; that said I am going to leave it out for now. I will close this issue with #62 that addresses this issue directly. IndefiniteArticle is something that could be used in other APIs too. Added #63 to address that. |
For forward compatibility, it's important to determine the long-term API before shipping a version with support for omitting the number. As it stands now, the merged pull request uses a non-flags enum. Normally, changing a non-flags enum to a flags enum requires a breaking change. That's because the .NET Framework convention for enums is a singular noun for non-flags enums and a plural noun for flags enums. That way the type of enum is readily distinguishable.
|
I did consider the long-term API. TBH I am not sold on the flags enum. Flags enums are good when all or at least most options can be mixed while in this case they cannot; e.g. WRT the name, IMHO “Programs must be written for people to read, and only incidentally for machines to execute.” :) |
FWIW I totally agree with @MehdiK here; a flags enum would be really weird and also fairly inconsistent with the rest of the API surface area inside of Humanizer. I'd suggest that if multiple options were needed in the future then assuming there are only a few valid options that make sense (like described above) you could simply add them to the non-flags enum thus making it much clearer to understand for consumers of the library. |
I agree that a flags enum that mixes mutually and non-mutually exclusive fields can be confusing. In the Even though I've now drunk the non-flags enum Kool Aid, I'm not so sure about using a verb-phrase for the enum name - not that I'm sure about using a conventional, stuffy, starched-collar noun-phrase, either. If I may be more than a trifle dramatic, there is an epic cosmic trade-off between the good of each individual method, which wants to tune itself to its ideal nuanced personality, which struggles against the grander assimilated API, which craves consistency and order, striving to keep its ranks regimented when soldier-methods from widely different backgrounds line up together on the coding battlefield. |
Provide a mechanism to optionally omit the number from the
ToQuantity
result. For example,"case".ToQuantity(5, QuantityOptions.OmitNumber)
would be "cases", whereOmitNumber
would be aFlags
enum.The text was updated successfully, but these errors were encountered: