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

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
主站蜘蛛池模板: 河源市| 偏关县| 贵州省| 云霄县| 文化| 随州市| 临邑县| 竹北市| 汉源县| 乌兰察布市| 枞阳县| 瓮安县| 萝北县| 遂平县| 策勒县| 余姚市| 边坝县| 廊坊市| 闻喜县| 安仁县| 合阳县| 托克托县| 峨眉山市| 丽水市| 南部县| 勃利县| 边坝县| 内江市| 西平县| 潞西市| 如东县| 石首市| 苍南县| 广昌县| 玛曲县| 吴旗县| 杭州市| 固原市| 开远市| 合江县| 湖南省|