dotnet / command-line-api

Command line parsing, invocation, and rendering of terminal output.
https://github.com/dotnet/command-line-api/wiki
MIT License
3.36k stars 375 forks source link

Consider a more commonly-known word than "arity" #1893

Open jonsequitur opened 1 year ago

reduckted commented 1 year ago

What about ValueCount?

public readonly struct ArgumentValueCount : IEquatable<ArgumentValueCount> {
    // ...
}
public abstract class Argument {

    public ArgumentValueCount ValueCount { get; set; }

    // ...

}
public static readonly Argument<FileSystemInfo?> Target = new("target") { 
    ValueCount = ArgumentValueCount.ZeroOrOne
};
KalleOlaviNiemitalo commented 1 year ago

Was discussed in https://github.com/dotnet/command-line-api/issues/2046 but not decided.

andrewimcclement commented 1 year ago

Given that Arity has exactly the desired meaning, would it be better to provide a suitable summary comment for people unfamiliar with the term? Part of my concern is that as soon as I see something like Count or Number I expect an integer type, which is incorrect in this instance.

tkapin commented 11 months ago

I just stumbled upon this issue when checking the API changes (listed in #1891). Since it's open for discussion, I'd like to support the opinion to keep using the term "arity". While this term might not be recognized by many developers (for example by folks who don't have formal mathematical or computer science education), it expresses the entity exactly (see Arity on Wikipedia for reference) and makes perfect sense to people familiar with the term.

Another benefit of using the proper formal term "arity" rather than an approximation is also an educational effect. It expands people's knowledge ("Oh, that's how this thing is called!") and helps to coin the right terminology which in turn results in better understanding between developers.

lukewis commented 8 months ago

After reading through #2046 , I'm happy to have a dedicated space (here) to discuss this. I'm afraid I don't have a perfect answer to this question (I suggest a few "less than ideal" possibilities in #2292) , but I very much appreciate the discussion.

I don't think anyone refutes the "correctness" of the term Arity. It's more a problem of "discoverability". By sharing some of the story of how I came to "discover" this property (below), I hope to raise some awareness on the importance of choosing terminology that is "ubiquitous" (any DDD fans?) across the developer community.

If I hadn't discovered a bug, cared enough to dig deeply into the source written a github issue, and gotten lucky when a contibutor responded and "happened" to mention a term I'd never heard before in their response, it's very possible I never would have discovered this property.

I'm also not a fan of the term Cardinality (discussed in the other thread) for the same reasons. This term I've heard of, but not often enough to memorize the definition.

Until I looked at the possible values for Arity, I also did not realize that a single argument accepting multiple values was even a possibility (nor do I fully understand the use case or how that would look in example commands). Would it be something like this (where pepperoni, sausage, ham are modeled as a single argument with Arity = ZeroOrMore)? Can someone help with a real-world example of when this is used?

restaurant order pizza pepperoni sausage ham
KalleOlaviNiemitalo commented 8 months ago

Parsing similar to ZeroOrMore is usual in Unix utilities that take a list of file names, e.g. cat or ls; it works nicely together with wildcard expansion (globbing) in the shell. Typically though, if the list is empty, then each utility uses some default value instead: cat reads from standard input (like cat -) and ls lists the working directory (like ls .).