IntelliTect / IntelliTect/CodingGuidelines

Flag optional arguments on methods that differ from their interface declarations

オープン
#102 コメント 5 件 リアクション 0 件 担当者 4 名 GitHub で見る

@GrantErickson がすでに取り組んでいます。

2020年4月10日 から。

documentation
主要言語
C#
スター
12
フォーク
16
平均マージ
2分
マージ済み PR(30日)
7

説明

Consider the following case:

public class Foo : IFoo
{
    public void Bar(int value = 2) => Console.WriteLine(value);
}
public interface IFoo
{
    public void Bar(int value = 1);
}

public static void Main(string[] args)
{
    IFoo foo1 = new Foo();
    foo1.Bar();
    var foo2 = new Foo();
    foo2.Bar();
}

Output:

2
1

I would propose that the coding standard be

DO NOT: declare optional arguments on class methods that are implementing an interface.

Rational:

  • If these value are not in sync it will cause behavior as shown above.
  • It is possible to declare a constant and share it in both places. However, if you have an interface for accessing the class, why is there code bypassing it? If you want to invoke the method using the default value, simply go through the interface.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。