Kotlin Web Demo is out!

Andrey Breslav

It’s been a little more than a year since the first commit was pushed to our source control, and we are happy to announce the first public preview of Kotlin.

This preview works as follows:

  • You go to http://kotlin-demo.jetbrains.com and it loads a code editor in your browser:
  • You check out examples, modify them or even solve our sample toy-problems;
  • You run your code on a JVM running on our server, so that you can use familiar JDK classes;
  • Or, alternatively, you compile you code to JavaScript and run it in your browser:

    Note that the JavaScript back-end is a pre-alpha version, so it may refuse to compile some of your programs.

Experimental features

By default, you get error highlighting only when you run your program. But you can try out some of the features we are experimenting with and turn on “as-you-type” error highlighting:

If you choose “Server”, the editor starts talking to a type checker service hosted on our server. If you choose “Client”, a type checker is loaded as a (so far rather big) Applet which runs on your machine.

Both “Server” and “Client” options give you code completion as well:

Please, note that these features are experimental and feel free to report any problems to us.

Coming soon

This demo will be developed further for you to have more fun. Among other things we plan to add the following:

  • Standard Library of extension functions that make using JDK collections and other common APIs more pleasant (things like map()/filter() and so on);
  • Code Challenge: currently we offer a few sample problems in the form of code snippets containing test data. This will be extended to contest-like automated testing system.
  • More Examples: There’s always some more to show off 🙂

Have fun!

Comments below can no longer be edited.

