Whats best practice to use 1 string in 2 places – e.g. 2 types of logging.
I sometimes have a situation like this.
System.out.println ("Error No 1: " + errstr);
log.print ("Error No 1: " + errstr);
Then the best I can think to make it better is this (for not having more than 1 string).
String str = "Error No 1: " + errstr;
System.out.println (str);
log.print (str);
Sure, I can hide it.
my.log ("Error No 1: " + errstr); // does both by implementation
But if it is not used often it may increase complexity instead of decrease it.
Maybe the question is opinion-based – but I think it is worth asking if it makes my coding better.
1