3 ms·
This looks like it could be a good change. Personally I think new point with { x = 1, y = 2, z = 3 } is much cleaner looking than say point.withX(1).withY(2).wi
by ecshafer 3y ago
This looks like it could be a good change. Personally I think new point with { x = 1, y = 2, z = 3 } is much cleaner looking than say point.withX(1).withY(2).withZ(3). names params is generally something I like it languages though, so I might be biased here.
- tadfisher 3y agoThis 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