3 ms·
This is just nuts. If you disregard the curly braces each of these guards are just two lines of code. When you place them into a function definition they each b
by jernfrost 11y ago
This is just nuts. If you disregard the curly braces each of these guards are just two lines of code. When you place them into a function definition they each become 3 lines of code. Just so you can replace them with single lines in the original code.
That isn't software engineering. That is religious fanaticism.
E.g.
guard item.count > 0 else {
throw VendingMachineError.OutOfStock
}
Is a very low complexity statement. One comparison is made and an enum value is thrown. You are gaining no clarity by placing this inside a separate function.
- therockhead 11y agoAgree completely, it comes across that the author of the post has read some useful guidelines and created a strict rule which must not be broken.
- DasIch 11y agoIndeed. You should keep the complexity to a reasonable level, lines of code tends to correspond to it so it makes sense to keep the number of lines of code per function low. The author doesn't understand the relationship, he blindly follows the advice to keep the number of lines low without considering the complexity and that leads to unnecessarily complex code.
- golergka 11y agoThis is an oversimplified example. When I imagine how both approaches would look like in actual production code with much more complex requirements, it makes much more sense.