Which one is recommended considering readability, memory usage, other reasons?
1.
String strSomething1 = someObject.getSomeProperties1(); strSomething1 = doSomeValidation(strSomething1); String strSomething2 = someObject.getSomeProperties2(); strSomething2 = doSomeValidation(strSomething2); String strSomeResult = strSomething1 + strSomething2; someObject.setSomeProperties(strSomeResult);
2.
someObject.setSomeProperties(doSomeValidation(someObject.getSomeProperties1()) + doSomeValidation(someObject.getSomeProperties2()));
If you would do it some other way, what would that be? Why would you do that way?
I would probably go in-between:
Option #2 seems like a lot to do in one line. It’s readable, but takes a little effort to parse. In option #1, each line is very readable and clear in intent, but the verbosity slows me down when I’m going over it. I’d try to balance brevity and clarity as above, with each line representing a simple ‘sentence’ of code.