Deploy Value

Milan Kotlin Community Conf

22 Giugno 2018 - 9 minuti di lettura

Thursday June 14th, Istituto Piero Pirelli: a piece of history has been written. The first Italian one-day conference about Kotlin happened!

Everything started with the check-in moment where we welcomed attendees and speakers to give them badge, t-shirt, and stickers of Intré, Agile ReloadedMolo17 (the sponsors of the event), Kotlin and Alf.io (big thanks to Celestino for his pleasantness and for helping us during the day: please take a look at Swicket.io for more info about the ticketing system we used)

After the check-in stage, everything was ready and Kotlin conference officially started (as Johan Duque kindly suggest in this picture)!

Keynote and all the talks were held in two different rooms named Elvis ?:D and Lambda {it} (a little Kotlin joke, of course)

Nando has opened the conference telling everyone how this conference was born.

So let’s get started!
Since I’m not a super-hero (I don’t have the ubiquity super power 🙂 ) below I will tell you something about the talks I personally followed.

Multi-platform Kotlin projects

Victor Kropp, software Engineer at JetBrains, talked about the advantages of adopting Kotlin as language in a multi-platform project.

Nowadays for any type of software project we work for, we tend to use different languages for the frontend and the backend, each of these certainly has it’s pros and cons:

  • Android: Java, Kotlin…
  • iOS: Objective C, Swift…
  • Desktop application: C++, C, C#…
  • Backend: Java, Python, Ruby…

Victor says: “Switching between different languages is never easy, what about considering to use only one language for the whole project?”
Kotlin is the answer!

Here is why:

  • It could be used for all platforms
  • The team can speak a same language
  • The team can work for all set of application
  • Fullstack development gets simplified
  • Having the code written in the same language is more maintenable
  • Knowledge transfer process could take less time

Victor explained us how to organize the architecture for a multi-platform project using Kotlin modules module and platform, and last but not least, demo time, a TO-DO list application with some web-server code (get, post, put), html page and error handling. Everything written using Kotlin common modules and libraries:

To recap in three short bullet points:

  • Consider using Kotlin in multi-platform application
  • Reuse business logic and data structure
  • This language is as power as cool!

Thank you Victor!

Functional programming triage

Francesco Sacchi made a wonderful introduction to functional programming, trying to answer two questions: “What is functional programming?” and “Why should I adopt it?”.

Not having any luck finding a good compact definition online, Francesco has made his own: “Functional programming is a style that maximizes readability“.

Readability is a very important aspect of the code we write: our code will necessarily be read by people, even ourselves, in order to fix bugs, add new features, adapt and evolve the code. And often, lot of time is spent reading code, but few time is actually spent writing it. For that reason we, as professional developers, want to increase the readability of our code, so functional programming is a style that helps us with that.

As for the language, Kotlin has a good support for functional programming with some interesting features:

– first class functions
– dsl support
– extension functions
– data classes and typealiases
– tail call optimization

Building DSL in Kotlin for fun and profit

Zan Markan started his talk about Domain Specific Language in Kotlin, showing us the pros:

  • Adapting the language
  • Allowing non-dev to read code
  • Readability
  • Save time on repetitive things (method, class…)

and cons:

  • Learning curve and maintainability
  • Adopting DSL can cause unintended side-effects

What is the difference between internal and external DSL?
An internal DSL live inside the host language while an external DSL depends on your application domain

We have everywhere DSL:

  • grep, wc, ls, sort (text processing in Unix)
  • hamcrest (testing)
  • gradle, make (configuration)

In Kotlin, one of the most popular DSL is Anko (simplify Android application development), or gradle Kotlin DSL for build definition.

This language is not only DSL compliant. It gives us other cool features:

  • Type aliases
  • Extension function
  • Lambda expression
  • Named arguments
  • Default values
  • Infix functions
  • Function literals with receiver
  • Operator overloading

An interesting introduction, but even more interesting live! Zan decided to show us all these features during his demo. Hands on code, he wrote a DSL step by step writing code about type aliases, overloading operators, infix functions and function literals.
It was very funny and interesting, well done Zan!

Kotlin beyond Android

As an Android developer you probably tried Kotlin the day it was announced as supported, then you loved it. Feeling a bit more comfortable with the language, you probably wondered “what else could I do?”.

Guillermo Orellana tried to answer that question.

He started showing us some screenshots of  his first app made in Kotlin, talking about similarities about expectation and excitation, pros and cons of adopting this language.

