Kotlin: Three Reasons To Start Using It Today

Kotlin: Three Reasons To Start Using It Today

With the announcement at Google I/O 2017 that the Kotlin programming language will be officially supported as a first class citizen for the Android framework, there’s been a lot of talk around what Kotlin is and how it compares to Java. This post highlights the reasons why our development team at Shockoe feels that Kotlin is the wave of the future and why Android developers should start adopting it.

What is Kotlin?

Kotlin is a statically typed programming language that runs on the Java Virtual Machine (JVM). It’s a multi paradigm language that contains elements of object-oriented programming that you’d see in languages like Java and elements of functional programming like what you’d find in JavaScript.

Why should you start using Kotlin?

Here are our top three reasons why you should jump in:

#1 Easily integrated into your mobile stack

Kotlin code is compiled into the same bytecode that your regular Java programs are and uses the Java Virtual Machine (JVM) to execute that code.
This means that Kotlin still has access to all the same libraries and frameworks available to you in the Java world with the addition of those from the Kotlin standard library. This also allows Kotlin and Java code to run concurrently with one another. Java classes calling methods in Kotlin classes or libraries and vice versa. This can even be done in the same file. Take this example from a library that handles unit conversion:

fun celsiusToFahrenheit(value: Double): Int = Math.round(value * 1.8 + 32).toInt()

Here we have a function that takes a Double parameter and returns an Int. However, we want to use the java.lang.Math class to round as this feature doesn’t exist in Kotlin. So we round to the nearest place and call a method from the Kotlin Double class to convert the result into an Int.

This duality of execution allows developers to easily convert their existing Android projects from Java to Kotlin or to simply add new features written in Kotlin, without converting previously written code.

Additionally, Kotlin has an option to compile into JavaScript which is compatible with the standard JavaScript specifications like Asynchronous Module Definition (AMD), CommonJS, and Universal Model Definition (UMD). This allows developers to share code written in Kotlin to other environments like Node.js or even to cross platform environments like to Appcelerator’s Titanium framework.

#2 Multi-paradigm language

A lot of the developers from Shockoe come from multiple different backgrounds. Some started with Java and transitioned into writing JavaScript while others started with JavaScript and have since learned about other languages.

Kotlin adds a lot of functional features to the object-oriented nature of Java. I realize that Java 8/9 adds similar features but this post is specific to the Android platform.

These features coupled with improved/sugar syntax lead to a much more easily read codebase. I won’t go over all the features but some of the most prominent ones are higher order functions, null safety, better typing with type inference, and much less boilerplate code.

These features, in particular, allow a developer to write much cleaner code and a lot less of it. Here’s an example of some Java code to perform and common action – filtering a list:

 ArrayList getAllEvenValues(int[] values) {
    ArrayList filtered = new ArrayList<>();
    for (int i : values) {
       if (i % 2 == 0) {
          filtered.add(i);
       }
    }
    return filtered;
 }

This isn’t too terribly much but it can quickly spiral out of control as you start adding more complexity. The Kotlin equivalent would look like:

fun getAllEvenValues(values: List): List = list.filter { it % 2 == 0 }

Yep, that’s it. There are many more operators that can be appended to the end of that, for instance if you wanted to map the results to strings and return the string list you just make one minor change.

fun getAllEvenValues(values: List): List = list.filter { it % 2 == 0 }.map { it.toString() }

#3 Official Support From Google

No brainer here, right? However, the announcement from Google I/O 2017 is a huge deal for the language. In addition to the benefits of Kotlin over Java such as those detailed above, Kotlin will now have full support in Android Studio and within the Android ecosystem. JetBrains and Google are working together to continue to support the language into the foreseeable future.

Kotlin is by no means meant to replace Java. However, it will allow for better apps to be written using a much more modern and architected language that keeps developers in mind.

Conclusion

Now is a great time to jump into Kotlin and to start writing your Android apps with it. It will lead to better productivity for your mobile team, as they’ll be writing less code – which will be more readable and therefore easier to maintain.

Additionally, if you’re a multi-platform development team, the cross compilation into JavaScript is a great addition as you can easily create tools that work within frameworks for both languages.

