15 ms·
> Java has been used successfully in large codebases, probably more so than Scala, and Kotlin, like Go, is a language following Java philosophy. Java didn't ha
by lmm 9y ago
> Java has been used successfully in large codebases, probably more so than Scala, and Kotlin, like Go, is a language following Java philosophy.
Java didn't have anything like as many ad-hoc language-level features as Kotlin has - checked exceptions are the only thing that's really comparable, and their reputation is decidedly mixed (note even Kotlin hasn't included them).
> Kotlin has delimited continuations, which express anything monads can (with a minor, unimportant caveat, which has to do with the particular features of Kotlin coroutines)
They can, but only in the same sense that an untyped language can express anything that a typed language can. They can express any effect but they can't express restricted subsets of effects. You could presumably write a continuation-based equivalent of traverse (though I'd be interested to see what it looks like in practice), but you can't give it the level of type safety it should have, and you can't write sequence when your effects aren't representable.
> Kotlin does this blending at least as well if not better than Java.
Not convinced; nulls aren't integrated as tightly into the language in Java (e.g. no elvis operator) and you don't have to deal with platform types. You can write Option-oriented code without it being a second-class citizen, though admittedly the second-class citizen experience in Kotlin may not be so much worse than the first-class citizen experience in Java.
> I don't think it is a language's job to support all idioms out there, even if they can be useful in some circumstances.
Yes and no. A language doesn't have to support everything out there, but putting together any of the features it does support should work the right way; it's not at all clear that this is the case for kotlin . And certainly when you end up copy-pasting code because you're using the same logic but the language doesn't let you express how it's the same, that's a problem with your language.
- haspok 9y ago> And certainly when you end up copy-pasting code because you're using the same logic but the language doesn't let you express how it's the same, that's a problem with your language. That is not the case. Sometimes language designers and maintainers _deliberately_ avoid language constructs that allow for more generic code. More generic is not always better, definitely not when you have to read and understand the code, and find a bug in it, for example. The more layers of abstractions you have, the harder it is to construct a model of it in your mind. (An example of this approach is Erlang, where parameterized modules were introduced as an unsupported, "beta" feature at some point, then a few major versions later they were removed. Why? Take this opinion, for example: "I would gladly reconsider my somewhat harshly critical position on parameterized modules if shown a clear example of how their use improves the readability or expressiveness of code. Until then I would urge that they didn't become an official part of the Erlang language." http://erlang.org/pipermail/erlang-questions/2010-February/049637.html http://erlang.org/pipermail/erlang-questions/2010-February/0...)
- pron 9y ago> They can express any effect but they can't express restricted subsets of effects. This is not true. E.g., see my blog post, http://blog.paralleluniverse.co/2015/08/07/scoped-continuations/ http://blog.paralleluniverse.co/2015/08/07/scoped-continuati..., with references to work by Oleg Kiselyov on typed continuations. Having said that, restricting effects is one of those solutions in search of a problem, at least at the moment. It is very questionable whether this has any substantial benefit, and the Java philosophy calls for adopting only features that have proven their (significant!) worth. On top of that, Scala can't restrict effects, either. > You can write Option-oriented code without it being a second-class citizen Which, BTW, Java discourages. Option is mainly recommended for use in functional composition in streams. For general null-safety, Java has pluggable nullability types (and many other useful pluggable types), similar to Kotlin's built-in nullability types. See https://checkerframework.org/ https://checkerframework.org/. Unfortunately, it's not yet seeing much adoption, largely due to the relatively low-key marketing of Checker and the fact that it's been not too user-friendly until quite recently. However, this is the recommended solution, e.g. in the Java tutorial: https://docs.oracle.com/javase/tutorial/java/annotations/type_annotations.html https://docs.oracle.com/javase/tutorial/java/annotations/typ.... > putting together any of the features it does support should work the right way; it's not at all clear that this is the case for kotlin Right, and certainly Kotlin has not yet proven itself (and neither has Scala), but in my opinion, this is quite clearly not the case for Scala. E.g., monads and the imperative control structures in Scala simply do not compose. You must commit to one or the other. > And certainly when you end up copy-pasting code because you're using the same logic but the language doesn't let you express how it's the same, that's a problem with your language. Not when that's required for non-idiomatic code. And, BTW, I believe that the pure functional paradigm in general suffers very strongly from this in a way that's very essential to the core of the paradigm (because typed monads introduce a dependence of code structure on a nominal type, i.e., the same computation can be expressed using different monads -- or no monads at all -- in a way that is non-composable or requires awful monad transformers).
- lmm 9y ago> see my blog post, http://blog.paralleluniverse.co/2015/08/07/scoped-continuati... http://blog.paralleluniverse.co/2015/08/07/scoped-continuati..., with references to work by Oleg Kiselyov on typed continuations. So a theoretical type system extension that Kotlin doesn't actually have could solve this, and looks ok in simple examples. That's not terribly reassuring and not much help to anyone writing Kotlin today; anyone wanting to do the equivalent of something basic like traverse or, I don't know, cataM will still have to either copy/paste their code or give up type safety. > On top of that, Scala can't restrict effects, either. In theory no. In practice I use traverse all the time without worrying about whether the function I called was secretly throwing an exception or modifying a global variable, and it hasn't caused a bug yet; the community and culture can mostly work around the lack of hard restrictions at the language level. > Which, BTW, Java discourages. Option is mainly recommended for use in functional composition in streams. I know that's the official line, but it still works in a first-class way in practice (which to my mind is the sign of good language design; you can't expect language designers to anticipate all your needs, so it's important that things continue to work even if used in unexpected ways). > I believe that the pure functional paradigm in general suffers very strongly from this in a way that's very essential to the core of the paradigm (because typed monads introduce a dependence of code structure on a nominal type, i.e., the same computation can be expressed using different monads -- or no monads at all -- in a way that is non-composable or requires aweful monad transformers). There are now ways to avoid having to copy-paste in that situation e.g. MTL-style code ("final tagless") or free coproduct style.