New Design Guideline: Be consistent in naming parameters when overloading, overriding and implementing interfaces

We have seen this come up a more than a few times in WinFX API reviews so I thought it was worth adding a quick guideline… As always, please let me know if you have any questions or comments.

You can check out the base design guidelines and my incremental updates.

 

 

Do be consistent in naming parameters when overloading, overriding and implementing interfaces. This discipline increases the developer perception of connection and interrelation between the methods. FxCop rule request Xxx.

Implementing Interfaces:

    public class IComparable

    {

        int CompareTo(object x, object y);

    }

    public class FooComparable : IComparable

    {

      //Correct

public int CompareTo(object x, object y)
{

}

      //Incorrect

      public int CompareTo(object value1, object value2)

      {

      }
     

    }

Overriding Members:

    public class Object

    {

        public virtual bool Equals(object obj)

        {

        }

    }

    public class MyClass

    {

      //Correct

        public overide bool Equals(object obj)

        {

        }

       //Incorrect

       public overide bool Equals(object value)

        {

        }

    }

Overloading:

    public class String {

      //Correct

        public int IndexOf (string value) {}

        public int IndexOf (string value, int startIndex) {}

        public int IndexOf (string value, int startIndex, int endIndex) {}

       //Incorrect

        public int IndexOf (string value) {}

        public int IndexOf (string str, int startIndex) {}

        public int IndexOf (string value, int beginIndex, int endIndex) {}

    }