Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing a 
Geospatial WebService with Spring...

Developing a 
Geospatial WebService with Spring Boot and Kotlin

Sébastien Deleuze

May 19, 2016
Tweet

More Decks by Sébastien Deleuze

Other Decks in Programming

Transcript

  1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Developing a 
 Geospatial WebService with Kotlin and Spring Boot by Sébastien Deleuze @sdeleuze
  2. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Who am I? • Sébastien Deleuze • Live in Lyon, France • Work at • Spring Framework and Reactor commiter • Actual focus on Spring Framework 5 Reactive support • Co-worker at • Staff member of conference 2
  3. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Introducing Kotlin
  4. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why Kotlin? 4 ?
  5. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Limits of Java • Verbose • Limited type inference • No properties • Checked exception • NullPointerException • Extensibility • End of lines with ; • Java Puzzlers • We deserve a better solution than Lombok … 5
  6. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Keep what makes Java great • Fast • Optimized bytecode • Static typing • Simple to learn • Amazing ecosystem 6
  7. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin • Elegant and pragmatic language • Concise code • Fast to write • Easy to read • Awesome type inference with static typing • Simple and easy to learn • Very good Java interoperability • Null safety, extensions, DSL, etc. • No more ; at the end of lines :-) 7
  8. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Status • February 2016: Kotlin 1.0.0 • Latest stable version is 1.0.3 • First Kotlin 1.1 preview available 8
  9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Use cases 9 Others 11 % Android 59 % Desktop 6 % Server 23 % Source: poll on Kotlin Slack
  10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Methods count on Android app* 10 0 6000 12000 18000 24000 Java Groovy Scala Kotlin 7 193 12 180 23 775 7 065 * https://github.com/SidneyXu/AndroidDemoIn4Languages
  11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How does it compare with ... 11 Same conciseness and expressive code, but Kotlin static typing and null-safety make a big difference. "Some people say Kotlin has 80% the power of Scala, with 20% of the features" *
 "Kotlin is a software engineering language in contrast to Scala which is a computing science language." * Swift Swift and Kotlin are VERY similar. Swift is LLVM based and has C interop while Kotlin is JVM based and has Java interop. * Quotes from Kotlin: The Ying and Yang of Programming Languages
  12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Classes 12 public class User { private String userName; private String firstName; private String lastName; private Point location; public User(String userName, String firstName, String lastName) { this(userName,firstName, lastName, null); } public User(String userName, String firstName, String lastName, Point location) { Assert.notNull(userName); Assert.notNull(firstName); Assert.notNull(lastName); this.userName = userName; this.firstName = firstName; this.lastName = lastName; this.location = location; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public Point getLocation() { return location; } public void setLocation(Point location) { this.location = location; } } class User(
 var userName: String,
 var firstName: String,
 var lastName: String,
 var location: Point? = null
 )
  13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Data classes 13 public class User { private String userName; private String firstName; private String lastName; private Point location; public User(String userName, String firstName, String lastName) { this(userName,firstName, lastName, null); } public User(String userName, String firstName, String lastName, Point location) { Assert.notNull(userName); Assert.notNull(firstName); Assert.notNull(lastName); this.userName = userName; this.firstName = firstName; this.lastName = lastName; this.location = location; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public Point getLocation() { return location; } public void setLocation(Point location) { this.location = location; } @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } UserJ j = (UserJ) o; if (!userName.equals(j.userName)) { return false; } if (!firstName.equals(j.firstName)) { return false; } if (!lastName.equals(j.lastName)) { return false; } return location != null ? location.equals(j.location) : j.location == null; } @Override public int hashCode() { int result = userName.hashCode(); result = 31 * result + firstName.hashCode(); result = 31 * result + lastName.hashCode(); result = 31 * result + (location != null ? location.hashCode() : 0); return result; } @Override public String toString() { return "User{" + "userName='" + userName + '\'' + ", firstName='" + firstName + '\'' + ", lastName='" + lastName + '\'' + ", location=" + location + '}'; } } data class User(
 var userName: String,
 var firstName: String,
 var lastName: String,
 var location: Point? = null
 )
  14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Optional and named parameter 14 // Given the following function fun reformat(str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true, divideByCamelHumps: Boolean = false, wordSeparator: Char = ' ') { } // You could call reformat("foo bar")
  15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Optional and named parameter 15 // Given the following function fun reformat(str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true, divideByCamelHumps: Boolean = false, wordSeparator: Char = ' ') { } // You could call reformat("foo bar", true, true, false, '_')
  16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Optional and named parameter 16 // Given the following function fun reformat(str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true, divideByCamelHumps: Boolean = false, wordSeparator: Char = ' ') { } // You could call reformat("foo bar", wordSeparator = '_')
  17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Optional and named parameter 17 // Given the following function fun reformat(str: String, normalizeCase: Boolean = true, upperCaseFirstLetter: Boolean = true, divideByCamelHumps: Boolean = false, wordSeparator: Char = ' ') { } // You could call reformat("foo bar", normalizeCase = true, upperCaseFirstLetter = true, divideByCamelHumps = false, wordSeparator = '_' )
  18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Null safety 18 class User(
 var userName: String,
 var firstName: String,
 var lastName: String,
 var location: Point? = null
 )
  19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Null safety 19 class User(
 var userName: String,
 var firstName: String,
 var lastName: String,
 var location: Point? = null
 ) var walter = User("wwhite", "Walter", "White") var location:Point? = walter.location var location2 = walter.location var location3:Point = walter.location ?: Point(0.0,0.0,0.0) var x = walter.location?.x
  20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ How I fell in love with a programming language? 20 « For many years my perspective was simple — I didn’t have to love Java (or whatever programming language) to do my work well.That all changed a few months ago. » Dan Kim, Basecamp
  21. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring + Kotlin
  22. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ http://start.spring.io/#!language=kotlin 22
  23. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring Boot + Kotlin 23 + Same pragmatic and innovative mindset
  24. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Friction points (will be fixed in 1.1) 24 • @RequestMapping(method=arrayOf(GET)) • @GetMapping with Spring 4.3+ • Kotlin’s « final by default » behavior is not a good fit with CGLIB proxies • For @Service and @Repository, use JDK dynamic proxies when possible (default with class + interface) • For other cases, @Configuration classes and @Bean methods, explicit open modifier is required
  25. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ https://github.com/sdeleuze/spring-kotlin 25
  26. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Geospatial Messenger case study
  27. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Geospatial Messenger 27 + + + = User location with HTML5 geolocation Popover Bootstrap (CSS + JS) OpenLayers 3 map Layer of points retrieved through REST JSON API /messages/bbox/{xMin},{yMin},{xMax},{yMax} or pushed via Server-Sent Events
  28. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Code available on GitHub 28
  29. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Spring MVC Controller 29 @RestController @RequestMapping("/user")
 class UserController(val repository: UserRepository) {
 
 @PostMapping @ResponseStatus(CREATED)
 fun create(@RequestBody u: User) { repository.create(u) }
 
 @GetMapping
 fun list() = repository.findAll()
 
 @GetMapping("/bbox/{xMin},{yMin},{xMax},{yMax}")
 fun findByBoundingBox(@PathVariable xMin:Double, @PathVariable yMin:Double,
 @PathVariable xMax:Double, @PathVariable yMax:Double)
 = repository.findByBoundingBox(PGbox2d(Point(xMin, yMin), Point(xMax, yMax)))
 
 @PutMapping("/{userName}/location/{x},{y}") @ResponseStatus(NO_CONTENT)
 fun updateLocation(@PathVariable userName:String, @PathVariable x: Double, @PathVariable y: Double)
 = repository.updateLocation(userName, Point(x, y))
 } New in 4.3: constructor injection without @Autowired if single constructor New in 4.3: method specific aliases for @RequestMapping Classes are public by default Type inference + shorter syntax for one line functions Methods are public by default
  30. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Repository Choosing Spring Data JPA is perfectly fine with Kotlin* but why not trying using a type-safe Kotlin SQL DSL like Exposed * See https://github.com/sdeleuze/spring-boot-kotlin-demo
  31. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Why using SQL without JPA? • More control on SQL queries and joins • Lighter technology stack • Take advantage of native database functionalities • We rarely need to change databases
  32. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ PostgreSQL native JSON support CREATE TABLE "users" (
 user_name text PRIMARY KEY,
 first_name text,
 last_name text,
 metadatas jsonb
 );
 CREATE INDEX users_metadatas_gin on users USING GIN(metadatas jsonb_path_ops);
 INSERT INTO users VALUES ("wwhite", "Walter", "White",
 '{
 "address":{
 "line1":"308 Negra Arroyo Lane",
 "postcode":"87104"
 "city":"Albuquerque"
 "state":"New Mexico"
 },
 "foo":"bar"
 }');
 SELECT * FROM users WHERE doc @> '{ "address": { "postcode":"87104" } }';
  33. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Regular schema.sql CREATE TABLE IF NOT EXISTS "users" (
 user_name text PRIMARY KEY,
 first_name text,
 last_name text,
 location GEOMETRY(Point, 4326)
 );
 CREATE INDEX IF NOT EXISTS users_gix
 ON "users"
 USING GIST (location);
 
 
 CREATE TABLE IF NOT EXISTS messages (
 id SERIAL PRIMARY KEY,
 content text NOT NULL,
 author text REFERENCES users(user_name),
 location GEOMETRY(Point, 4326)
 );
 CREATE INDEX IF NOT EXISTS messages_gix
 ON messages
 USING GIST (location);
  34. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ SQL schema with Kotlin + Exposed object Messages : Table() {
 val id = integer("id").autoIncrement().primaryKey()
 val content = text("content")
 val author = reference("author", Users.userName)
 val location = point("location").nullable()
 }
 
 object Users : Table() {
 val userName = text("user_name").primaryKey()
 val firstName = text("first_name")
 val lastName = text("last_name")
 val location = point("location").nullable()
 }
  35. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Repository interface interface CrudRepository<T, K> { fun createTable() fun create(m: T): T fun findAll(): Iterable<T> fun deleteAll(): Int fun findByBoundingBox(box: PGbox2d): Iterable<T> fun updateLocation(userName:K, location: Point) } interface MessageRepository: CrudRepository<Message, Int> interface UserRepository: CrudRepository<User, String>
  36. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Repository implementation @Repository
 @Transactional
 class DefaultUserRepository : UserRepository {
 
 override fun createTable() = SchemaUtils.create(Users)
 
 override fun create(user: User): User {
 Users.insert(toRow(user))
 return user
 }
 
 override fun updateLocation(userName:String, location: Point) {
 location.srid = 4326
 Users.update({Users.userName eq userName}) { it[Users.location] = location}
 }
 
 override fun findAll() = Users.selectAll().map { fromRow(it) }
 
 override fun findByBoundingBox(box: PGbox2d) =
 Users.select { Users.location within box }.map { fromRow(it) }
 
 override fun deleteAll() = Users.deleteAll()
 
 private fun toRow(u: User): Users.(UpdateBuilder<*>) -> Unit = {
 it[userName] = u.userName
 it[firstName] = u.firstName
 it[lastName] = u.lastName
 it[location] = u.location
 }
 
 private fun fromRow(r: ResultRow) =
 User(r[Users.userName], r[Users.firstName], r[Users.lastName], r[Users.location])
 
 } Exposed now supports Spring @Transactional (should be on @Service in real apps) Write your SQL queries with a Kotlin type-safe DSL infix notation equivalent to Users.userName.eq(userName) Geospatial extensions are not supported by Exposed, so how can I write that ???
  37. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin extensions class PointColumnType(val srid: Int = 4326): ColumnType() {…} fun Table.point(name: String, srid: Int = 4326): Column<Point> = registerColumn(name, PointColumnType()) // Usage object FooTable : Table() {
 val location = point("location")
 }
 ————————————————————————————————————————————————————————————————————————————————— class WithinOp(val e: Expression<*>, val box: PGbox2d) : Op<Boolean>() {…} 
 infix fun ExpressionWithColumnType<*>.within(box: PGbox2d) : Op<Boolean> = WithinOp(this, box)
 
 // Usage var box = PGbox2d(Point(0.0, 0.0),Point(0.0, 0.0)) FooTable.select { FooTable.location within box }
  38. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Configuration @SpringBootApplication
 @EnableTransactionManagement
 open class Application {
 
 @Bean
 open fun objectMapper(): ObjectMapper {
 val mapper:ObjectMapper = Jackson2ObjectMapperBuilder().modulesToInstall(PostGISModule()).build()
 mapper.setSerializationInclusion(Include.NON_NULL)
 return mapper
 }
 
 @Bean
 open fun transactionManager(dataSource: DataSource) = SpringTransactionManager(dataSource)
 
 @Bean
 open fun persistenceExceptionTranslationPostProcessor() = PersistenceExceptionTranslationPostProcessor()
 
 @Bean
 open fun init(ur: UserRepository, mr: MessageRepository) = CommandLineRunner {
 ur.createTable()
 // ...
 ur.create(User("swhite", "Skyler", "White"))
 // ...
 }
 
 }
 
 fun main(args: Array<String>) {
 SpringApplication.run(Application::class.java, *args)
 } New in 4.3: Kotlin Jackson module automatically registered Top level function open needed because of CGLIB open needed because of CGLIB
  39. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Gradle goes Kotlin !!!
  40. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Build Gradle written in Kotlin (build.gradle.kts) buildscript {
 repositories {
 mavenCentral()
 gradleScriptKotlin()
 }
 dependencies {
 classpath(kotlinModule("gradle-plugin"))
 classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE")
 }
 }
 apply {
 plugin("kotlin")
 plugin("spring-boot")
 }
 repositories {
 mavenCentral()
 maven { setUrl("https://dl.bintray.com/kotlin/exposed") }
 maven { setUrl("https://dl.bintray.com/sdeleuze/maven/") }
 }
 dependencies {
 compile("org.springframework.boot:spring-boot-starter-web") {
 exclude(module = "spring-boot-starter-validation")
 }
 compile("org.springframework.boot:spring-boot-starter-jdbc")
 compile("org.springframework.boot:spring-boot-devtools")
 
 compile(kotlinModule("stdlib"))
 compile(kotlinModule("reflect"))
 compile("com.fasterxml.jackson.module:jackson-module-kotlin:2.7.5")
 
 compile(exposedModule("exposed"))
 compile(exposedModule("spring-transaction")) ...
 }
 fun exposedModule(val module: String) = "org.jetbrains.exposed:$module:0.5.0"
  41. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Game changer : autocomplete and validation
  42. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Deployment • Regular Spring Boot Runnable JAR • 18 MBytes • Start within 2.8 seconds on my laptop • Run with -Xmx32m !!!
  43. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin for client side development
  44. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin2js map.kt declarations/openlayers.kt declarations/other.kt Kotlin2js See https://github.com/sdeleuze/geospatial-messenger/tree/kotlin-js map.js lib/kotlin.js
  45. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ declarations/other.kt package declarations
 
 import jquery.JQuery
 import org.w3c.dom.Element
 
 @native("$")
 val j: dynamic = noImpl
 
 @native
 fun JQuery.append(element: Element): JQuery = noImpl
 
 @native
 fun alert(a: Any) {}
  46. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ declarations/openlayers.kt package openlayers
 
 import org.w3c.dom.Element
 import org.w3c.dom.events.Event
 
 @native
 object olx {
 interface MapOptions {
 var controls: Any? get() = noImpl; set(value) = noImpl
 var layers: Array<Any>? get() = noImpl; set(value) = noImpl
 var target: Any? get() = noImpl; set(value) = noImpl
 var view: ol.View? get() = noImpl; set(value) = noImpl
 }
 interface OverlayOptions {
 var element: Element? get() = noImpl; set(value) = noImpl
 var positioning: ol.OverlayPositioning? get() = noImpl; set(value) = noImpl
 }
 interface ViewOptions {
 var zoom: Number? get() = noImpl; set(value) = noImpl
 }
 interface Projection {
 }
 @native
 object control {
 interface DefaultsOptions {
 var attributionOptions: Any? get() = noImpl; set(value) = noImpl
 }
 } // ...
  47. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ • Auto-complete + compile time checks • Sharing code between client-side and server-side (domain model, validation) • Source map Kotlin on client-side
  48. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin 1.1 Javascript support • TypeScript API definition -> Kotlin API definition • Module support • Better documentation • Better IDE integration • More ES6 support
  49. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Web Assembly? • WebAssembly (WASM) = Web bytecode • Supported by major browser vendors • ES6 or TypeScript for the JavaScript ecosystem • In 2017, JavaScript won’t be the web bytecode anymore • WASM is a huge opportunity for Kotlin • Avoid the compiling to JS hack • Faster, less memory consumption • A new ecosystem to create
  50. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learn Kotlin
  51. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin Koans try.kotlinlang.org
  52. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Community kotlinlang.org/community.html
  53. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ What’s next?
  54. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin support in Spring • spring-kotlin: Kotlin extensions for Spring • reactor-kotlin: Kotlin extensions for Reactor • Kotlin nullable first class support in Spring Framework • Improve Kotlin integration in Spring Boot
  55. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin 1.1 (M01 preview released) • Coroutines • Type aliases • Java 8 bytecode generation • Jigsaw support • CGLIB style proxies without open • Kotlin to Javascript compiler
  56. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Kotlin native? • LLVM backend • AOT compiler • Lightweight runtime (think 128K RAM) • Targets: embedded, IoT, iOS • Bridge to Web Assembly?
  57. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software,

    Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/