Monday, May 11, 2020
Kotlin vs Java continued
Sunday, May 10, 2020
Kotlin vs Java continued
Saturday, May 9, 2020
Kotlin versus Java continued...
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
Thursday, May 7, 2020
Kotlin vs Java continued
Wednesday, May 6, 2020
Tuesday, May 5, 2020
There were a few requirements of invoking JavaScript in languages like Kotlin that doesn’t change. These include:
Specifying keywords to denote external code implementation in JavaScript
Allowing inheritance and static membership.
Ability to proxy and extend the implementation with extension classes by giving it the same level of representation as first class citizens of Kotlin.
Ability to bridge the programming paradigm of Javascript with the functional languages. For example, Kotlin does not support dynamic types when targeting ‘jvm’ plugin type
Ability to perform code access security when running in server mode
Ability to maintain strict level for JavaScript consistency and canonicalization of logic expressed in JavaScript
Support for the numerous frameworks and plug-ins that JavaScript comes with. For example, Json with padding provides a method to request data from a server in a different domain. This was previously prohibhited to ensure same origin policy but has since been addressed with Cross-Origin resource sharing (CORS). This way JsonP helps with script element injection or reuse of an existing one. CORS may improve security but JsonP improves functionality providing different purposes and need to run with the language support.
JavaScript dependencies are managed by npm which is a public repository with tools to download the packages. Kotlin allows us to declare these dependencies in the build script and leverages the Yarn package manager to download the packages. It also generates a webpack module bundler configuration for browser targets. Directories can be distributed by specifying it in the build script.
When JavaScript is called from Kotlin function, it can be inlined with the js(…) function. Other than that, all member functions, optional parameters, classes and interfaces can be written in pure JavaScript and marked with the external modifier. The compiler skips these declarations for generating JavaScript code and the onus on the developer to provide the necessary implementation.
JavaScript does not have the concept of interfaces. Instead JavaScript objects with those methods are passed to the code. A good example for the application of this pattern is the settings object.
The reverse is also made popular with Kotlin being called from JavaScript. For this purpose, Kotlin creates an object that contains all the declarations from the current module
Monday, May 4, 2020
One of the best advantages of using Kotlin code is its ability to invoke JavaScript consider the equivalence in ASP. NET programming where the server side could invoke JavaScript. Theree were limitations to what the server could execute that the client cannot but overall the facility was widely appreciated because it gave the convenience of not being limited by resources. The server side was always heavy duty and had better hooks than client side. The server side also provided the ability to run custom controls and the ability to allow seamless debugging.
There were a few requirements of invoking JavaScript in languages like Kotlin that doesn’t change. These include:
Specifying keywords to denote external code implementation in JavaScript
Allowing inheritance and static membership.
Ability to proxy and extend the implementation with extension classes by giving it the same level of representation as first class citizens of Kotlin.
Ability to bridge the programming paradigm of Javascript with the functional languages. For example, Kotlin does not support dynamic types when targeting ‘jvm’ plugin type
Ability to perform code access security when running in server mode
Ability to maintain strict level for JavaScript consistency and canonicalization of logic expressed in JavaScript
Support for the numerous frameworks and plug-ins that JavaScript comes with. For example, Json with padding provides a method to request data from a server in a different domain. This was previously prohibhited to ensure same origin policy but has since been addressed with Cross-Origin resource sharing (CORS). This way JsonP helps with script element injection or reuse of an existing one. CORS may improve security but JsonP improves functionality providing different purposes and need to run with the language support.