9 ms·
I tried Kotlin during the Surprise Language round of Codeforces, a programming competition. I found it to be more verbose than a typical modern scripting langu
by Scene_Cast2 10y ago
I tried Kotlin during the Surprise Language round of Codeforces, a programming competition.
I found it to be more verbose than a typical modern scripting language. Maybe it's the result of choosing the least of the evils for what it's trying to accomplish.
The other drawback: the documentation. Kotlin's reference documentation (looking up how to properly use a call) does not have any examples. I'm not even talking about full compilable examples - although that would be nice, it doesn't even have one-liner examples. FWIW, I was trying to look up how to use a comparator to sort a MutableArray<Int,Int>.
- rattray 10y agoPersonally I don't much mind the added verbosity, coming from Ruby/Python/JS, so long as I don't have to write so many damn tests. Speaking from minimal experience, Kotlin still seems like a big net win here. Same is true of other languages with lightweight, static type systems like TypeScript/Flow, Swift, and Go. I agree about the documentation – I think it's one of the biggest reasons the language has seen such little adoption given its benefits. I couldn't even find how to integrate Kotlin files into a Java project without using IntelliJ. Kotlin is developed by Jetbrains, so of course they're used to IDE-driven-development, and have a financial stake in people using their products for development. But coming from scripting languages, this sort of documentation gap was a real turn-off for me.
- Bromskloss 10y agoWhat is it that makes you not having to write so many tests?
- smt88 10y agoA decent type system
- iends 10y agoStatic typing.
- Bromskloss 10y agoIs the reasoning that you then don't have to test what happens if you pass a parameter of the wrong type to a function?
- bbcbasic 10y agoThe compiler guarantees it won't happen. Such a test would be a test of the compiler and in my opinion unnecessary. And in Haskell at least... impossible. You can't write the the test because IT won't compile!
- Bromskloss 10y agoI understand that. My question is if that is the kind of tests that people have in mind when they say that static typing requires fewer tests.
- StavrosK 10y agoWithout looking, I'm guessing static typing.
- eropple 10y ago> I couldn't even find how to integrate Kotlin files into a Java project without using IntelliJ. I would suggest (and I'm not trying to bag on you with this) that this concern is more your unfamiliarity with the JVM than a failure of Kotlin, which is generally targeting Java and Scala developers. Kotlin operates pretty idiomatically in the Java universe and, as an experienced JVM developer who's comfortable with all of Maven, Gradle, and SBT, I dropped Kotlin into a Maven project, side-by-side with Java, with a cursory glance at the documentation--"oh, it's another pre-compile-step thing". (Which I then consume via IntelliJ, because IntelliJ imports Maven projects nicely, but Maven allows others to use their IDE of choice.) The pre-compile-step thing sucks, I'll be the first to say that, and it's a problem with multi-language, multi-compiler projects that none of the major build systems on the JVM really handle admirably. I prefer to use multi-module Maven projects and separate out Java and Kotlin--or Scala, for that matter--code into separate ones. But that's a different beast entirely from the initial bootstrap when learning.
- rattray 10y ago> your unfamiliarity with the JVM Correct! > a problem with multi-language, multi-compiler projects that none of the major build systems on the JVM really handle admirably A bummer to hear – though I'm glad it's not just me. I tried using Kotlin with the Play Framework and did not have a great time. The hot-reloading features of Play didn't work with Kotlin at all, even with my attempts to `touch` a Java file whenever my Kotlin file changed (presumably they're recompiling more intelligently than I was). Perhaps having SomeController.java and SomeController.kt in parallel, where the former imports the latter, and receives a `touch` or similar whenever the Kotlin file changes, might work? Or would you recon such a project to be a fool's errand?
- meddlepal 10y agoI agree the documentation needs work and I am using Kotlin in prod. JetBrains please take note!
- voddan 10y agoCould you please elaborate on what needs improving in the docs? Btw, the whole kotlinlang.org is OSS, and you can correct things you don't
- winstonewert 10y agoWhat sort of tests don't you end up writing? I ask because I work in both dynamic and static languages, and find myself writing very similiar tests in each case.
- sanderjd 10y agoTests that verify the behavior of functions when they are passed data of a type that does not support the behavior that the function expects to be supported. I find this to be a very common case.
- dmichulke 10y agoI address this problem by checking the type at run-time via an assertion. Depending on where you are in the security vs efficiency spectrum, you may opt to ignore those assertions in production. Writing specific tests for that looks very inefficient to me but maybe I am missing something.
- bbcbasic 10y agoI don't see how this reduces the need for a test that the wrong type is handled correctly.
- dmichulke 10y agoThe underlying idea is that it shouldn't handle the wrong type at all, it should fail. If some function A calls function B with a wrong type, the problem is with function A. So basically, there should be only type tests after IO functions (probably after parsing), the rest can be assertions.
- mac01021 10y agoAnd you don't need tests to make sure the assertions are there?
- cageface 10y agoAbsolutely. Dynamic languages only seem terse because you don't see all the associated test code inline. I've been programming in a mix of dynamic and statically typed languages for more than 15 years now and I'll take a modern statically typed language over a dynamic language any time if I have my choice. It's a lot harder to design a static type system that's both expressive enough to be pleasant to use and strict enough to be useful. But we're getting there in modern languages like Rust, Kotlin, Swift etc.
- voddan 10y ago"integrate Kotlin files into a Java project without using IntelliJ" - compilation of a mixed project is not a trivial tasks, many things must be set up. A detailed description of this takes a chapter in a book. That's the reason one should use build tools, be it Ant, Maven, or Gradle. The process of setting them up without an IDE is narrowly described in the docs https://kotlinlang.org/docs/tutorials/build-tools.html https://kotlinlang.org/docs/tutorials/build-tools.html
- fierycatnet 10y agoFrom what I understand Kotlin is the language that was designed to be used in house by JetBrains to simplify their Java code. It wasn't born to be the revolutionary, just practical for Java developers.
- voddan 10y agoThe Kotlin reference is not supposed to be used for finding methods. The way to go is to use auto completion in an IDE. If you type `myArray.sort<ctrl+space>`, you get all one needs, including `sort`, `sorted`, `sortBy` (which you needed). Alternatively you could search the reference page for Array or MutableList or MutableMap, not sure what you wanted: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/ https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/ https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/ https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collecti... https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-map/ https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collecti...
- Scene_Cast2 10y agoI had something like this: var heights: Array< Pair<Int, Int> > = ... //populating the array heights.sortBy { it.second }; It was not obvious at all that I had to use curly braces. The documentation says: inline fun <T, R : Comparable<R>> MutableList<T>.sortBy( crossinline selector: (T) -> R?) (source) This is after I figured out that I'm not supposed to use sortWith (I never figured out how to use this one)
- voddan 10y agoThe curly braces are the syntax for lambdas, one of the basic types `(T) -> R?`. There are plenty of examples for using that, but in the respective chapters: https://kotlinlang.org/docs/reference/lambdas.html#higher-order-functions https://kotlinlang.org/docs/reference/lambdas.html#higher-or... or in this bunch of examples: https://kotlinlang.org/docs/reference/idioms.html#filtering-a-list https://kotlinlang.org/docs/reference/idioms.html#filtering-... The docs are arranged in a way that one reads them in the order they are written (at least the first half). I supposed that would take more than half an hour given at the competition. I don't think Kotlin is the best choice for programming challenges like codeforces - they really don't let him shine (although I use it whenever I can). But if this is a valid case, we can collaborate and write a short tutorial for C/C++ to Kotlin programmers.
- Scene_Cast2 10y ago
- n72 10y agoFor those who want docs in the examples, perhaps "liking" my post regarding this on the kotlin discussion forum would help: https://discuss.kotlinlang.org/t/examples-in-the-api-docs/1646 https://discuss.kotlinlang.org/t/examples-in-the-api-docs/16...