10 ms·
Kotlin: A statically-typed language that compiles to JVM bytecode and JavaScript
- curtis 13y agoI am happy to see that there's some example code on the home page.
- desireco42 13y agoI am honestly a little tired of one more language that is statically typed and compiles in js. It really has to bring something huge for me to consider it, even from name like JetBrains.
- jonsterling 13y agoI am pretty tired of statically typed direct-to-JS languages which are wildly unsound. I use TypeScript at work, and I grant it's hugely safer than JavaScript and has saved us from dozens of defects even in the two weeks since I introduced it, but its type system is pretty broken. A DSL written in a dependently-typed language (such as Idris) would suffice for both the kind of safety and the level of expressivity I require. (Unfortunately, the various JS backends for Haskell, Idris, Agda, etc. are not usable for my purpose, since I need the output to be readable and debuggable). Anything less than what I have proposed in the previous paragraph is pretty uninteresting to me. It's unfortunate that people are working so hard on Kotlin, when it cannot contribute anything new or interesting, by its very nature.
- profquail 13y agoHave you looked at Haxe (http://haxe.org/ http://haxe.org/)? It's supposed to have a decent type system, although I can't say how it compares to TypeScript's since I've used neither of them. If you need a stronger type system, and you're already using TypeScript, take a look at FunScript (http://funscript.info/); http://funscript.info/); it uses the meta-programming features of F# to do strongly-typed JS (and TypeScript) code generation and interop with existing code.
- jonsterling 13y agoThanks for the links! FunScript looks really neat.
- mortyseinfeld 13y agoIt's unfortunate that people are working so hard on Kotlin, when it cannot contribute anything new or interesting, by its very nature. Maybe you can think outside of yourself for once and consider that your uses cases or personal preferences aren't what the Kotlin devs consider important.
- jonsterling 13y agoYes, my very point is that it is unfortunate that my use cases and personal preferences are not what Kotlin devs consider important. This is not a matter of “Waaaa, they don’t consider me the center of the Universe as I do!”; it's simply the case that my “personal” preferences correspond with reality and safety more closely than do theirs. A priori, it would be better if they conformed to my expectations; anything less than awareness and deference to the last 40 years in PL research is uninteresting and unhelpful.
- mortyseinfeld 13y agoit's simply the case that my “personal” preferences correspond with reality and safety more closely than do theirs. A priori, it would be better if they conformed to my expectations; anything less than awareness and deference to the last 40 years in PL research is uninteresting and unhelpful. Amazing. Are you a solipsist or just incapable of perceiving outside of your little bubble? Do you even understand what the Kotlin devs are trying to accomplish? Hint, they're not trying to develop the next dependent type theory implementation on the JVM. They're implementing a language so that Java developers can be a bit more productive than they are now.
- jonsterling 13y agoClearly I am a solipsist, my dear fellow. Case closed.
- camus2 13y ago> but its type system is pretty broken. In order to have a type system that is compatible with javascript , there are things you just cant do. I think Microsoft TS team did an acceptable compromise. TS is not perfect , but the fact that one can still use pure JS in typescript is a huge plus.
- jonsterling 13y agoReally, that's quite the problem: the desire for at least one-way compatibility.
- michielvoo 13y ago> but its type system is pretty broken Can you explain this? Thanks!
- jshen 13y agoIt has the few things that I believe will make my life a lot easier. 1) compiles to jvm and javascript 2) handles null better than java/javascript 3) good tooling I don't know of many other languages that hit this mark.
- hhariri 13y agoKotlin targets the JVM and JS. Emphasis on targeting both, not just one. Targeting to JS allows for certain scenarios, such as those I recently wrote about: http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-the-browser/ http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-t...
- laureny 13y agoProbably the most promising language on the JVM in my opinion, one that stands a reasonable chance to see wider adoption than the faltering and overly complex Scala. Kotlin feels like an incremental improvement over Java that I can wrap my head around and it comes with stellar IDE support right out of the box. I hope they release a 1.0 soon so we can see if it gains traction, but it will be challenging, because Java certainly seems invincible right now, and probably for years to come thanks to the imminent Java 8.
- pron 13y agoI absolutely agree. I can see my future projects being written either entirely in Kotlin or in a combination of Kotlin and Clojure. Kotlin is a very practical, well thought-out language, that was designed with the right approach re language features: if in doubt, leave it out. The result is simple, modern and powerful, with – and this one is extremely important – top notch Java integration. It is extremely easy to integrate Java and Kotlin in the same project, and easy enough to go back to Java if Kotlin doesn't catch on. Kotlin is very easy for Java developers to learn, and easy to read and understand if they haven't learned it. It feels very unobtrusive when introduced into a Java project.
- qwerta 13y ago>one that stands a reasonable chance to see wider adoption t Not just compared to Scala but any other language. I actually think Kotlin is more similar to Groovy than Scala. Sure the facade is veri similar, but the philosophy and internals are very different. Also founders of Groovy and Groovy++ (statically typed) are involved in Kotlin development. Most of Scala was created by postdoc and students. Kotlin was created by java company who want to scratch their own itch. I especially like that Kotlin is 100% compatible with Java. I think best trick in language design is how Kotlin interacts and adds new features into legacy Java codebase. For example it introduces 'immutable collections' into existing Java Collection hierarchy without modifications.
- seanmcdirmid 13y ago> Most of Scala was created by postdoc and students. Kotlin was created by java company who want to scratch their own itch. Even though the students and postdocs definitely contributed, it is still probably accurate to say most of Scala was created by Martin Odersky.
- niutech 13y agoIt's old news - see https://news.ycombinator.com/item?id=2784086 https://news.ycombinator.com/item?id=2784086
- losethos 13y agoI wrote a HolyC to x86_64 machine code compiler. It compiles 50,000 lines of code in 0.7 seconds. I do a clean make-all compiling 50,000 lines in 0.7 seconds. Then, I JIT compile another 50,000 during boot in 0.7 seconds. Fucken niggers. Disk drives are mechanical and their operation sometimes takes longer or shorter. A nerve signal going from brain to finger, sometimes takes longer or shorter.
- dgreensp 13y agoDoes anyone know how Kotlin bridges the differences between the JVM and JS? For example, the demo video that prints an ArrayList of Integers raises more questions than it answers, given that JavaScript doesn't have Integers or ArrayLists and has different built-in stringification (which is always idiosyncratic from language to language). Can I write portable code that uses arrays? Some quick poking around indicates that Kotlin is pretty JVM-centric for someone who works in the web world. (I used to write a lot of Java and Scala and even wrote a mini JVM once, but these days JavaScript is my go-to platform.) There's good old byte/short/int/long and there's boxing of primitives. They don't even bother to mention that arrays have immutable size (like Java and unlike JS), presumably because they assume it's obvious. Inexplicably, the English words "and" and "or" are used for bitwise operations while && and || are unchanged. Hate to criticize but it all just seems rather strange.
- hhariri 13y agoThe demo (I'm the author of the video) is showing JVM, not JavaScript target. For JavaScript, check out: http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-the-browser/ http://blog.jetbrains.com/kotlin/2013/10/writing-kotlin-in-t...
- camus2 13y agoFirst thanks for your excellent products. JetBrains rocks and i bought 2 ides from your business. Now my question : Why didnt you chose an existing language like Dart for instance?which would have been closer to java and still compile down to javascript. I think dart on the jvm would be a great idea.
- eonil 13y agoI like to know whether this language support these stuffs. - C++ level of const correctness or a simple way to make immutable data structure. Or immutable view of full data structure. - Explicit symmetric coroutine with safe data sharing machinery. I mean something like Erlang process or Goroutine. - Any meta-programming facility such as macro or template.
- hhariri 13y ago1. Yes 2. No 3. A bit. Not macros or templates but nonetheless you can do some type of meta programming with reflection.
- mwcampbell 13y agoDo you plan to add macros or some other kind of compile-time metaprogramming? I think it's important to have that, since reflection is at odds with obfuscation and also introduces runtime overhead compared to compile-time code generation.
- abreslav 13y agoMany ideas of this sort are flying around, but we postpone the decision to some time after 1.0
- rnikander 13y ago> [...] the faltering and overly complex Scala I use it everyday for work, and it's an excellent language. I think it "falters" because it's more ambitious than anything else. Kotlin doesn't look as ambitious so far. I'd rather stick with Scala and see them keep improving. There are some promising ideas in the pipeline for future simplification without loss of power: http://www.infoq.com/presentations/data-types-issues http://www.infoq.com/presentations/data-types-issues
- lmm 13y agoIf that's the one I think it is it, the proposal would make type-level programming much harder to debug than it currently is (because it becomes impossible to specify the types of type-level functions).
- woutervdb 13y agoAnother day, another new programming language that compiles to [popular language]. I'm sorry, I may be looking at this from the wrong perspective, but in my opinion, they're starting to lose their value. Sure, accessing a hard language (like C, or Python (for me, I find Python difficult at times) by writing your own dialect or higher-level language can be fun and maybe can make your workflow better, for me it doesn't. Actually, I view these higher-level languages as the program that ships with a Raspbery Pi (don't know what it's called, sorry), which uses a drag and drop interface to create loops and create a game. You'll learn the basics of programming, but having a company where everyone speaks their own higher-level language won't really work. You're especially fked if you've got a developer that has to read the generated code, in a lot of cases. Please correct me if I'm wrong, I'm still genuinely interested in the purpose of such languages!
- hhariri 13y agoNot exactly sure what you're saying here.
- woutervdb 13y agoEnglish is not my native language and I'm kinda busy, so it's pretty hard for me to explain myself, sorry. I'm saying that languages like these (if I understand correctly), when compiled, result in a program generated by said language, "written" in another language, like Javascript, Java, Python or something. Personally, I see no value in doing so. It creates a bit of an "overhead" (you compile it twice), and you actually don't really see what happens in the layer below the layer you're working in: the JS/Java/Python layer. Say you've been working in the language FooBar, which creates, say, Javascript. Now most examples of code generators I've seen don't really care about the readability of the code they output. They have a readable, human-created bootstrap.js loading the default handler, and a bunch of semi-obfuscated .js floating around. Usually, this doesn't matter. However, I see a lot of these languages appear on HN lately. The problem I'm starting to see is that, when we've got 10,000 alternatives to FooBar, people all start using different FooBar-like languages, and it becomes a mess. If you, for example, like to write in BarFoo, then we have a problem. We both understand JS, but the generated code is a mess. What do? Then again I could be wrong. :P
- deathanatos 13y agoThis has null-safety. As in, you can't assign null to a variable without explicitly qualifying that variable as "nullable". Glad to see this. But it's yet another language with strings-are-a-list-of-code-units. I've mentioned it before, but I'd like more languages to follow Haskell/Python's suite of "String are a list of code points", at the very least. (Those as others have point out, while dealing with code points is less error prone than code units, you probably want something even higher level.) Integers are still range-limited. For some things this is okay, for some things it'd be nice to not worry about what happens when you get near 4B. Python solved this nicely. (There's a place for range-limited ints, and you can always have a ranged_int<0, 65565> type, or something. But by default, I don't want to think about overflow!) Generics appear to be C#/Java like (i.e., limited, not full meta-programming). Some things that run when targets to the JVM don't in JS. `for(c in "a string")` didn't compile for JS, nor did `1000000000000000 or 0`. (To be sure, this isn't exactly easy.) (Last, the issue tracker infinite-redirects, likely because it doesn't handle a browser rejecting cookies.)
- DigitalJack 13y agoCould you take a crack at explaining code-unit vs code-point? I'd never heard of them, and they sort of looked like the same thing on Wikipedia.
- aardvark179 13y agoA code unit is the minimal bit length for a character in a particular encoding, so in UTF16 that's 16 bits and in UTF8 it's 8 bits. A code point is a character, that may be encoded by a single code unit or may require multiple code units. Mostly Java handles strings as 16bit code units, code point functions were only introduced at 1.5.
- DigitalJack 13y agoSo, a dumb question, If a code unit is the minimal bit length for encoding a character: why would you need more than one to encode a character? Is this just a way of saying "variable bit length character encoding?"
- bjeanes 13y agoIs this JetBrains' answer to Eclipse's Xtend (http://www.eclipse.org/xtend/ http://www.eclipse.org/xtend/)?
- colig 13y agoI started using Kotlin on the weekend and I have been pretty happy with it. The only issues I have with it so far is that I would like to use a package name with more than two identifiers (eg. com.android.scripting, instead of just com.android), and there isn't a succinct way of declaring multidimensional arrays. I resort to doing something like val arr: Array<Array<Tile>> = Array<Array<Tile>>(height, { x -> Array<Tile>(width, { y -> Tile(x, y, Terrain.GRASS) }) }) Now I'm looking at writing my array in Java instead and making good use of Kotlin's interoperability with Java. :)
- udalov 13y agoMost of the time you can omit type arguments: val arr = Array(height) { x -> Array(width) { y -> Tile(x, y, Terrain.GRASS) } }