Posts

Showing posts with the label Kotlin

Using the Same Language for Microservices, iOS Apps, and Browser / Web Apps

Image
You're looking for the appropriate language?  Kotlin  might be the language you're looking for! Here you can find some sample projects that show how it can actually be done: Sample iOS app, written in Kotlin, using Maven or Gradle for building   —  this is how it looks Browser app that shows how Kotlin can access HTML's DOM  — this is  how it looks Browser app written in Kotlin that uses HTML5' Canvas  — this is  how it looks Another Browser app that shows how Kotlin can be used to build HTML5 apps   — this is  how it looks …all projects should work out-of-the-box.

Kotlin/JavaScript HTML5 Canvas Example

Image
This is the  source for a simple Kotlin (JavaScript) HTML5 Canvas app  that lets one type a random series of letters. And this is  how it looks like .

Kotlin/JavaScript HTML5 Example for DOM Manipulation

Image
I just published a simple  Kotlin/JavaScript "getting started app"  that  shows the Unicode characters for a specific decimal range. And  this is how it looks like .

Kotlin JavaScript “Hello, World!” Project

Image
 This  GitHub repository  provides you with detailed instructions and an out-of-the-box working sample project to get started with Kotlin and its JavaScript transpilation  capability.

Escape @Value Spring Annotation in Kotlin

Image
If you are using Spring annotations like  Value(" ${repositoryServiceUri} ") in your Kotlin code, you might get compile-time errors like these Error:Kotlin: [Internal Error] org.jetbrains.jet.utils.KotlinFrontEndException: Exception while analyzing expression at (16,14) in /Users/alex/my/project/loxal/rest-kit/src/main/kotlin/net/loxal/soa/restkit/client/RepositoryClient.kt: repositoryServiceUri Error:Kotlin: Compiler terminated with exit code: 2 because the ${blub}  notation is also used by Kotlin for expression and literal resolution. So just add a backslash like Value(" \${repositoryServiceUri} ") and everything is going to be alright. 

Kotlin / Java / GWT / JavaScript Interoperability HTML5 Web CRUD Showcase

Image
Check out the  code  and check out the actually  deployed and working showcase app  :)

Using Kotlin for DTOs instead of Java

Image
Creating DTOs  in Java, you often end up with very verbose code, similar to the following Address data class: public class Address { private String contactName; private String companyName; private String street; private String streetNumber; private String streetAppendix; private String zipCode; private String city; private String country; private String state; private String contactPhone;  public String getContactName() { return contactName; } public void setContactName(final String contactName) { this.contactName = contactName; }          // 90 lines of getter / setter code has been omitted here!   } Studies have shown  that there is a correlation between code size and erroneous code . Hence reducing code size results in concise code which improves readability and understanding of the underlying solution idioms. The following Kotlin data class  with merely 11 lines of code re...