3 ms·
The one thing I would like is for all functions to be pure by default and we could have something like "impure def" for functions with side-effects and function
by tormeh 12y ago
The one thing I would like is for all functions to be pure by default and we could have something like "impure def" for functions with side-effects and functions that take mutable objects as arguments. It's basically my only complaint about the core language. Well, I would also like iota and defer from Go, but that's minor.
- dpratt 12y agoEnforcing pureness on the function might be difficult w.r.t. things like IO, due to Java interop, and frankly that's one of the strengths of the platform. Inferring loose immutability constraints on a function would be interesting. You could implement it in the compiler, perhaps something like an annotation on a method that declares all inputs must consist of only final/immutable values, enforced all the way down the chain. This is more of a JVM gripe, but as long as we're talking about Go, I'd love to see actual VM-level coroutine support. It'd make async code in Scala a lot easier to both author and debug.
- tormeh 12y agoWell, you could just assume that all non-Scala code is impure. Actually, thinking about it, why not just make it illegal to modify arguments, full stop? It's perhaps the worst software practice I can think of. I think Oracle is going to wait a long time until they add that to Java, and it's not going into the JVM before it's going into Java, unfortunately. Well, there is a limited number of instructions in the JVM, so using them on things that are unproven might be a very bad idea.
- virtualwhys 12y agoInteresting, I wonder how many Scala users intentionally pass around mutable objects and/or attempt to mutate non-local state. I guess for Java devs new to Scala that might seem a viable approach at first...so yes, maybe forcing the user to be explicit in the same way that the `var` keyword is required to stray into mutable territory would be a good thing -- certainly wouldn't bother those that use immutable constructs 99% of the time.