My question is general. When should I consider splitting a statement to multiple lines?
I'm writing code on my own, and never worked in a team. I always prefer to make my code as compact as it can get.
For instance, instead of writing:
depth = depth - randomNumbers.nextInt(depth) -1;
Expression expA = createRandomExp(depth);
Expression expB = createRandomExp(depth);
SubtractionExpression subExp = new SubtractionExpression(expA,expB);
return subExp;
I will just write:
return new SubtractionExpression(createRandomExp(depth - randomNumbers.nextInt(depth) - 1), createRandomExp(depth - randomNumbers.nextInt(depth) - 1));
The pros as I see it are:
- Less lines of code.
- No need for declaration of variables.
Cons:
- Can be less readable
- Some stuff are written multiple times, like:
randomNumbers.nextInt(depth) -1
What are the standards in the industry? And what should I consider when writing statements? Some guidelines might help.
I came over this, but it doesn't really answer my question.