官术网_书友最值得收藏!

Super smart syntax

You are going to write succinct code with Scala. There are a lot of examples we can look at to see Scala's syntax conciseness. Let's take an example from Scala's rich collections and create a Map:

val words = Map ("Wisdom" -> "state of being wise")
println(words("Wisdom"))

> state of being wise

The preceding code is creating a map of words and their meaning. Only Map ("Wisdom" -> "state of being wise") is the amount of code we have to write to make it possible. No need to add semicolons. We did not even mention the type of our value and the Scala compiler was able to infer it. Type inference is a characteristic of this language. Because of Type inference, a lot of times we omit type declaration and use a value directly. This way, using only a minimal set of words/tokens you can express the logic to implement them. Constructs like case classes and pattern matching take away the extra effort one might have to make and makes writing code joyful. It also helps you reduce written code by a good margin.

主站蜘蛛池模板: 通道| 宜君县| 廊坊市| 遂昌县| 武穴市| 敦化市| 湖州市| 灯塔市| 布尔津县| 栖霞市| 剑阁县| 治多县| 张家口市| 安庆市| 通山县| 临沭县| 新安县| 宁波市| 泸定县| 台江县| 阿荣旗| 哈尔滨市| 玛沁县| 克什克腾旗| 青田县| 电白县| 车致| 青州市| 牙克石市| 鲁甸县| 茌平县| 集贤县| 历史| 格尔木市| 石嘴山市| 株洲县| 黄冈市| 鹤庆县| 娱乐| 儋州市| 鄯善县|