hmm, but do they actually? i assume you mean that deconstruction is meant to look like construction of class instance. in some of the simple forms they do look similar, i.e. when we copy & paste the constructor invocation with parameter names, but without default parameters (unless the parameters are literals, then they can be copied verbatim too). when we start to add other things, like _
, @
or non-literal defaults, then they are different already. i don’t think that increasing the similarity to constructors, beyond simple forms, is more important than the confusion. also creating instance of class is usually done without spelling out parameter names. in summary, i don’t think there’s much of similarity in typical usage anyway, so it shouldn’t be a dominating argument in discussion.
also, when we pass some variable x
to class parameter y
, the relationship between the names shouldn’t matter. if i do:
val input = ???
MyCaseClass(param1 = input)
then having the same name mapping in pattern matching, i.e.:
case MyCaseClass(param1 = input) => ???
is not important. in example above, the name input
could have some significance and make sense in context of object’s construction, but during deconstruction the context is different, so in general there’s no point in replicating the name mapping.
also, to take it from another perspective:
is this written in some official scala language design documents (i.e. how far it should go)? is this elaborated and justified / rationalized somewhere?
i get that regularity of language is very important in scala, but here x = a
can be thought of as an another case of simple assignment too (from cursory look at the source code), therefore changing the regularity argumentation (i.e. similarity to some constructor invocations vs similarity to typical assignments).