Kotlin Python migration

From Kotlin Scripting to Python

GitHub offers a way to customize one’s profile by allowing one to create a README in a specific repository, named as your profile, e.g., nfrankel/nfrankel. A couple of years ago, I automated the update of my GitHub profile with up-to-date info: my latest blog posts, my upcoming talks, and the last recorded YouTube talk. I took the time to document how to do it on this blog. At the time, I chose Kotlin scripting because I was proficient enough in Kotlin, but I wanted to learn the scripting

Java Kotlin

Null safety: Kotlin vs. Java

Last week, I was at the FOSDEM conference. FOSDEM is specific in that it has multiple rooms, each dedicated to a different theme and organized by a team. I had two talks: Practical Introduction to OpenTelemetry Tracing, in the Monitoring and Observability devroomWhat I miss in Java, the perspective of a Kotlin developer, in the Friends of OpenJDK devroom The second talk is from an earlier post. Martin Bonnin did a tweet from a single slide, and it created quite a stir, even attracting Brian Goe

Kotlin API design extension delegation tip

Beautify third-party API with Kotlin

Scala has popularized the 'Pimp my library' pattern: This is just a fancy expression to refer to the ability to supplement a library using implicit conversions. — Pimp My Library Pattern in Scala Kotlin does provide the same capability. However, it achieves it via extension functions. While the generated bytecode is similar to Java’s static methods, the developer experience is the same as adding functions to existing types. This approach has limitations, though. One cannot

Kotlin serverless FaaS JVM performance GraalVM native

Kotlin and FaaS, an impossible union?

Some time ago, I read a post describing how to run a serverless Kotlin function on OpenFaaS. While the content is technically correct, I believe the concept itself is very wrong. Such posts can lead people to make ill-advised decisions: 'because we can' is hardly a winning strategy. in this post, I’d like to first explain why the JVM platform is a bad idea for FaaS. Then, I’ll proceed to propose alternatives to use Kotlin nonetheless. I deliberately chose not to link to the original

Spring configuration beans context Kotlin

Multiple ways to configure Spring

Two weeks ago, I wrote how you could write a Spring application with no annotations. Many alternatives are available to configure your Spring app. I’d like to list them in this post, leaving Spring Boot out of the picture on purpose. Core concepts Property file XML Groovy DSL Self-annotated classes Configuration classes Kotlin DSL Bean definitions Beans Conclusion Core concepts A couple of concepts are central in Spring. The related documentation doesn’t describe most of them

GUI SWT Kotlin

The state of JVM desktop frameworks: SWT

This is the 3rd post in the The state of JVM desktop frameworks focus series. This series is dedicated to the state of JVM desktop frameworks. After having had a look at Swing the previous week, this post focuses on the Standard Widget Toolkit. SWT originates from the Eclipse project, an IDE. For Eclipse, the developers built a dedicated framework to build their graphic components upon. Swing implements the drawing of widgets in Java from scratch. On the opposite, SWT is a thin wrapper API that r

Reactive Programming Kotlin coroutines Project Reactor

From Reactor to Coroutines

Last September, I wrote how to migrate from an Imperative Programming codebase to a Reactive Programming one in a step-by-step process. Because of its popularity, I illustrated the post with a Spring Boot demo. The final result uses Mono and Flux from Project Reactor. I also made sure that no step in the processing pipeline is blocking thanks to Blockhound. I wrote the code in Java so that it could be accessible to the largest audience. But I’m still a Kotlin fan at heart. Hence, I ported

GitHub Kotlin Kotlin Scripting Freemarker

Customizing your GitHub profile - Scripting

Recently, GitHub allowed users to customize the appearance of their profile page. This is different from GitHub Pages: it allows to add extra content to one’s GitHub profile. Since that feature is available, a lot of developers have decided to customize their page. I think this is fun, so I also wanted to do the same, in my own way. I wanted to describe it, so fellow developers can take inspiration. Since the whole process is a bit long, I’ve split this post in two parts. This par

programming language Kotlin Elixir

6 interesting features in programming languages

Java is the first language that I learned and used professionally. It has been my bread and butter for about a decade and half years. And yet, it’s not the only language I’ve learned nor used in all my years: for example, a long time ago, I’ve had to develop JavaScript code to implement a dynamic user interface. At that time, it was called DHTML…​ A couple of years ago, I also taught myself Kotlin, and never stopped using it. Last year, working for a new company, I t

Kotlin API design extension function

Write extension functions for your own classes in Kotlin

A recent question on Kotlin’s Reddit came to my attention lately: 'Why is it bad to write extension functions for classes that you own?' One of the answer was that it was the opposite: it’s a good practice, and for several reasons. Among them were two very important ones that improve the design of one’s code: Able to call the function on a nullable. For a class with generic types, add a function that is only available when a specific type is used.

Kotlin software design UML

Options for managing derived attributes in Kotlin

