Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is preferred option for assignment and formatting?

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?

like image 911
Sajal Dutta Avatar asked Nov 27 '22 22:11

Sajal Dutta


1 Answers

I'd go with:

String strSomething1 = someObject.getSomeProperties1();
String strSomething2 = someObject.getSomeProperties2();

// clean-up spaces
strSomething1 = removeTrailingSpaces(strSomething1);
strSomething2 = removeTrailingSpaces(strSomething2);

someObject.setSomeProperties(strSomething1 + strSomething2);

My personal preference is to organize by action, rather than sequence. I think it just reads better.

like image 194
Greg Avatar answered Dec 21 '22 08:12

Greg