rspec/rules/S2360/description.adoc

6 lines
925 B
Plaintext
Raw Normal View History

2020-06-30 12:48:07 +02:00
The overloading mechanism should be used in place of optional parameters for several reasons:
2020-06-30 12:48:07 +02:00
* 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.
2021-01-26 14:30:57 +01:00
* 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 {cpp}/CLI), you will have to provide all arguments. When using method overloads, you could achieve similar behavior as default arguments.
2020-06-30 12:48:07 +02:00
* 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?