4 ms·
This concerns me: Point newLoc = oldLoc with { x *= 2; y *= 2; z *= 2; }; It feels more like a mutable "Builder" class than a
by tadfisher 3y ago
This concerns me:
Point newLoc = oldLoc with {
x *= 2;
y *= 2;
z *= 2;
};
It feels more like a mutable "Builder" class than a copy constructor. I guess the benefit is that you can do things like the above, instead of the following in Kotlin:
val newLoc = oldLoc.copy(
x = oldLoc.x * 2,
y = oldLoc.y * 2,
z = oldLoc.z * 2
)
But in Kotlin it's more clear that oldLoc is immutable.
- rbehrends 3y agoFor what it's worth, in Kotlin you could also do the following: val newLoc = oldLoc.run { copy(x = x * 2, y = y * 2, z = z * 2) }
- zaphirplane 3y agoThe syntax is definitely strange and not Java like, it doesn’t match any Java syntax I recall. Not a lambda, not a method call, not a keyword or even a static method It should be 1 of the above. They also made the same weird new syntax choice with string template. One of the most important things about a language is coherence and consistency. That’s why a language designer is a role/talent