3 ms·
And why not just return the result instead of assigning it to something you eventually return?
by rezistik 7y ago
And why not just return the result instead of assigning it to something you eventually return?
- winrid 7y agoThe argument against this is usually one return statement is preferred.
- maynman 7y agoYep, that's why I chose to implement it that way. I generally prefer single return statements. Plus my day job enforces it as part of the coding convention, so force of habit too haha.
- gatherhunterer 7y agoThe initial assignment is used as a base case. Returns in a conditional statement are often used as an "escape" when you want to get out of a function (e.g. null checks). This is purely a stylistic choice whereas using constant time lookup over conditional evaluation could be argued to have some performance impact (although in this case it would not be meaningful). That said, I don't see anything about this choice that needs to be defended.