Writing type-safe language while maintaining less boilerplate code is an important aspect of programming languages in terms of developer’s productivity. Because type-safe code is less error-prone and less boilerplate code leads to more readable code, both together means reduced development time. Type-inference is a great programming language feature that maintains this balance.

Developers usually read more often than write. Thus, even if the source code will end up being processed by the computer, most of the time our focus is putting it into more human-readable form. At some point, we pay attention to the UX principles, like:

Humans have a limited attention span, so source code should help to spend this attention wisely. Information comes at a cost, so the longer the code is, the more overwhelming it is to read.

Sometimes, less means more. Short code may look brilliant, but it amplifies the time that others must spend on it. We should provide just enough information. Implicit values, if we do not abuse them, are the fix for this.

Let's introduce an example of this. It is well-known that .json is used as an application configuration. Imagine we want to build up a tcp connection. What we need is to read the connection information from the config file and set the connection builder's fields based on it.

Here, we reach the fields without using their type information. Instead, we get them like they are some kind of information stored under some path. This could happen through the implicit values and type inference feature of Scala language. Below, you can see the step by step explanation of how it works.

First, we need to define wrapper for our existing JsonObject class so that we can use methods like \\, \.

This will cause JsonObject to be wrapped upon method call \\. Our next objective is to wrap methods like getString, getInteger, getBoolean, getJsonArray, so that we can use the abstraction of \ method to reach the fields. Hence, we should also wrap getters using the GetterWrapper trait and define another method \ in the JsonWrapper class.

Here, method \ has type parameter T. This parameter's value will be determined by the type inference. For example, setAddress method of ConnectionBuilder accepts String so T will be String and the available implicit value will be chosen by compiler and placed as variable ex. Therefore, we need to define the implicit values like this...