A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2219 below:

[java] Document Reasons to Avoid Reassigning Parameters · Issue #2219 · pmd/pmd · GitHub

Affects PMD Version:

6.20.0

Rule:

Java Best Practices - AvoidReassigningParameters
https://pmd.github.io/latest/pmd_rules_java_bestpractices.html#avoidreassigningparameters

Description:

The comment for this rule is:

Reassigning values to incoming parameters is not recommended. Use temporary local variables instead.

This comment does not tell me why reassigning parameters is "not recommended". Please add reasons why this is a bad idea so that users can make better informed decisions about the rule.

I tried looking for reasons on the Internet. One reason was due to parameters being passed via reference as in C/C++. This is not applicable to Java since the method parameter reference can be changed without impacting the caller. Here is another reason:

Multiple assignments of different values to a single parameter make it difficult for you to know what data should be contained in the parameter at any particular point in time. The problem worsens if your parameter and its contents are documented but the actual value is capable of differing from what’s expected inside the method.

Please find other reasons for this rule and add it to the documentation.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4