3 ms·
Why would you need to know if a value is the default or a value the equals the default? I can't think of a reason for that as I've never faced this problem in m
by pietrovismara 6y ago
Why would you need to know if a value is the default or a value the equals the default? I can't think of a reason for that as I've never faced this problem in my career.
- taeric 6y agoIt is niche, but it does come up. Usually with boolean parameters, but also on migrations. Makes it possible to change defaults in a controlled way rather easily, since you can very easily log all of the places you used the default.
- tener 6y agoNah, you should be using another value if you care about that. For example in C# a nullable bool would be a fine choice (three values: true, false, null), or alternatively Option types.
- taeric 6y agoThis feels like classic blaming the user. :) You can also have better behavior between multiple defaults if you know whether someone gave a value or not. Basically, it is another tool compared to overloading. It should be no surprise that there can be preference on how to use between them.
- uryga 6y agoone example is `namedtuple`'s `._replace`: >>> x = Foo(a=1, b=2, c=3) >>> x._replace(a=1000, c=3000) Foo(a=1000, b=2, c=3000) in this case, you really need to know if the user passed a replacement or not.