Why not Kotlin (but Java)?

Правка en8, от oversolver, 2022-06-09 20:39:59

Looking at language statistics in last rounds I have wondered why so many Java and so extremely low Kotlin coders?

Codeforces Round #797 (Div. 3)
CodeCraft-22 and Codeforces Round #795 (Div. 2)
Educational Codeforces Round 129 (Rated for Div. 2)

Kotlin, in a rough sense, is modern replace for Java, so...

If you are Java-coder then I am curious why you not change Java to Kotlin?

  • I'm too accustomed to Java/other, my brain think in Java, my hands do in Java
  • My (future) job is coding in Java
  • I doesn't like/hate Kotlin for some reasons
  • I don't want to note basic advantages of Kotlin which described everywhere. But it is language with modern syntax, and I think it is cool for cp almost as Python. I have more than one year experience of coding in Kotlin (but not cp!!), and I can describe my feelings as "I will never write even single line again in Java".

    Maybe you remembered Kotlin as not so cool language when it was 1.4 but now (1.7 in moment of writing this blog) both syntax and std lib have improvements. For example, instead of readLine()!! now it is readln(). Or modulo function

    val MOD = (1e9 + 7).toInt()
    println((-1).mod(MOD)) //1000000006
    println(((MOD-1L)*(MOD-2L)).mod(MOD)) //2
    

    Usage of lambdas in Kotlin is awesome. Just look at this custom comparator:

    data class Segment(val l: Int, val r: Int, val id: Int)
    ...
    segments.sortWith(compareBy<Segment> { it.l }
        .thenByDescending { it.r }
        .thenBy { a[it.id] }
    )
    

    Last what I really like is extensions, great for templates/libraries

    fun IntRange.firstFalse(pred: (Int) -> Boolean): Int {
        var l = first
        var r = last + 1
        while (l < r) {
            val m = (l + r) / 2
            if (pred(m)) l = m + 1 else r = m
        }
        return r
    }
    
    //usage:
    val i = (0 .. 2e9.toInt()).firstFalse {
        1L * it * it <= s
    }
    
    Теги kotlin, java

    История

     
     
     
     
    Правки
     
     
      Rev. Язык Кто Когда Δ Комментарий
    en8 Английский oversolver 2022-06-09 20:39:59 0 Tiny change: '\n}\n```\n' -> '\n}\n```\n\n' (published)
    en7 Английский oversolver 2022-06-09 20:39:26 297 Tiny change: 'r r = last\n whil' -> 'r r = last + 1\n whil'
    en6 Английский oversolver 2022-06-09 20:35:51 669 Tiny change: 'MOD))\n```' -> 'MOD))\n```\n'
    en5 Английский oversolver 2022-06-09 11:46:55 251
    en4 Английский oversolver 2022-06-09 11:37:18 147
    en3 Английский oversolver 2022-06-09 09:06:12 528 Tiny change: '\n\n\nI do not want to ' -> '\n\n\nI don't want to '
    en2 Английский oversolver 2022-06-09 08:55:15 310 Tiny change: '\n\n<li>\n(likes:1,option1)\n</li>' -> '\n\n<li>\na\n</li>\n\n<li>\na\n</li>'
    en1 Английский oversolver 2022-06-09 08:47:35 1347 Initial revision (saved to drafts)