-
Notifications
You must be signed in to change notification settings - Fork 1k
Suggestions on the Scala 3 book (part 5) #2088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
julienrf
merged 1 commit into
scala:main
from
scalacenter:scala3-book-suggestions-part5
Jun 28, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ Also at a high level, the differences between Java and Scala are: | |
- Scala has a full suite of immutable collections, including `List`, `Vector`, and immutable `Map` and `Set` implementations | ||
- Everything in Scala is an _expression_: constructs like `if` statements, `for` loops, `match` expressions, and even `try`/`catch` expressions all have return values | ||
- Scala idioms favor immutability by default: you’re encouraged to use immutable (`final`) variables and immutable collections | ||
- Idiomatic Scala code does not use `null`, and thus does not suffer from `NullPointerException` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the comma is not necessary |
||
- The Scala ecosystem has other [build tools][tools] in sbt, Mill, and others | ||
- In addition to running on the JVM, the [Scala.js](https://www.scala-js.org) project lets you use Scala as a JavaScript replacement | ||
- The [Scala Native](http://www.scala-native.org) project adds low-level constructs to let you write “systems” level code, and also compiles to native executables | ||
|
@@ -117,14 +118,18 @@ This section provides comparisons of features related to OOP-style classes and m | |
|
||
### OOP style class, primary constructor: | ||
|
||
Scala doesn’t follow the JavaBeans standard, so instead of showing Java | ||
code written in the JavaBeans style, here we show Java code that is | ||
equivalent to the Scala code that follows it. | ||
|
||
<table> | ||
<tbody> | ||
<tr> | ||
<td class="java-block"> | ||
<code>class Person { | ||
<br> private String firstName; | ||
<br> private String lastName; | ||
<br> private int age; | ||
<br> public String firstName; | ||
<br> public String lastName; | ||
<br> public int age; | ||
julienrf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<br> public Person( | ||
<br> String firstName, | ||
<br> String lastName, int age | ||
|
@@ -160,9 +165,9 @@ This section provides comparisons of features related to OOP-style classes and m | |
<tr> | ||
<td class="java-block"> | ||
<code>public class Person { | ||
<br> private String firstName; | ||
<br> private String lastName; | ||
<br> private int age; | ||
<br> public String firstName; | ||
<br> public String lastName; | ||
<br> public int age; | ||
<br> | ||
<br> // primary constructor | ||
<br> public Person( | ||
|
@@ -424,7 +429,7 @@ This section compares Java interfaces to Scala traits, including how classes ext | |
<tbody> | ||
<tr> | ||
<td class="java-block"> | ||
<code>class Dog extends Animal, HasLegs, HasTail</code> | ||
<code>class Dog extends Animal implements HasLegs, HasTail</code> | ||
</td> | ||
</tr> | ||
<tr> | ||
|
@@ -976,7 +981,7 @@ val a = Array("a", "b") | |
as being backed by this Java `String[]`: | ||
|
||
```scala | ||
String[] a = ["a", "b"] | ||
String[] a = ["a", "b"]; | ||
``` | ||
|
||
However, a Scala `Array` also has all of the functional methods you expect in a Scala collection, including `map` and `filter`: | ||
|
@@ -1275,7 +1280,7 @@ For more information on dealing with errors and exceptions in Scala, see the [Fu | |
|
||
That concludes are comparison of the Java and Scala languages. | ||
|
||
Currently there are other concepts in Scala which currently have no equal in Java 11. | ||
There are other concepts in Scala which currently have no equal in Java 11. | ||
This includes: | ||
|
||
- Everything related to Scala’s [contextual abstractions][contextual] | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is important to not say things like “we run a
Future
” because that maintains a confusion on the purpose ofFuture
(which only holds a future result, unlike a “task”, which is a computation that we can run, cancel, etc.)