Just a quick one, Is there anyway to shorthand this?
It's basically determining the direction left or right, 1 for left, 0 for right
In C#:
if (column == 0) { direction = 0; }
else if (column == _gridSize - 1) { direction = 1; }
else { direction = rand.Next(2); }
The statement following this will be:
if (direction == 1)
{
// do something
}
else
{
// do something else
}
If there isn't, it doesn't really matter! just curious:)
direction =
is repeated three times. By bringing that out, it makes it objectively clear (not just a matter of opinion, but a fact based on the reduction of needless repetition).direction
, because nested ternaries are much harder to parse when reading. I would also say that the repetition ofdirection
makes it more obvious that it is the same variable getting different values in each branch.direction =
, that makes it immediately obvious from the start that we are assigning something todirection
, and hence the rest of the statement must be an expression producing the value to be assigned. The only problem would be if the person reading the code is not aware of how? :
works.