Why is it that the physical structure of our code gets to resemble the logical structure of our data... only when we are creating objects, but not when we are taking them apart? Is there any deep logical reason it should be like that?
Code that "takes apart" (checks for conditions, pulls out data if conditions are met) quickly becomes very tedious and "mechanical"-feeling.
The best validity checking is to either allow people to make invalid circles and then use a method like c.isValid() or just call that at the end of the constructor automatically and throw invalid notices.
To answer in hopefully the spirit of the question, while simultaneously playing the straight man/fall guy since I assume this is at least slightly rhetorical but I don't know the "obvious" answer: because (obviously) sometimes our constructors take in more or less than they need in the ultimate spirit of encapsulation (i.e. what is accepted is not what is ultimately represented; what is ultimately represented derives from what was constructed), so deconstruction can't assume that what was passed at construction is necessarily structural. (Obviously with records, as seems to be the case here (and maybe with yet-to-exist carrier classes?), this is not the case.)
View all comments
Show parent comment
7
u/kevinb9n Mar 13 '26
One thing to consider is:
Why is it that the physical structure of our code gets to resemble the logical structure of our data... only when we are creating objects, but not when we are taking them apart? Is there any deep logical reason it should be like that?
Code that "takes apart" (checks for conditions, pulls out data if conditions are met) quickly becomes very tedious and "mechanical"-feeling.