Skip to content

Revisit: parameters and tuples #140

@bkoelman

Description

@bkoelman

It looks like #127 was merged, but then lost in the site migration process. So the change did not make it into the current release.

That's fortunate, because I would like to revisit my earlier proposal at #127, which limited the number of values flowing in and out to four.

An alternative approach would be to keep the number of incoming values to 3, and then allow at most 2 (or 3) values going out.

The earlier proposal allowed incoming tuples, which may not be so practical after all. Consider the next code snippet:

class Demo
{
    (string First, string Middle, string Last) GetName() => throw new NotImplementedException();

    void SaveName((string First, string Middle, string Last) name) => throw new NotImplementedException();
    void SaveName(string first, string middle, string last) => throw new NotImplementedException();

    void Caller()
    {
        var name = GetName();

        SaveName(name);
        SaveName(name.First, name.Middle, name.Last);
    }
}

Only in the example above the tuple-based overload makes the calling code a bit shorter. But it seems like a theoretical example. What are the benefits of tuple parameters, if any?

Also the existing rule is a bit ambiguous: the first overload of SaveName has 3 or 4 incoming values, depending on whether name is included in the count.

Maybe it would be better to advice against tuple parameters?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions