3 ms·
Well exceptions are generally a sign that code smells. Instead of throwing an exception, just return the default value.
by sdwvit 6y ago
Well exceptions are generally a sign that code smells. Instead of throwing an exception, just return the default value.
- Smaug123 6y agoHonestly that sounds substantially worse in pretty much every way in nearly every situation. If an assumption of your program has broken, you almost always want to do something about it rather than simply silently producing garbage. Even in a less expressive language like C you'll still often use e.g. a negative return code to indicate failure.
- josalhor 6y agoThis is worse in every possible way. If the default value was part of the domain of the function it would be impossible to distinguish an error from a legit answer without breaking encapsulation. If it wasn't, then you're handling errors like in C.. ugh
- leptons 6y ago>code smells This is one of the worst "ideas" ever in programming. It allows any programmer to shit on any other programmer's work in practically any arbitrary way they feel like. Your idea of returning default is considered by others here to be a "code smell" - if you want to call it that. Looks like using that term just doesn't give your idea any benefit the way you thought it would.
- otabdeveloper4 6y ago> 1 / 0 just returns 0, #yolo No thanks.
- sdwvit 6y agoReturns infinity like it should
- choward 6y agoHow do I know if it errored or not? The default value is ambiguous. It either means that it's the correct result or that the function errored. Sure, the program might not crash right then and it will compile, but it's guaranteed to lead to confusion for both users and programmers who have to debug it.