Learning Kotlin – Part 6 – functions

This time we look at functions. Let’s take a simple function from Java: public int mult(int num1, int num2){ return num1 * num2; } In Kotlin it would look like this: fun mult(num1: Int, num2: Int): Int{ return num1 * num2 } A function definition always starts with the keyword fun. That’s fun isn’t it?…

Learning Kotlin – Part 5 – loops

This time we deal with loops Loops Kotlin has two types of loops: for and while. For-loop for(x in 1..10){ println(“Loop: $x”) } We can count backwards as well for (x in 10 downTo 1) { println(“Loop: $x”) } While-loop var i = 10 while(i > 0) { println(“$i”) i– } Break & Continue for(x…

Learning Kotlin – Part 3 – ranges

After Learning Kotlin  –  Part 1 and Learning Kotlin – Part 2 we will now dive into the ranges. One nice little feature is the .. syntax: you can generate an IntRange object just by specifying the start and the end element: val oneTo10 = 1..10 You can even use values for the start and…

Features and Permissions in Android

Features and Permissions A permission is something an app is allowed to do 🙂 E.g. using the camera, reading location or accessing your contacts. <uses-permission android:name=”android.permission.CAMERA” /> <uses-feature android:name=”android.hardware.camera” android:required=”true” /> Internet Access If your app uses e.g. web-APIs you need internet access. This can be achieved by adding android.permission.INTERNET to your manifest. In this…

Learning Kotlin – Part 2 – Arrays

In Learning Kotlin – Part 1 we looked at some basic concepts like type inference and string handling. In this part we deal with arrays: You can easily create an array with the arrayOf function var myArray = arrayOf(1, 1.23, “Jörn”) Element access You can access arrays directly with the [] operator println(myArray[2]) myArray[1] =…

Learning Kotlin – Part 1 – print

Motivation I wanted to try writing an Android app. In spite of using plain old Java I wanted to give the new kid on the block Kotlin (from the Jetbrains folks) a try. First observations Coming from a Python background it’s good to see that Kotlin doesn’t use semi-colons! But the curly braces from Java…

Python Protocols

In my article Python Type Checking I wrote about type hints. Type hints are around the block since Python 3.5. Python 3.7 introduced another interesting concept to make Python code even more type safe: Protocols Duck typing If it walks like a duck and it quacks like a duck, then it must be a duck…