- Learning Scala Programming
- Vikash Sharma
- 187字
- 2021-06-30 19:07:45
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.
- Practical Data Analysis Cookbook
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- Node.js Design Patterns
- ThinkPHP 5實戰
- Mastering Entity Framework
- Python爬蟲開發與項目實戰
- Internet of Things with the Arduino Yún
- Scratch真好玩:教小孩學編程
- Ext JS 4 Web Application Development Cookbook
- 名師講壇:Spring實戰開發(Redis+SpringDataJPA+SpringMVC+SpringSecurity)
- Mastering Data Mining with Python:Find patterns hidden in your data
- 小程序,巧應用:微信小程序開發實戰(第2版)
- 詳解MATLAB圖形繪制技術
- JSP程序設計實例教程(第2版)
- 從零開始學UI:概念解析、實戰提高、突破規則