32 Responses to Kotlin Web Demo is out!

  1. HamsterofDeath says:

    January 10, 2012

    finally 🙂

    solved the pairless problem.

    for (i in a) {
    if (lonely.contains(i)) {
    lonely.remove(i)
    } else {
    lonely.add(i)
    }
    }
    val it = lonely.iterator()
    if (it != null) {
    return it.next()
    }
    return -1;

    is it possible to switch off the “this is a java method, it might return null! you need to check it!”-rule? if i had a mixed java/kotlin project, the kotlin code would be scattered with either if ( != null) or “?” otherwise….

    and about the extension functions to make java collections more pleasant to use – this is your enemy:
    def findPairless(t: Seq[Int]) = t.filterNot(e => t.count(_ == e) % 2 == 0).distinct

    • Andrey Breslav says:

      January 11, 2012

      On the nullability of Java types: we are working on it.

    • Eisbrecher says:

      January 12, 2012

      From the scala-user mailing list:

      HamsterofDeath Jan 10 09:25PM +0100

      in case you didn’t know, today is the public preview of kotlin 🙂
       
      http://kotlin-demo.jetbrains.com/
       
      main differences i spotted:
      + zero overhead null safety instead of options.
      + access to variables inside strings: “hello ${somevar}”
      + automatic casts inside “if (x instanceof Foo)”
      + extension functions
      + generics still available at runtime
      + apparently, it compiles as fast as java
       
      but:
      + no things like implicits, abstract types or destructuring.
        
      the first one should be stolen and added to scala. for the second one, i
      heard there is a compiler plugin. the automatic cast can be done via
      enrichment, the fourth also.

      You shouldn’t trust to this man.

      • Andrey Breslav says:

        January 12, 2012

        We are always glad when other projects learn from us (as we learn from them all the time).

        One correction: Kotlin has “destructuring” (we call it “decomposing”), although it is not finished yet.

        • Eisbrecher says:

          January 12, 2012

          Great answer. Humans’ evolution is more important, than one sole programming language or single library.
          This is why you are project leader Andrey. All the best!

          • soc says:

            January 21, 2012

            I still haven’t understood what the problem is.

            It’s not like any of this stuff is secret.

  2. Rezkell says:

    January 10, 2012

    Very nice! And very interesting language. Congratulations to Andrey and the gang 😉

  3. Gaetan says:

    January 10, 2012

    Great job!!!

    Where sould we discuss possible bugs or differences beetween the «specifications» and the demo?

  4. Isaka says:

    January 10, 2012

    Could Kotlin pull a “Visual Basic” on the software community? This example may be the start of something. Well done guys!

  5. Alex Besogonov says:

    January 10, 2012

    I’ve seen the preview a few days ago. VERY impressive. The Web IDE itself is much better than some other ‘web IDEs’.

    However, now that you are teasing us with preview – can you tell when the full stand-alone compiler will be available?

    • Andrey Breslav says:

      January 11, 2012

      We are planning to open a public open source preview version of the compiler sometime before the end of March.

      • Mikael Gueck says:

        January 12, 2012

        Take your time. The worst thing that might happen would be to go the same way some other languages went, and start releasing half-baked features, followed by the same basic feature in a little different form, again and again.

  6. Roberto says:

    January 11, 2012

    I really enjoyed the infix extensions functions:


    fun String.log(){
    System.out?.println(this);
    }

    fun String.format(p0 : String) : String{
    return String.format(this, p0).toString();
    }

    fun main(args : Array) {

    val e = "Too Awesome";

    "Database error: %s".format(e).log();
    "Database Access Required".log();

    }

    A few questions arise though:
    1. How are infinite argument lists defined (ala printf). IDE suggests p : ... : String, but that did not really work.
    2. If annotation support is in yet – how do you define them?

    • Andrey Breslav says:

      January 11, 2012

      Varargs are defined as:

      fun foo(vararg s : String) {
      // s in an array here
      }

      Annotations are not supported yet, but the definitions will look like

      annotation class persistent() {}

      Usage:

      persistent class Foo(…) {…}

  7. Serger says:

    January 11, 2012

    This is a bug?

    var s = null : String?
    s = “a”
    var s1 = “” // String – ?
    if (s != null) {
    s1 = s.toString() // return String?
    s1 = s // Error “Type mismatch: inferred type is String? but String was expected”
    val s2 = s
    val s3 = s.toString()
    }

    • Andrey Breslav says:

      January 11, 2012

      This is a bug in diagnostics. The compiler should have told you that ‘s’ is a var and thus smart casts do not work for it. Only immutable values can be safely cast.

      I filed an issue about it: http://youtrack.jetbrains.net/issue/KT-969

      • Serger says:

        January 11, 2012

        Thanks. It was a terrible code, but why there is no error here:
        s1 = s.toString() // return String?
        smart cast?

        • Andrey Breslav says:

          January 11, 2012

          No, we simply call Kotlin’s toString() that never returns null. If you say null.toString() you just get a string “null”.

          • Serger says:

            January 11, 2012

            Ups! of course – s?.toString()
            But I have in mind this assignment:
            s1(String type) = s?.toString()(String? type)

          • Andrey Breslav says:

            January 11, 2012

            This wont compile:
            var s1 : String = s?.toString()

            This will:
            var s1 : String = s.toString()

          • Serger says:

            January 11, 2012

            I understood.

  8. Otto Christian says:

    January 11, 2012

    wow, the web demo of Kotlin is impressive. Awesome!

    Is Jetbrains planning to release full-blown web IDE? Would it be a separate product than IntelliJ? I wonder if perhaps eventually it will supersede and replace IntelliJ altogether?

    Also, I notice that if I start using Kotlin I will have lots of “fun” all over my code. So I’d like to suggest that Jetbrains change the motto for the Kotlin IDE from “Develop with pleasure!” to “Develop with lots of fun!” 🙂

    • Andrey Breslav says:

      January 12, 2012

      Currently this is only a demo. If we ever build a full-featured web-based IDE, it is unlikely to be developed up from this.

  9. Andrew O'Malley says:

    January 11, 2012

    Are you monitoring the web demo for compiler crashes? (I managed to crash it yesterday and can’t see any related issues in the tracker).

    Would you prefer any such issues to be reported via the issue tracker directly? Or should I just give you a chance to get to it? 🙂

    • Andrey Breslav says:

      January 12, 2012

      We monitor crashes in the demo, but they need manual preprocessing to be added to the tracker, so this will take time. If you don’t mind filing an issue yourself, it won’t hurt 🙂

  10. @ groovy says:

    January 12, 2012

    Anyone can summarily list what I’d possibly lose if I gave up on groovy for Kotlin – except embracing this silly name, Kotlin?

    • Andrey Breslav says:

      January 12, 2012

      “Kotlin” is a code name.

      Comparing to Groovy, you get static typing and better performance (no reflective calls), to begin with. If you don’t care about these things, you are probably happy with Groovy and don’t need Kotlin.

  11. Andrey says:

    January 15, 2012

    I had to use while loop in the Palindrome problem:

    var i = 0
    while(i < s.length) {
    if (s.get(i) != s.get(s.length - 1 - i))
    return false
    i++
    }
    return true

    The solution with for the classical C-style for loop is shorter by two lines of code:

    for(int i = 0; i < s.length; i++) {
    if (s.get(i) != s.get(s.length - 1 - i))
    return false
    }
    return true

    Are you going to implement this kind of loop from Kotlin?

    • Andrey Breslav says:

      January 15, 2012

      You can use ranges:

      for (i in 0..s.length-1) {
      ...
      }

  12. Andreas says:

    January 16, 2012

    Documentation in :
    “Strings are represented by the type String. Strings are immutable. … A string can be iterated over with a for loop:
    for (c in str) { println(c) }”

    In Web Demo:
    ——–
    fun isPalindrome(s : String) : Boolean {
    for (c in s)
    {
    }
    return true
    }

    Error message: For-loop range must have an iterator() method
    —–
    Bug in Web demo or error in documentaion?

    • Andrey Breslav says:

      January 16, 2012

      This is due to the temporary absence of the Standard Library in the Web Demo. We’ll fix it soon.