In his demo, he didn’t want show us a typical TO-DO list (no offence Victor, he was kidding 🙂 ) but another application fully written in Kotlin:

  • Web: Kotlin meet Javascript, Kotlin to Javascript… what about with types? No problem, dynamic keyword resolve the problem!
  • UI: Kotlin meet ReactJs
  • Backend: stop using Node.js, but consider other framework as Vert.x, Spring or Ktor (Kotlin native, easy to use)

Guillermo also showed us some examples of promise implementation in Kotlin, and last but no least, a live demonstration of  doku, a module that deploy an application just pushed via git.

Funny, rousing and interesting talk, Guillermo!

From Java to Kotlin beyond Alt+Shift+Cmd+K

Do you need to convert your Java code to Kotlin code?
Using Android Studio, the magic happens with the simple Alt + Shift + Cmd + K combination.
But the new syntax is just the beginning, using Kotlin we can improve our code making it more readable and simpler to write.
That’s what Fabio Collini is about to share with us!

Starting from a classic Java code that create a list and make some operations of its data, Fabio has converted into the equivalent Kotlin listOf<T> using map, filter, distinct, sortedBy, joinToString methods.
The code was more readable, shorter (line of codes) and less complex compared with the equivalent written in Java8 using Stream.
What if you want add\remove\modify data of a list in Kotlin? Simply use MutableList<T> instead of listOf<T>.
And what about map? Fabio showed us how to add key;value into map using x to y where to is an example of infix function.

Fabio covered other interesting topics like:

  • companion objects, properties in a Kotlin class that can be compared to static properties obtained  in Java using keyword static
  • Kotlin coroutines: difference between sleep method used in Java and delay method used in Kotlin; example of thread management in Kotlin
  • delegates

It was a very interesting talk, Fabio shared with us not only technical info but his passion for Kotlin 🙂

Kotlin in legacy apps

Federico Oldrini talked about his experience on adopting Kotlin in a legacy project.
What’s the best way to prove it? Show your code, Federico! So he decided to do this using a class of an Android project he worked for.

The first step was to convert the Java code in the equivalent in Kotlin using the feature provided by the Android Studio IDE.
The worst is yet to come…the converted code was full of errors related to wrong import, old method calls.
These kind of errors are easy to resolve, but technical debt remains.
Why?

  • Classes written along years, written by different people
  • Old API’s used in classes
  • Code written to respond to big feature requests

Fighting against the “monster” of technical debt is never easy, but Kotlin is a powerful weapon. You can write a classic Person Java class in one unique row.

Thanks Federico, we’ll win the war, and Kotlin will give us a great help!

Everyone can build a REST service with Kotlin

Andrea Maglie spent his time to explain us how to organize the architecture to build a REST service for a Google assistant application.
The architecture is composed by DialogFlow, a Google-owned developer of human–computer interaction technologies based on natural language conversations, webhook, a Backend and a database.

DialogFlow is a good solution because it’s free, and it’s integrated into Google Platform. It analyzes a phrase, or question, to get the most important word, or keys. These keys needs to be sent to something that “queries” a database.
How to do that? With webhooks.
After that, the webhook communicates with the back-end that realizes the communication with the database.

Why should we choose Kotlin for our back-end instead of Javascript or Node.js?
Because Kotlin is easy to use and for its short learning curve when adopted to implement a REST server.
Andrea explained how to implement the back-end using Spark framework, showing us a simple web-server Kotlin code that exposes a simple “hello” endpoint.
From this simple code, Andrea showed us an example of POST request and than Ngrok to test our web-server.
Before leaving, Andrea talked a little about mockk.io, a library for unit testing.

Interesting talk, we all now a little bit how to write a DialogFlow application using Kotlin. Thanks Andrea!

Closing remarks

It was an exciting journey, lot of code and nice people. Before leaving Fabio, a business partner of Intré and chairman of Italian Agile Movement spent some words to thank all the sponsors that make this conference possible, the first agile venture event.
It’s time to go back home guys!
I hope every attendees and readers enjoy this article but…wait a moment! Everybody in Elvis room for ruffle time!


Damiano (with me in this picture) used his Kotlin written program to give some prizes to the lucky present attendees (using one simple rule: who leaved, leaved. Who remained, can partecipate to the lottery).

Prizes were:

  • Kotlin books
  • Kotlin e-books
  • JetBrains All Products Pack licenses

 

After this funny moment, it was really time to go.
We want to thank you all again for made this event possible, and remember that for attendees there is 40% discount: ctwkotlinconf18 (thanks to Manning).

Articolo scritto da