In light of just having been made aware of a bug (written by yours truly ) where three functions have the same implementation due to non diligent use of copy paste, I thought it would be a good idea to make a post about this.
It is likely a bug if functions have exactly the same implementation. Maybe if the function body consists of only one function call there could be an argument to allow duplicates from a readability standpoint.
Functions whose bodies are non-trivial that differ at most by the name of local variables, including parameters are candidates for non-conformance for this rule.
Maybe itās worth considering this rule on a per-class basis. Member functions of different classes could conceivably have the same implementation, especially in terms of using member functions/variables that are not public. However, if functions on the same class are more likely to be subject to this rule.
Iām sorry but I canāt seem to find the code I fixed that relates to this suggestion.
Iām not sure how I didnāt find this rule, but for what itās worth, I brought this up as a general topic that relates to many programming languages. Iām personally working in C++ most of the time. Maybe part of the confusion is that in some languages thereās a rule called Methods should not have identical implmentations, while in some others, thereās Functions should have identical implementations. It appears that C++ only has the alternative about methods. So maybe I searched for something and specified āfunctionsā for C++, and didnāt find the specific rule, then proceeded to assume that it didnāt exist for any programming languages.
Either way, though, I suspect that this rule didnāt trigger in my case because I write a lot of functions in C++ that arenāt member functions. As far as I know, that is the preferred lingo about this in the context of C++, instead of methods. So maybe the rule for C++ only checks for identical member functions of the same class, while free functions are out of scope for that specific rule? Which I guess would go to show that thereās a difference between methods and functions. I noticed that for python specifically, the rule is called Functions and methods.... Which certainly implies thereās a difference.
Thanks for the reply. As far as there is no reproducer I canāt investigate why Java rule wasnāt triggered.
If you think your feedback about methods and functions in C++ is still relevant, you can open another thread and add c++ tag. So the proper language specialist will answer you. For this thread, I think we can close it.