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

Shaping our Scala Program

"I conclude that there are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult."
- C. A. R. Hoare

A program is a solution specific to a problem. The solution we write is broken down to different tasks. Tasks can be specific to a step or a part of the solution. While coding for such tasks, we use constructs as tools to make them easier, readable, and performant. These tools make it possible to shape up your program at hand.

To code for a task that is repetitive requires either a construct that can repeat a given logic for you, or write the same snippet of code by hand again and again. I bet the first one is far better and that's why we have a few constructs, we call them looping constructs. Scala supports for, while, and do while loops. We'll see how these loops work in Scala. From there, we'll have a quick look at for expressions. We'll also go through the FP (functional programming) way of doing loops through recursion. Then, we'll start taking a look at Scala's conditional statements if and end, with learning how we can shape up program flow using pattern matching. Here's a quick card for what's in there for us in this chapter:

  • Looping
    • for, while, and do while loops
  • The for expressions: a quick go-through
  • Recursion
  • Conditional statements
    • if, and if else
  • Pattern matching
主站蜘蛛池模板: 疏附县| 康马县| 普兰县| 教育| 南皮县| 双城市| 喀喇沁旗| 顺义区| 宜宾市| 鄂州市| 昌图县| 萨迦县| 隆安县| 晋城| 白河县| 九台市| 云浮市| 镇雄县| 中西区| 库伦旗| 岱山县| 鹤峰县| 锦屏县| 津南区| 西贡区| 搜索| 温宿县| 荃湾区| 南岸区| 余干县| 闻喜县| 额尔古纳市| 化德县| 秦皇岛市| 图木舒克市| 错那县| 竹山县| 垣曲县| 阳山县| 新营市| 天长市|