markdown kotlin_tips_part1.md
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown kotlin_tips_part1.md相关的知识,希望对你有一定的参考价值。
Which is a new programming language that is a pragmatic, safe,concise, and interoperable alternative to Java.With Kotlin, you can implement your projects with less code, a higher level of abstraction, and fewer annoyances
Kotlin is concise, safe, pragmatic, and focused on interoperability with Java code. It can be used almost everywhere Java is used today - for **server-side development,Android apps, and much more.** Kotlin works great with all existing Java libraries and frameworks and runs with the same level of performance as Java.
This allows for shorter code and greater flexibility in creating data structures.*But the downside is that problems like misspelled names can’t be detected during compilation and lead to runtime errors.*
The ability of the compiler to determine types from context is called **type inference**.
**Performance** - Calling methods is faster because there’s no need to figure out at runtime which method needs to be called.
**Maintainability**-Working with unfamiliar code is easier because you can see what kind of objects the code is working with.
The most important of those is Kotlin’s support for **nullable types**.Which lets you write more reliable programs by detecting possible null pointer exceptions at compile time.
Kotline is **functional programming language**.
**First-class function**: You work with functions as values. You can store them in variables,pass them as parameters, or return them from other function.
**Immutability**: You work with the immutbale objects, which guarantees that there state can't change after their creation.
**No side effects**: You use pure functions that return the same result given the same inputs and don't modify the state of other object or interact with outside world.
What benefits can you gain from writing the code in the function style?
1.**Conciessness**: Working with functions as value gives you much more power of abstraction, which lets you avoid duplication in your code. Imagine that you have two similar code fragment that implement similar task but different in details. You can easily extract the common part of logic into a function and pass the differing parts as parameters. Those parameters are themselves functions but you can express them using a concise syntax for functions called lambda expressions:
fun findAlice() = findPerson{ it.name= 'Alice' }
fun findBob() = findperson{ it.name='Bob'}
2.**Safe Multithreading**:One of biggest sources of errors in multithreaded programs is modification of same data from multiple threads without proper synchronization. If you use pure function and immutable data structure, you can sure that such unsafe modifications won't happen.
3.**Easier Testing**: Code without side effects is usually easer to test. Functions can be tested in isolation without requiring a lot of setup cpde
以上是关于markdown kotlin_tips_part1.md的主要内容,如果未能解决你的问题,请参考以下文章