Kotlin Language Features Related to Null Handling

Any software engineer with a Java background would find the null handling features in the Kotlin language interesting. Let's summarize this topic with some examples. Nullable types: In Kotlin, types are non-nullable by default. If you want a variable to be able to hold a null value, you need to explicitly declare its type as nullable using the Type? syntax. For example, String? denotes a nullable string, while String represents a non-nullable string. Safe calls (?.): Kotlin introduces the safe call operator (?.) for handling nullable types. It allows you to safely invoke a method or access a property on a nullable object. If the object is null, the expression returns null instead of throwing a NullPointerException. Example: data class Person(val name: String, val age: Int, val address: String?) fun main() {     // Create a person with a nullable address     val person1 = Person("John Doe", 25, "123 Main Street")     val person2 = Person("Jane Doe", 30,...

Notes on Parallel Programming

In the past, the performance of microprocessors increased on average, 50% per year. In this period, you could simply wait to buy the next generation of microprocessors that will speed up your applications. But since 2002, single processor performance has slowed down. By 2005, most manufacturers decided to go on in the direction of paralellism. They started to put multiple processors on a single circuit.

But this does not magically improve the performance of serial applications. It may be a silly question to ask: why do we need ever increasing performance? But why do they manufacture multi-core hardware? Because as the speed of transistor increase, so does the power consumption. The circuit becomes too hot and is not reliable anymore. And if the integrated circuit industry stop producing new and better products, those companies dissapear. So today, CPU clock speed is not increasing, and manufacturers does not design complex processors.

Most of the time, it is not possible to automatically convert serial programs to parallel programs. We need to find better algorithms that use parallelism.

In the classical Von Neumann architecture, there is a CPU, a memory and the interconnection between them. The seperation of memory and CPU is a bottleneck. Today CPUs can execute instructions more than one hundred times faster than they can read items from main memory.

To be continued..

Comments

Popular posts from this blog

Trie Data Structure and Finding Patterns in a Collection of Words

Virtual Memory

NOTES ON COMPUTER ARCHITECTURE: Some important concepts in computer architecture