3 ms·
Look, suppose you go ahead and follow this advice instead of using a constructor function. What have you got? First, you'll have to update each-and-every sing
by politician 11y ago
Look, suppose you go ahead and follow this advice instead of using a constructor function. What have you got?
First, you'll have to update each-and-every single function that operates on the struct to deal with zero-values with ambiguous semantics (i.e. is it zero because that's meaningful in my domain, or is it zero because Johnny forgot to update the allocation). If you'd used a constructor function, then you could've resolved the meaning of those default values and been done with it.
Second, the next time you add a new field, you'll have to deal with a potentially complex interplay between default values and what the code actually needs to do.
Third, the absence of compiler errors fails to notify third-party users of your library how the semantics of your struct has changed, with all of the long-nights-of-debugging that that will entail.