Content deleted Content added
→Design: extensive support for both object-oriented and functional programming is another big similarity with Scala |
→Design: Kotlin is similar to Scala in function parameter features as well |
||
Line 126:
Kotlin [[Variable (computer science)|variable]] declarations and [[Parameter (computer programming)|parameter lists]] have the [[data type]] come after the variable name (and with a [[Colon (punctuation)|colon]] separator), similar to [[Ada (programming language)|Ada]], [[BASIC]], [[Pascal (programming language)|Pascal]], [[TypeScript]] and [[Rust (programming language)|Rust]]. This, according to an article from Roman Elizarov, current project lead, results in alignment of variable names and is more pleasing to eyes, especially when there are a few variable declarations in succession, and one or more of the types is too complex for type inference, or needs to be declared explicitly for human readers to understand.<ref>{{cite web|title=Types are moving to the right|url=https://elizarov.medium.com/types-are-moving-to-the-right-22c0ef31dd4a#:~:text=Woot!%20That%E2%80%99s%20nice%20and%20aligns,%20pleasure%20for%20our%20eyes%20to%20see.|website=Medium|date=16 July 2020|access-date=6 November 2021|archive-date=22 May 2023|archive-url=https://web.archive.org/web/20230522024640/https://elizarov.medium.com/types-are-moving-to-the-right-22c0ef31dd4a#:~:text=Woot!%20That%E2%80%99s%20nice%20and%20aligns,%20pleasure%20for%20our%20eyes%20to%20see.|url-status=live}}</ref><ref>{{cite web|title=Roman Elizarov is the new Project Lead for Kotlin|url=https://blog.jetbrains.com/kotlin/2020/11/roman-elizarov-is-the-new-project-lead-for-kotlin/|website=The Kotlin Blog|date=19 November 2020|publisher=JetBrains|access-date=7 November 2021|archive-date=20 January 2022|archive-url=https://web.archive.org/web/20220120205530/https://blog.jetbrains.com/kotlin/2020/11/roman-elizarov-is-the-new-project-lead-for-kotlin/|url-status=live}}</ref>
The influence of [[Scala (programming language)|Scala]] in Kotlin can be seen in the extensive support for both object-oriented and functional programming.<ref>{{cite web |url=https://confluence.jetbrains.com/display/Kotlin/Functions |title=functions |website=jetbrains.com |access-date=8 February 2014 |archive-date=23 November 2015 |archive-url=https://web.archive.org/web/20151123112725/https://confluence.jetbrains.com/display/Kotlin/Functions |url-status=live}}</ref>a number of other features:
* there is a distinction between [[Immutable object|mutable and immutable]] variables (''var'' vs ''val'' keyword), and
* all classes are public and final (non-inheritable) by default.
* functions and methods support [[default argument]]s, [[variadic function|variable-length argument]] lists and [[Named parameter|named argument]]s
Kotlin 1.3 added support for contracts,<ref>{{Cite web|url=https://kotlinlang.org/docs/reference/whatsnew13.html|title=What's New in Kotlin 1.3 - Kotlin Programming Language|website=Kotlin|access-date=4 April 2020|archive-date=22 August 2023|archive-url=https://web.archive.org/web/20230822164600/https://kotlinlang.org/docs/reference/whatsnew13.html|url-status=live}}</ref> which are stable for the standard library declarations, but still experimental for user-defined declarations. Contracts are inspired by [[Eiffel (programming language)|Eiffel's]] [[design by contract]]<ref>{{Cite web|url=https://discuss.kotlinlang.org/t/design-by-contract-dbc-design-considerations/1321|title=Design by Contract (DbC) design considerations|quote=Implement the full semantics of Eiffel DbC and improve upon it.|date=16 August 2012|website=Kotlin Discussions|language=en-US|access-date=4 April 2020|archive-date=5 April 2023|archive-url=https://web.archive.org/web/20230405081654/https://discuss.kotlinlang.org/t/design-by-contract-dbc-design-considerations/1321|url-status=live}}</ref> programming paradigm.
|