De-Structuring in Kotlin

Recently I wrote an article about de-structuring in TypeScript, and hinted that Kotlin has a similar feature, but in more of a “strongly typed” language style. Today I want to discuss that feature. To re-cap from the previous article, de-structuring is, at the core, a syntactic sugar to easily “lift” parameters out of an object or array and declare local all in one shot. With ECMAScript and TypeScript, this comes in two forms: positional (for arrays and iterables) and by name (for objects). [Read More]
kotlin  java 

Typescript for Java Developers: Index Types

A fairly recent addition to Typescript is index types and the keyof operator. For a Java developer this is an interesting thing to learn about, as Java doesn’t have this feature, specifically due to type system inflexibility. Academically speaking, an index type is a small facet of dependent type systems (where one type in use is dependent upon the value of another input). This is also, in effect, a way to get many of the benefits of a heterogenous map. [Read More]

Typescript for Java Developers: De-Structuring of Variables

ECMAScript is all about wrangling loosely typed variables. In a compiled and strongly typed language like Java, classes have a fixed shape (aka schema) and every object follows that pattern strictly. With ECMAScript, objects are more “ad-hoc” in that any single object be comprised of any combination of properties. Prototypes help with pre-defining that combination, but you can muck around with it all you want. Consequently, there is an opportunity for language features around lifting, shifting, filtering, and moving around properties from objects. [Read More]

Typescript for Java Developers: Variable Scoping

When learning a language built on another existing platform, like TypeScript (or, for that matter Kotlin), one of the challenges you face is understanding the underlying platform or language so that you can, in turn, understand how the higher-level language is applied to meet the restrictions and features of the lower-level language. Inevitably, no amount of documentation for a language built upon another language or platform is complete without some degree of knowledge of the underlying platform. [Read More]

What's the Deal with @JvmDefault?

Kotlin has an annotation called @JvmDefault which, like most of the “Jvm” prefixed annotations, exists to help massage the Kotlin compiler output to match Java classes in a certain way. This annotation was added in 1.2.40, and has now seen some experimental enhancements in 1.2.50, so it seems worth exploring what this is all about.

[Read More]
kotlin  java  jvm 

Diagnosing a 3.6L "Pentastar" Jeep JK Radiator Fan Issue (Code: P0480)

Recently, I was driving my 2015 Jeep Wrangler JK Unlimited through a parking lot on a 95 degree day, and after leaving a stop sign, a check engine light flashed on (later I would learn it was a P0480 Cooling Fan Relay 1 Control Circuit), and shortly thereafter my Jeep overheated. What followed was a multi-day Google searching and diagnostic session, which made me realize there is a lack of information as well as a lot of mis-information about the 3.6L “Pentastar” Jeep Wrangler model years, and how the radiator fan works.

This is my summary of what I learned about the cooling fans on these Jeeps, so hopefully more people can diagnose issues themselves.

[Read More]

Tail Recursion in Kotlin

Tail recursion can be a very elegant way to solve problems that involve a significant number of iterations but are better organized using recursion, without paying the cost you normally pay for recursion. Kotlin can enable the use of tail recursion. To understand the benefits of this, a quick recap would be of value.

[Read More]

Kotlin: Reified Type Function Parameters

As most Java programmers know, Java generics are erased at compile-time. This has trade-offs, but the two main reasons for this are:

  • Compatibility - Java 1.4 and earlier dealt exclusively in raw types at the VM level. Generics were able to compile without introducing significant new typing to the bytecode and classfile format spec, and having to deal with older classes generated without that typing.
  • Simplicity - By erasing to raw types, the JVM doesn’t have to understand specialization; something that has its own complexities and downsides. For example, specialized types are much more challenging to optimize with a just-in-time compiler.

However, knowing the type parameters used at runtime can have real value, and it’s something Java simply doesn’t offer. Kotlin would like to help in this area, but there are many challenges in doing so.

[Read More]
kotlin  java 

Kotlin Logging Without the Fuss

One of Kotlin’s strengths is that generally speaking, the code you might write in Java is generally more compact in Kotlin without losing any of the readability, functionality, or performance.

An odd case where that doesn’t prove to be true is declaring loggers as Java developers.

[Read More]