It is bad form to use the same string literals multiple times in the same module or method:
- it can lead to problems with further maintenance, if necessary, change the value - there is a high probability of missing one of the repetitions
- it can be a consequence of "copy-paste" - the developer may have forgotten to change the code after copying a similar block of code.
- Diagnostics with default settings does not respect the case of literal characters - the strings
AAAA
andAaaA
are considered the same. - You cannot specify a minimum parsed literal value less than the default. Short service literals are often used, which will generate unnecessary comments. For example: empty string "", selector numbers "1", "0", etc.
- You cannot reduce the allowed number of repetitions to less than 1, because it makes no practical sense.
Bad code
Procedure Test(Param)
Result = "Value";
If Param = "One" Then
Result = Result + One("Value");
Else
Result = Result + Two("Value");
EndIf;
EndProcedure
Сorrected:
Procedure Test(Param)
Result = "Value";
If Param = "One" Then
Result = Result + One(Result);
Else
Result = Result + Two(Result);
EndIf;
EndProcedure
Bad code
Procedure Test2(Param)
Result = "Value";
If Param = "One" Then
Result = Result + One("Value");
Else
Result = Result + Two("Value");
EndIf;
EndProcedure
Procedure Test3(Param)
If Param = "Five" Then
Result = Result + Five("Value");
EndIf;
EndProcedure
Сorrected
Procedure Test2(Param)
Result = "Value";
If Param = "One" Then
Result = Result + One(StringValue());
Else
Result = Result + Two(StringValue());
EndIf;
EndProcedure
Procedure Test3(Param)
If Param = "Five" Then
Result = Result + Five(StringValue());
EndIf;
EndProcedure
Function StringValue()
Return "Value";
EndFunction