Kotlin Web Demo is out!

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!

About Andrey Breslav

Andrey is the lead language designer working on Project Kotlin at JetBrains. He also works on making the Java language better, serving as a Java Community Process expert in a group for JSR-335 ("Project Lambda"), and occasionally speak at software conferences such as Devoxx or JavaOne.
This entry was posted in General and tagged . Bookmark the permalink.

32 Responses to Kotlin Web Demo is out!

  1. HamsterofDeath says:

    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

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

    • Eisbrecher says:

      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.

      • 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:

          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!

  2. Rezkell says:

    Very nice! And very interesting language. Congratulations to Andrey and the gang ;-)

  3. Gaetan says:

    Great job!!!

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

  4. Isaka says:

    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:

    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?

  6. Roberto says:

    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?

    • 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:

    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()
    }

  8. Otto Christian says:

    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!” :)

  9. Andrew O'Malley says:

    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? :-)

    • 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:

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

    • “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:

    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?

  12. Andreas says:

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">