Then there’s also the similarities between Kotlin and Swift as is highlighted here. This helps  bridge the gap between iOS and Android development teams.

Additional Resources

Official Kotlin Documentation

Sample Kotlin App

Kotlin Android (Layout) Extensions

Anko – Library with many Kotlin helper tools for Android

Kovenant – Promises for Kotlin

Virtual, Augmented and Mixed Reality… Confused Yet?

Virtual, Augmented and Mixed Reality… Confused Yet?

There are exciting new worlds being created, recreated and explored as we speak. There are digital worlds being developed from the inspirations of Earth and beyond. For those of us not able to travel to places like the polar ice caps, the Sistine Chapel, Rome, the Pyramids of Egypt, Mars, or other places we may not be able to visit in our lifetime, this is our chance. Now, we have the opportunity to visit them from the comforts of our very own homes.

Our mobile enterprise company, Shockoe.com has recently branched out into the brave new world of Virtual Reality (VR). In this ambitious new venture, there are many things to consider. First, let’s break down the different branches of the digital realities.

VR provides the user with a digitally created 360 degree world using a type of headset, whether it’s utilizing Google cardboard, an Oculus or one of the many other options of headset viewers. Augmented Reality (AR) uses our mobile devices and overlays digital images over physical reality (ever heard of Pokemon Go)? Lastly, and my favorite, there’s Mixed Reality (MR).

MR might be such an advanced technology, that we likely won’t see this catch on until VR and AR are more of a regularity. MR is the ability to use virtual reality inside of our physical world. For instance, a doctor performing surgery on a patient could use a virtual magnetic resonance imaging (MRI) or X-ray scanner over their patient, providing them with an accurate view inside their patient’s body. Mind-blowing, right?

Now that you have an idea of the different realities being created, let me tell you that there is nothing more exciting than having the opportunity to design the User Experience (UX) and User Interface (UI) for these exciting realities. When starting the conversation of UX for VR, it’s easy to get a little carried away. The possibilities seem endless (because they are), which is why it’s important to focus on what’s best for the user, what makes the most sense for the user to do in order to see and navigate our experiences. What does the client want to provide their users?

These questions are seemingly simple, yet necessary. A UX/UI designer needs to know what type of VR they are designing for. Is it for a headset alone, headset with camera sensors, or headset with gloves? What are the limitations of this experience? How far can the UX/UI designer push these limitations while still maintaining a fulfilling, yet positive user experience? What can I designer do to keep users returning to their fascinating VR experiences and even share them with others?

shockoe_vr_coneoffocusUsers with solo headsets can only use their Field of View (FOV) or Cone of Focus to make their selection, not their hands. While this might seem limiting, it’s not. Keep in mind that this is VR, where the user can turn in any direction they choose and explore a new world by just putting on a headset. Making a selection through vision is quite simple. A UX designer could use a countdown, various loading animations, or status bars. They can even invent something totally new and intuitive that hasn’t been thought of yet.

Making a selection is one thing, navigating these new worlds is another. There are a lot of different things to consider when navigating in VR. For one thing, it’s somewhat similar to navigating our physical world in terms of our FOV. We all have our own, some of us more or less than others, and the Cone of Focus is how designers segment the FOV.

The UX designer should focus the user’s primary actions within the initial area of vision. When we look directly forward, by just moving our eyes we can see approximately 90 degrees within our central vision. Everything outside of that is our far peripheral vision and should be designed accordingly by placing only secondary and tertiary user actions within these areas of vision, such as motion cues or exit options.

These are extremely important limitations to know when designing the UX for VR experiences. These degrees of vision define how the UX should be envisioned and implemented. Without making the user work too hard to explore their new digital surroundings, the UX designer must take into account the Cone of Focus for all primary actions without taking away from the extraordinary experience of VR. Thus, making one consider the visual placement of UX design by measurements of FOV degrees throughout the app.

While all of this information may seem overwhelming, it is also very, very exciting. Designing UX and UI in 360 degrees is a phenomenal opportunity to learn, adapt and innovate in this amazing new digital age. At Shockoe.com, we are on the edge of our seats with excitement about being able to provide our clients with the intuitive experiences their users want through innovative technology that VR offers.