Skip to content

Commit 96670b1

Browse files
author
Dean Wampler
committed
Refreshed the README
1 parent 1f25ad2 commit 96670b1

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

README.md

+37-29
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424
| February 21, 2021 | Scala `3.0.0-RC1` updates |
2525
| April 3, 2021 | Scala `3.0.0-RC2` updates |
2626
| April 24, 2021 | Scala `3.0.0-RC3` updates |
27+
| May 15, 2021 | Scala `3.0.0` final updates. Almost done! |
2728

2829
[![Join the chat at https://gitter.im/deanwampler/programming-scala-book-code-examples](https://badges.gitter.im/deanwampler/programming-scala-book-code-examples.svg)](https://gitter.im/deanwampler/programming-scala-book-code-examples?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2930

30-
This repo contains all the code examples to be included in [Programming Scala, Third Edition](http://programming-scala.org). (The second edition is [available here](http://shop.oreilly.com/product/0636920033073.do).) There are also many code files in this distribution that aren't included in the book.
31+
This repo contains all the code examples in [Programming Scala, Third Edition](http://programming-scala.org). (The second edition is [available here](http://shop.oreilly.com/product/0636920033073.do).) There are also many code files in this distribution that aren't included in the book.
3132

32-
When the second edition was published, the examples used Scala 2.11. The code has since been updated to also compile with Scala 2.12 and 2.13. Many examples are being improved, in part so they compile with newer library versions and with the stricter compiler flags now used. (ScalaTest, in particular, has changed a lot since the second edition.)
33-
34-
If you want the example code for the second edition (with some bug fixes and Scala 2.12-2.13 support), [download the tagged 2.1.0](https://github.com/deanwampler/programming-scala-book-code-examples/releases/tag/2.1.0) build or check out the `release-2.1.0` branch. The latest `2.X.Y` release and `release-2.X.Y` branch include all the updates for 2.12 and 2.13. (No more `release-2.X.Y` releases are planned.) The third edition code for Scala 3 will be tagged with `release-3.0.0-XYZ`, with `XYZ` starting at `001` until the edition is published. Afterwards, `release-3.X.Y` will be used. These releases will be based off of `master`.
33+
The `master` branch and the `3.X.Y` tag releases are for the third edition. The code examples for the second edition are still available. [Download the release tagged 2.1.0](https://github.com/deanwampler/programming-scala-book-code-examples/releases/tag/2.1.0) or check out the `release-2.1.0` branch. While the second edition was published for 2.11. The latest `2.1.0` release and `release-2.1.0` are updated for 2.12 and 2.13. (No more `release-2.X.Y` releases are planned.)
3534

3635
## How the Code Is Used in the Book
3736

@@ -43,18 +42,18 @@ In the book's text, when an example corresponds to a file in this distribution,
4342

4443
Following the usual conventions, tests are in `src/test/...`.
4544

46-
Use these comments to find the corresponding source file. This archive also contains *MUnit* and *ScalaCheck* unit tests to validate some of the code. Most of these tests are not reproduced in the text of the book.
45+
Use these comments to find the corresponding source file. This archive also contains *MUnit* and *ScalaCheck* unit tests to validate some of the code.
4746

4847
## Naming Conventions
4948

50-
The examples include "scripts" that are run with the `scala` command-line "REPL" (read, eval, print loop) or using `sbt console`. Other files are compiled.
49+
The examples include "scripts" that are intended for interactive use in the `scala` command-line "REPL" (read, eval, print loop), for example using `sbt console` (where [`sbt`](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html) is the de facto build tool for Scala that I use). Other files are compiled.
5150

52-
To keep these different kinds of files straight and to support building with SBT, the following conventions are used for the files:
51+
To keep these different kinds of files straight and to support building with `sbt`, the following conventions are used for the files:
5352

54-
- `src/main/scala/.../*.scala` - All Scala 3 source files built with SBT.
55-
- `src/test/.../*.scala` - All Scala 3 test source files built and executed with SBT.
53+
- `src/main/scala/.../*.scala` - All Scala 3 source files built with `sbt`.
54+
- `src/test/.../*.scala` - All Scala 3 test source files built and executed with `sbt`.
5655
- `src/script/.../*.scala` - "Script" files that won't compile with `scalac`, but can be interpreted with the `scala` REPL or used as a worksheet (see below).
57-
- `src/*/scala-2/.../*.scala` - Some Scala 2 source files that won't compile with Scala 3. They are not built with SBT.
56+
- `src/*/scala-2/.../*.scala` - Some Scala 2 source files that won't compile with Scala 3. They are not built with `sbt`.
5857

5958
## Other Notes about the Code
6059

@@ -67,25 +66,25 @@ Some files have sections marked like this:
6766
// end::section1[]
6867
```
6968

70-
These are used to mark sections that are selectively included in the book. Sometimes the whole file is included in sections, while other times the file has content that isn't included ("Bonus!!").
69+
These are used to mark sections that are selectively included in the book. Sometimes the whole file is included in sections, while other times the file has extra bonus content that doesn't appear in the book.
7170

7271
## Required and Optional Tools
7372

74-
To build and run the examples, all you need is a recent version of the the JDK and [SBT](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html), the de-facto standard build tool for Scala. When you run SBT, it will bootstrap itself with the correct version of its jar file, Scala, and project dependencies, which are specified in the `build.sbt` file in the root directory and other build files in the `project` directory.
73+
To build and run the examples, all you need is a recent version of the the JDK and [`sbt`](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html). When you run `sbt`, it will bootstrap itself with the correct version of its jar file, Scala, and project dependencies, which are specified in the `build.sbt` file in the root directory and other build files in the `project` directory.
7574

76-
Follow these [installation instructions](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html).
75+
Follow these [`sbt` installation instructions](http://www.scala-sbt.org/release/docs/Getting-Started/Setup.html).
7776

78-
If you want to install Scala separately and Scala's *Scaladocs*, go to [scala-lang.org](http://scala-lang.org) for details. However, this isn't required.
77+
If you want to install Scala separately and Scala's *Scaladocs*, go to the [scala-lang.org _Getting Started_ guide](https://docs.scala-lang.org/scala3/getting-started.html) for details. However, this isn't required.
7978

80-
If you want to play with the Spark example, `src/script/scala-2/progscala3/bigdata/SparkWordCount.scala`, you'll need to download a Spark distribution from https://spark.apache.org and use a compatible version of Scala, 2.12 (at the time of this writing). With that version of Scala on your path and assuming that `$SPARK_HOME` refers to the root directory of your Spark installations, run the following command in the root directory of this project:
79+
If you want to play with the Spark example, `src/script/scala-2/progscala3/bigdata/SparkWordCount.scala`, you'll need to download a Spark distribution from https://spark.apache.org. Assuming that `$SPARK_HOME` refers to the root directory of your Spark installation, run the following command in the root directory of this project:
8180

8281
```
8382
$ $SPARK_HOME/bin/spark-shell
8483
...
8584
scala>
8685
```
8786

88-
Then paste the content of `SparkWordCount.scala` at the prompt. After it runs, there will be a new directory, `README.md.wordcount` with the _partition_ files of the output.
87+
Then copy and paste the content of `src/script/scala-2/progscala3/bigdata/SparkWordCount.scala` at the prompt. After it runs, there will be a new directory, `README.md.wordcount` with the _partition_ files of the output.
8988

9089
> **Tip:** For more on Spark, see my free tutorial on GitHub, [spark-scala-tutorial](https://github.com/deanwampler/spark-scala-tutorial).
9190
@@ -95,29 +94,29 @@ Then paste the content of `SparkWordCount.scala` at the prompt. After it runs, t
9594
9695
Most editors and IDEs now have some sort of Scala support:
9796

98-
* [IntelliJ](https://www.jetbrains.com/idea/): Either the Community or Ultimate additions will work. Install the Scala plugin, which has built-in support for SBT.
97+
* [IntelliJ](https://www.jetbrains.com/idea/): Either the Community or Ultimate additions will work. Install the Scala plugin, which has built-in support for `sbt`.
9998
* [Visual Studio Code](https://code.visualstudio.com/): Use the new [Scala Metals](https://scalameta.org/metals/) plugin instead of older plugins.
10099
* [Eclipse Scala IDE](http://scala-ide.org): Old, no longer recommended.
101100

102101
For other IDEs and text editors, try [Scala Metals](https://scalameta.org/metals/) first (I've used it with [Sublime Text](https://www.sublimetext.com/), for example) or the older [ENSIME](http://ensime.github.io/) project. You may also need additional, third-party tools for syntax highlighting, etc.
103102

104-
After installing the required plugins, load this project in your IDE, which should detect and use the SBT project automatically. For eclipse, run the `sbt eclipse` task to generate project files, then import them.
103+
After installing the required plugins, load this project in your IDE, which should detect and use the `sbt` project automatically. For eclipse, run the `sbt eclipse` task to generate project files, then import them.
105104

106105
### Using Scala Worksheets
107106

108-
If you like working with _Scala worksheets_ in your IDE or editor, you may be able to load any of the REPL "script" files under `src/script` as a worksheet. If your environment is more restrictive, for example about the extension used, then run the included `bash` script `./make-worksheets.sh` to copy all the REPL "script" examples to worksheet files. This command copies the tree `src/script` to `src/worksheet` and changes the `.scala` extension for all the files to `.worksheet.sc`, the VSCode convention. These behaviors are configurable. Use the `--help` option to see the details. If you are using Windows and you don't have `bash` available, e.g., through the Linux subsystem, then modify individual files as you see fit.
107+
If you like working with _Scala worksheets_ in your IDE or editor, you may be able to load any of the REPL "script" files under `src/script` as a worksheet. If your environment is more restrictive, for example about the file extension used, then run the included `bash` script `./make-worksheets.sh` to copy all the REPL "script" examples to worksheet files. This command copies the tree `src/script` to `src/worksheet` and changes the `.scala` extension for all the files to `.worksheet.sc`, the VSCode convention. These behaviors are configurable. Use the `--help` option to see the details. If you are using Windows and you don't have `bash` available, e.g., through the Linux subsystem, then modify individual files as you see fit.
109108

110109
See this [Dotty documentation page](https://dotty.epfl.ch/docs/usage/worksheet-mode.html) for more information about worksheets.
111110

112111
## Building the Code Examples
113112

114-
After installing SBT, open a command/terminal window and run the `sbt test` command.
113+
After installing `sbt`, open a command/terminal window and run the `sbt test` command.
115114

116115
You'll see lots of output as it downloads all the dependencies, compiles the code and runs the tests. You should see `[success]` messages at the end.
117116

118-
SBT is discussed in more detail in the book and the [SBT website](https://www.scala-sbt.org/), but a few useful commands are worth mentioning here.
117+
`sbt` is discussed in more detail in the book and the [`sbt` website](https://www.scala-sbt.org/), but a few useful commands are worth mentioning here.
119118

120-
If you start `sbt` without any arguments, it puts you into an interactive mode where you can type commands. Use control-D to exit this mode. Once at the SBT prompt (`sbt:programming-scala-3rd-ed-code-examples>`), try the following commands, where each `#` starts a comment; don't type those!
119+
If you start `sbt` without any arguments, it puts you into an interactive mode where you can type commands. Use control-D to exit this mode. Once at the `sbt` prompt (`sbt:programming-scala-3rd-ed-code-examples>`), try the following commands, where each `#` starts a comment; don't type those!
121120

122121
```
123122
help # help on tasks and settings
@@ -132,20 +131,29 @@ tasks -V # REALLY show ALL tasks
132131

133132
The `~` prefix causes the task to be run continuously each time source code changes are saved. This promotes continuous TDD (test-driven development) and is one of my favorite features!
134133

135-
Outside of SBT, you could, in principle, run the script files manually at the console/terminal prompt.
134+
Outside of `sbt`, you could, in principle, run the REPL and load the script files manually at the prompt:
136135

137136
```
138-
scala src/script/scala/.../Foo.scala
137+
$ scala
138+
scala> :load src/script/scala/.../Foo.scala
139139
```
140140

141-
However, _at the time of this writing_, the `scala` REPL for the preview versions of Scala 3 do not support loading script files like this. Hopefully the final version of Scala 3 will restore this ability. Actually, it's easier to run many of the scripts using the SBT `console` task, at least those that use libraries or other compiled code that SBT has on the `CLASSPATH` already. Use the REPL's `:load src/script/scala/.../Foo.scala` feature to load and run a script file. You can also work with these files as Scala worksheets, as discussed above.
141+
However, it's easier to run most of the scripts using `sbt console`, because `sbt` will configure the `CLASSPATH` with the third-party libraries and compiled code examples that a script file might use.
142+
143+
Also, new for the Scala 3 REPL, for those `src/main/...` files that define one (and only one) _entry point_, meaning a `main` method (Scala 2 compatible) or annotated with `@main` (new Scala 3 technique), you can compile and run them in one step:
144+
145+
```
146+
$ scala src/main/scala/progscala3/introscala/UpperMain2.scala Hello World!
147+
HELLO WORLD!
148+
$
149+
```
142150

143151
## Feedback
144152

145153
I welcome feedback on the Book and these examples. Please post comments, corrections, etc. to one of the following places:
146154

147-
* This GitHub repo's [Gitter channel](https://gitter.im/deanwampler/programming-scala-book-code-examples), [Discussion forum](https://github.com/deanwampler/programming-scala-book-code-examples/discussions), or [Issues](https://github.com/deanwampler/programming-scala-book-code-examples/issues)
148-
* The book's Twitter account, [@ProgScala](https://twitter.com/ProgScala)
149-
* The O'Reilly book and errata sites, after publication.
155+
* This GitHub repo's [Gitter channel](https://gitter.im/deanwampler/programming-scala-book-code-examples), [Discussion forum](https://github.com/deanwampler/programming-scala-book-code-examples/discussions), or [Issues](https://github.com/deanwampler/programming-scala-book-code-examples/issues).
156+
* The book's Twitter account, [@ProgScala](https://twitter.com/ProgScala).
157+
* The O'Reilly book and errata sites (coming soon).
150158

151-
There is also a dedicated site for the book where occasional updates, clarifications, corrections, and lame excuses will be posted: [programming-scala.org](http://programming-scala.org).
159+
There is also my dedicated site for the book where occasional updates, clarifications, corrections, and lame excuses will be posted: [programming-scala.org](http://programming-scala.org).

0 commit comments

Comments
 (0)