Skip to content

Commit

Permalink
Improve Koltin background + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
francescoo22 committed Jul 17, 2024
1 parent fa5a0d7 commit 0e189f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
20 changes: 9 additions & 11 deletions chapters/2-Background.typ
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,26 @@
= Background

// TODO: symbols for code that compiles vs code that doesn't?
// TODO: cite language specification

== Kotlin

// TODO: scriverlo per davvero AIG
Developed by JetBrains, Kotlin @Kotlin is an open-source, statically typed programming language that gained popularity in recent years especially in the Android software development field. Kotlin shares many similarities with Java and can fully interoperate with it. Notably, Kotlin also introduces several features that are absent in Java, such as improved type inference, functional programming, null-safety, and smart-casting.

Kotlin @Kotlin is a statically-typed, versatile programming language that was developed by JetBrains in 2011. Built with the aim to enhance productivity and satisfaction of developers, it offers a unique blend of object-oriented and functional programming features capable of gracing any application with simplicity, clarity, and excellent interoperability. Kotlin is primarily used for Android app development and is officially recommended by Google. Its efficiency, conciseness, and safety to prevent common programming errors make it a rather compelling choice for developers worldwide.

Only Kotlin's features that are relevant for this work will be discussed in detail.
The following sections will present the features of the language that are more relevant for this work.

=== Mutable vs Immutable Variables

// AIG
// TODO sistema i blocchi di codice che vanno a capo
In programming languages, mutability refers to the capability to alter the value of a variable after it has been initialized. Variables in Kotlin are either mutable, defined using the `var` keyword, or immutable, defined using the `val` keyword. Mutable variables, once assigned, can have their value changed during the execution of the program, while immutable variables, once assigned a value, cannot be altered subsequently. For instance, `var x = 5` allows you to change the value of `x` later in the program, while `val y = 5` maintains `y` at a value of 5 throughout the program. Mutability is a fundamental principle in programming, and Kotlin's clear distinction between `val` and `var` improves code readability and helps in maintaining data consistency, especially in a multithreaded environment.

In Kotlin, mutability refers to the capability to alter the value of a variable after it has been initialized. Variables in Kotlin are either mutable, defined using the `var` keyword, or immutable, defined using the `val` keyword. Mutable variables, once assigned, can have their value changed during the execution of the program, while immutable variables, once assigned a value, cannot be altered subsequently. For instance, `var x = 5` allows you to change the value of x later in the program, while `val y = 5` maintains y at a value of 5 throughout the program. Mutability is a fundamental principle in programming, and Kotlin's clear distinction between `val` and `var` enhances code readability and aids in maintaining data consistency, especially in a multithreaded environment.
=== Functional Programming?

=== Smart Casts

// AIG un po' rivisto

In Kotlin, smart casts refer to a feature of the language that automatically handles explicit typecasting, reducing the need for manual intervention. A smart cast occurs when the compiler tracks conditions inside conditional expressions and automatically casts types if possible, eliminating the necessity for explicit casting in many scenarios. This considerably simplifies the syntax and increases readability. For example, if we perform a type check on a variable in an `if` condition, we can use that variable in its checked type within the `if` block without the requirement to explicitly cast it. An example of smart cast can be found in @smart-cast
In Kotlin, smart casts refer to a feature of the language that automatically handles explicit typecasting, reducing the need for manual intervention. A smart cast occurs when the compiler tracks conditions inside conditional expressions and automatically casts types if possible, eliminating the necessity for explicit casting in many scenarios. This considerably simplifies the syntax and increases readability. For example, if we perform a type check on a variable in an `if` condition, we can use that variable in its checked type within the `if` block without the requirement to explicitly cast it. An example of smart cast can be found in @smart-cast.

#figure(
caption: "",
caption: "Example of smart-cast in Kotlin",
```kt
open class A()
class B : A() {
Expand All @@ -45,6 +41,8 @@ In Kotlin, smart casts refer to a feature of the language that automatically han

=== Null Safety

*TODO*

=== Contracts

Kotlin contracts are an experimental feature introduced in Kotlin 1.3 designed to provide additional guarantees about code behavior, helping the compiler in performing more precise analysis and optimizations. Contracts are defined using a special contract block within a function, describing the relationship between input parameters and the function's effects. This can include conditions such as whether a lambda is invoked or if a function returns under certain conditions. By specifying these relationships, contracts help the compiler understand the function's logic more deeply, enabling advanced features like smart casting and better null-safety checks.
Expand Down
4 changes: 4 additions & 0 deletions preface/firstpage.typ
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#align(left, text(12pt, weight: 400, style: "italic", supervisor))
#v(5pt)
#align(left, text(11pt, profTitle + myProf))
#v(10pt)
#align(left, text(12pt, weight: 400, style: "italic", "Tutors"))
#v(5pt)
#align(left, text(11pt, "Ilya Chernikov, Komi Golov"))

#align(right, text(12pt, weight: 400, style: "italic", undergraduate))
#v(5pt)
Expand Down
17 changes: 8 additions & 9 deletions preface/table-of-contents.typ
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
target: figure.where(kind: image)
)

#v(8em)

#outline(
title: tablesList,
target: figure.where(kind: table),
indent: auto
)

// TODO: decide whether to include listings here, along figures or not to include them at all
// TODO: show if there will be tables
// #v(8em)

// #outline(
// title: tablesList,
// target: figure.where(kind: table),
// indent: auto
// )

#v(8em)

Expand Down

0 comments on commit 0e189f0

Please sign in to comment.