Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Kotlin in Action: Is there a Kotlin language specification?  RSS feed

 
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I looked on the Kotlin language website for a specification document, but could not find one.  How, for example, do you know what the order of evaluation of arguments is for a function call, and other pedantic issues?

Trying out Kotlin using the online editor, I was happy to see that "unreachable statements" appear not to be compile-time errors, unlike Java (see https://github.com/dtrebbien/JEP-Unreachable-Assertions/blob/aa528f5/jep.md ); the following code compiled with a warning rather than an error:



I am wondering, though, if this will be changed in a future version of Kotlin.

Is there a complete language specification document?
 
Marshal
Posts: 5802
401
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can find it there -> https://github.com/JetBrains/kotlin-spec
 
Daniel Trebbien
Ranch Hand
Posts: 90
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Liutauras Vilda!

For those curious, §16.39. Order of Evaluation states:

Generally, the order of evaluation is left to right, non-lazy (eager). Some expressions have special rules for order of evaluation of their constituent parts (some of them may be not evaluated at all). Order of evaluation of named arguments corresponds to their order at the invocation site, not the declaration site.

TODO



Also from the spec, §8.4. Unreachable Code:

Certain regions of code may be proved unreachable via static analysis, which results in a compile-time warning. Definite assignment is not checked within unreachable code, and assignment in unreachable code has no effect of definite assignment state of variables. Otherwise, unreachable code is not exempt from rules of this specification, and any violations result in errors in the same way as in reachable code. Compiler is free to skip code generation for any code proved to be unreachable, but this shall not have any observable effects (beyond those that can be obtained by inspection of the binaries).

 
author
Ranch Hand
Posts: 149
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no complete specification for Kotlin at this time. The link posted above is a work-in-progress draft of the spec; the work on it is on hold for now, but we plan to resume it later. In addition to that, you can find specifications for new features being added to Kotlin in the KEEP repository.

Changing something like that from a warning to an error would be a breaking change, and the Kotlin compatibility policy does not allow us to make such changes without increasing the major version number of the language (basically until Kotlin 2.0), and we don't plan to do that any time soon.
 
Liutauras Vilda
Marshal
Posts: 5802
401
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dmitry Jemerov wrote:The link posted above is a work-in-progress draft of the spec; the work on it is on hold for now


In which case perhaps would be fair to provide such information there, otherwise it is misleading.
 
Dmitry Jemerov
author
Ranch Hand
Posts: 149
5
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've updated the README and repo description to mark it as work-in-progress.
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!