4 ms·
I don't think any one pattern rules out any other, but this is a good one for people to keep in mind as I think sometimes it makes more sense. Heck, there are
by ravenstine 8y ago
I don't think any one pattern rules out any other, but this is a good one for people to keep in mind as I think sometimes it makes more sense. Heck, there are even some cases where an object lookup makes more sense than an if-then-else statement.
I'm also a fan of other patterns like early returns, but few people ever seem to do it.
- smhenderson 8y agoI like early returns as well, especially in short functions where there is not a lot of code between returns. In other words if I can see all returns in a function on one screen of text then I'm OK with it and I think it improves readability. On the other hand if I have to scroll up and down a lot to see all return paths then that's a problem. But I generally find the problem is that the function is too long/does too much and should be broken down into smaller pieces.