Opcjonalne parametry metod - hit czy kit?

0

W którejś tam wersji C# wprowadzono opcjonalne parametry.

I tak, u nas w tyrce wdrozyli SonarQube. No i sie zaczeło..... Bo Sonar nie lubi tych parametrów.
cytat z Sonara:

The overloading mechanism should be used in place of optional parameters for several reasons:

Optional parameter values are baked into the method call site code, thus, if a default value has been changed, all referencing assemblies need to be rebuilt, otherwise the original values will be used.
The Common Language Specification (CLS) allows compilers to ignore default parameter values, and thus require the caller to explicitly specify the values. For example, if you want to consume a method with default argument from another .NET compatible language (for instance C++/CLI), you will have to provide all arguments. When using method overloads, you could achieve similar behavior as default arguments.
Optional parameters prevent muddying the definition of the function contract. Here is a simple example: if there are two optional parameters, when one is defined, is the second one still optional or mandatory?

Jakos nie przekonują mnie te argumenty, nijak sie mają do mojego projektu.
Czy ślepe podążanie za tymi zasadami ma sens?

1

Jesli kierujesz pytanie poza świat C# byłoby prościej jakbyś opisał co to są "opcjonalne parametry" lub dał linka co to. Jeśli dobrze rozumiem dokumentację to w Scali nazywany to parametrami z wartościami domyslnymi. Czasem używam, ale nie lubię. Ale ja już nawet przeciążania nazw metod nie lubię i staram się nadawać różne nazwy

4

Wdróżcie Sonara nowszego niż 5 lat. :)
Albo skonfigurujcie swojego. Niektóre reguły Sonara są po prostu z czapy, i trzeba je wyłączyć.

1

Chyba tylko pierwszy argument:

Optional parameter values are baked into the method call site code, thus, if a default value has been changed, all referencing assemblies need to be rebuilt, otherwise the original values will be used.

Mnie jakoś przekonuje. Bo reszta to trochę bzdury patrząc po tym, że C++/CLI jest martwym bytem, który MS utrzymuje chyba tylko z przymusu.

1 użytkowników online, w tym zalogowanych: 0, gości: 1