Observability Done Right: Best Practices and Anti-Patterns for Effective System Monitoring

Image
  WHAT Observability is a concept that refers to the ability to gain insights into the behavior and performance of complex systems. In the context of software engineering, observability involves the collection, analysis, and visualization of data from software applications, infrastructure, and other components of a system. In the animal kingdom, observability plays a critical role in survival, allowing animals to monitor their surroundings, detect threats, and find food. Dolphins use echolocation to observe their surroundings. They emit high-frequency sounds that bounce off objects, allowing them to create a 3D map of their environment. Thanks for reading Knowledge Cafe! Subscribe for free to receive new posts and support my work. Subscribed WHY In today's era, architectures are becoming increasingly large, complex, and fast-paced due to the faster development and deployment of software by distributed teams with the help of DevOps, continuous delivery, and agile development methodo...

Kotlin String Template


Lets learn about one of the awsome feature of Kotlin, String Templates !  This feature allows Strings to contain template expression.

One way to write code like below using string concatenation in java (which works in Kotlin as well)

package stringtemplate

fun main(args: Array<String>) {
    val carName = "BMW 5 Series"
    val carModel = "Saloon 3.0"
    val carPrice = 68000
    println(carName + " car of model " + carModel + " cost up to " + carPrice + " Euros")
}

With String Templates life will be much easier and code will be more readable, basically String Templates syntax in Kotlin used to dynamically embed variables and expressions into a string as your code executed.

package stringtemplate

fun main(args: Array<String>) {
    val carName = "BMW 5 Series"
    val carModel = "Saloon 3.0"
    val carPrice = 68000
    println("$carName  car of model $carModel cost up to $carPrice Euros")
}

Output of both above code sample will be exactly same. 

Unlike Java, many of Kotlin’s constructs (not all) are expressions. Therefore, a String template may contain conditions or logic. This is one of the major advantage of Kotlin over Java.

Lets see this in action via even/odd example 


public class Condition {
    public static void main(String[] args) {
        int x =101;
        if (x % 2 == 0)
            System.out.println("The number " + x +" is even.");
        else
            System.out.println("The number " + x +" is odd.");
    }
}

With Kotlin, the same code can be written as 

fun main(args: Array<String>) {
    val x = 101
    println("The number $x is ${if(x % 2 == 0) "even." else "odd."}")
}

That's all for this short lesson
Learn more about Kotlin from Official Kotlin site:


Popular posts from this blog

Chain of responsibility using Spring @Autowired List

Iterate Through a HashMap

Under the Hood: Understanding the Gossip Protocol in Apache Cassandra