A derived attribute is an attribute computed from other attributes e.g.: The fullName is aggregated from the first, middle and last nameThe age is computed from the birthdateetc. Kotlin offers different options to manage such derived attributes. Let’s browse through them. Inline field initialization The simplest way to manage derived attributes is to declare a property, and compound its declaration with its initialization: class Person(val firstName: String, val middle

Kotlin collection sequence stream lazy evaluation

Kotlin, collections and sequences

When streams were added to Java 8, I wanted to jump on the bandwagon. I read blog posts, watched videos, attended workshops to understand what this was all about. After a while, I became comfortable enough…​ but I was unhappy with the implementation: while streams offer methods with a functional approach, legacy collections do not. When one wants to use Java capabilities on an existing collection, the later needs to be transformed to a stream, and then back again. For example, the f

Kotlin stdlib Stack Overflow

Elements combination in Kotlin collections

I’m not a regular StackOverflow user, neither as a contributor, nor to ask questions. However, I recently stumbled upon a question, tried to help…​ and failed. I was pointed out my answer was wrong - thanks for everyone who did. I think failures are great occasions to learn something new! In this post, I’d like to detail what I learned after digging further: there are several ways to combine elements from an existing collection in Kotlin stdlib.

Kotlin code quality SonarQube

Check the quality of Kotlin code

Last week, I read a post about Kotlin code analysis, thanks to the Kyiv Kotlin UG. I stumble upon a lot of similar posts: they show how to hack into the build to produce a text report showing quality issues. At the risk of sounding arrogant, I claim this is not proper software engineering. It’s a one-time hack: it has no value over the long term. Code quality is a serious subject, and should be treated accordingly. First, it needs to be evaluated, then issues have to be stored and compare

Kotlin hybris

Using Kotlin on the SAP Hybris platform

Since I discovered Kotlin, I use it in all my personal projects. I’ve become quite fond of the language, and with good reason. However, there’s yet no integration with the Hybris platform - though there’s with Groovy and Scala. This post aims at achieving just that, to be able to use Kotlin on Hybris projects. Generate a new extension The first step on the journey is to create a new extension: ant extgen Choose the yempty packageChoose an adequate name, e.g. 'kotlinfun'

Kotlin stdlib

Make your life easier with Kotlin stdlib

IMHO, Kotlin is not about big killer features - although extension methods and properties could certainly be categorized as such, but about a bunch of small improvements that have deep impact. Most of them are not built-in into the language, but are functions offered as part of the Kotlin standard library. In this post, I’d like to go through a limited set of them, and describe how they can be used to improve the code.

JVM bytecode javap Kotlin

Synthetic

There is a bunch of languages running on the JVM, from of course Java, to Clojure and JRuby. All of them have different syntaxes, but it’s awesome they all compile to the same bytecode. The JVM unites them all. Of course, it’s biased toward Java, but even in Java, there is some magic happening in the bytecode. The most well-known trick comes from the following code: public class Foo { static class Bar { private Bar() {} } public static void main(String... arg

Spring configuration Groovy Kotlin XML annotations

Flavors of Spring application context configuration

Every now and then, there’s an angry post or comment bitching about how the Spring framework is full of XML, how terrible and verbose it is, and how the author would never use it because of that. Of course, that is completely crap. First, when Spring was created, XML was pretty hot. J2EE deployment descriptors (yes, that was the name at the time) was XML-based. Anyway, it’s 2017 folks, and there are multiple ways to skin a cat. This article aims at listing the different ways a Sprin

code quality SonarQube Kotlin plugin ANTLR

A SonarQube plugin for Kotlin - Creating the plugin proper

This is the 3rd post in a series about creating a SonarQube plugin for the Kotlin language: The first post was about creating the parsing code itself.The 2nd post detailed how to use the parsing code to check for two rules. In this final post, we will be creating the plugin proper using the code of the 2 previous posts. The Sonar model The Sonar model is based on the following abstractions: Plugin Entry-point for plugins to inject extensions into SonarQube A plugin points to the ot

code quality SonarQube Kotlin plugin

A SonarQube plugin for Kotlin - Analyzing with ANTLR

Last week, we used ANTLR to generate a library to be able to analyze Kotlin code. It’s time to use the generated API to check for specific patterns. API overview Let’s start by having a look at the generated API: KotlinLexer: Executes lexical analysis.KotlinParser: Wraps classes representing all Kotlin tokens, and handles parsing errors.KotlinParserVisitor: Contract for implementing the Visitor pattern on Kotlin code. KotlinParserBaseVisitor is its empty implementation, to ease t

code quality SonarQube Kotlin plugin ANTLR

A SonarQube plugin for Kotlin - Paving the way

Since I started my journey into Kotlin, I wanted to use the same libraries and tools I use in Java. For libraries - Spring Boot, Mockito, etc., it’s straightforward as Kotlin is 100% interoperable with Java. For tools, well, it depends. For example, Jenkins works flawlessly, while SonarQube lacks a dedicated plugin. The SonarSource team has limited resources: Kotlin, though on the rise - and even more so since Google I/O 17, is not in their pipe. This post series is about creating such a pl

JavaScript Kotlin front-end

Kotlin for front-end developers

I assume that readers are already familiar with the Kotlin language. Advertised from the site: Statically typed programming language for the JVM, Android and the browser 100% interoperable with Java™ — Headline from the Kotlin website Kotlin first penetrated the Android ecosystem and has seen a huge adoption there. There’s also a growing trend on the JVM, via Spring Boot. Since its latest 1.1 release, Kotlin also offers a production-grade Kotlin to JavaScript transpiler. Thi

design Object-Oriented Programming tooling Bean Validation Kotlin IDE

Coping with stringly-typed

UPDATED on March 13, 2017: Add Builder pattern section Most developers have strong opinions regarding whether a language should be strongly-typed or weakly-typed, whatever notions they put behind those terms. Some also actively practice stringly-typed programming - mostly without even being aware of it. It happens when most of attributes and parameters of a codebase are String. In this post, I will make use of the following simple snippet as an example: public class Person { private fin

microservice Spring Framework Spring Cloud Kotlin HTTP monitoring Sleuth

HTTP headers forwarding in microservices

Microservices are not a trend anymore. Like it or not, they are here to stay. Yet, there’s a huge gap before embracing the microservice architecture and implementing them right. As a reminder, one might first want to check the many fallacies of distributed computed. Among all requirements necessary to overcome them is the ability to follow one HTTP request along microservices involved in a specific business scenario - for monitoring and debugging purpose. One possible implementation of it