Global variables are an example of shared state but they bring about unintended concurrency runtime. Kotlin mitigates that by allowing global variables to be accessible only from main thread unless otherwise specified, allowing thread local storage and shared immutability. These enable race free programming. The freeze function enables immutability of object subgraph. Primitive references like AtomicInt and Atomic Reference are frozen by default.
The checks for mutability involve immutability check as well as whether the object is mutable from a single thread. This is referred to as “mutable xor global” check. The freezing helps with the immutability while the thread local storage helps with mutability that is hidden from others.
The native library is produced from Kotlin by specifying a parameter to the compiler.
There are also tools, aside from the compiler Kotlinc, such as Cinterop which produces klib wrappers for native libraries. The klib tool allows us to inspect and install these libraries the Kotlin native libraries are an archive file of predefined directory structure. Some libraries have proper module.Map file that describe the relation between header file and modules
Kotlin has a wide variety of tools available.
These tools are available from gradle, maven, ant, compiler opts, plug-ins, Kapt, Dokka and Osgi. These toolsand their plug-ins help Kotlin support multiple languages.
The plugins can also be extracted during compilation rather than require pre-installation. It might look like the traditional apply() method in gradle is no different from the plugins block and that they both serve to list plugins and their versions but the latter is actually more recent, has more rigorous checks, constraints and restrictions. If we want to avoid the restrictions, we could make use of the buildScript block. Gradle has support for multi-project builds so the build.gradle is composable for different projects
No comments:
Post a Comment