Skip to content

Instantly share code, notes, and snippets.

View cbruegg's full-sized avatar

Christian Brüggemann cbruegg

View GitHub Profile

Using Kotlin in Android projects

What is Kotlin?

Kotlin is a programming language backed by JetBrains, the company that develops IntelliJ IDEA, which is the backend of Android Studio. After five years of development, version 1.0 was released in February, 2016. Kotlin compiles to JVM bytecode that is fully compatible with the Android platform. The developers even pay special attention to it by providing libraries (for example Anko), tooling and more.

It is a language designed for interoperability with Java code, which allows for a gradual migration from Java to Kotlin. The tooling is great and aids usability much. Additionally, picking up the language is very easy if you already know Java, since the syntax and concepts are similar, while still providing a lot of value for developers held back by the bad Java support on Android. Most developers are currently limited to Java 7 or even Java 6 and it will take a long time before we'll be able to properly use features like lambda expressions to make code mo

@cbruegg
cbruegg / KnuthMorrisPratt.kt
Last active October 27, 2016 19:53
An implementation of the Knuth-Morris-Pratt String matching algorithm in Kotlin.
/**
* For each i in [0, length), this function computes
* the length of the longest suffix of a substring of pattern from 0 to i
* that is also a prefix of the pattern itself.
*/
private fun computePrefixFunction(pattern: CharSequence): IntArray {
val resultTable = IntArray(pattern.length)
var matches = 0
for (i in 1..pattern.length - 1) {