Skip to content

Commit 5a7b431

Browse files
TazzleSethTisue
authored andcommitted
Grammar and wording changes to 'Basics' page. (#1579)
* Add colon before list * Change ordered list to unordered list as items do not represent a sequence or hierarchy * Change 'either' to 'whichever' * Capitalise first letter of item in a list * Add 'by' to clarifymeaning * Add colon before a list * Add missing word, and add a comma and a 'for' for clarity * Change html lists to markdown for consistency with other lists * Change 'set up' verb to 'setup' adjective * Change 'smoothly' integrates to 'seamlessly' integrates, as 'seamlessly' is more commonly used to express integration. * Flesh out the word 'that', to provide more clarity * Change 'behavior' to 'behaviors' for clarity, as it may seem like all objects have one behaviour, instead of each object having its own behaviour * Change sentence slightly to clarify that subclassing and mixins are two separate options * Add it for consistency with the rest of the list * Add missing word * Capitalise first letter of items in a list * Change use of 'easy' and 'smoothly' to 'straightforward', as these two words may be an expert's subjective opinion * Change 'smooth' to 'seamless' * Change 'close' to 'closely', as 'close' relates to location in physical space. Add 'as reasonably possible' to have a shorter sentence while retaining same meaning. * Change grammar; should be 'as' instead of 'with' * Remove reference to contents menu to prevent information overload; there is a link to the next page within the sentence, and again directly below the sentence * Add a colon directly preceding a list * Remove unnecessary comma from list item * Add missing word * Add a colon before a list * Change words to increase clarity * Rearrange wording to increase clarity. Italicise 'ScalaFiddle' * Italicise 'ScalaFiddle'. Reorganise sentences to group similar information together * Add a colon when introducing a code example * Add words for clarity and consistency * Add more clarity around type inference * Add more clarity around type inference * Update description of scala functions. * Add clarity to anonymous function description * Change 'parameter' to 'argument' * Change 'parameter' to 'argument' * Add parenthesis around 's' to clarify that multiple parameter lists are not a rule * Remove redundancy of having the word 'colon' followed by the colon punctuation mark * Clarify the description of 'Unit' * Flesh out the definition of case classes * Add missing word * Add clarity to case class comparison * Add missing word * Flesh out the description of traits for clarity * Clarify the definition of a main method * Tidy up: add commas and clarifications * Remove contractions * Make changes requested in PR comments
1 parent 6d03862 commit 5a7b431

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

_tour/basics.md

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@ previous-page: tour-of-scala
1010
redirect_from: "/tutorials/tour/basics.html"
1111
---
1212

13-
In this page, we will cover basics of Scala.
13+
In this page, we will cover the basics of Scala.
1414

1515
## Trying Scala in the Browser
1616

17-
You can run Scala in your browser with ScalaFiddle.
17+
You can run Scala in your browser with _ScalaFiddle_. This is an easy, zero-setup way to experiment with pieces of Scala code:
1818

1919
1. Go to [https://scalafiddle.io](https://scalafiddle.io).
2020
2. Paste `println("Hello, world!")` in the left pane.
21-
3. Hit "Run" button. Output appears in the right pane.
21+
3. Click __Run__. The output appears in the right pane.
2222

23-
This is an easy, zero-setup way to experiment with pieces of Scala code.
24-
25-
Many of the code examples in this documentation are also integrated with ScalaFiddle, so you
26-
can directly experiment with them simply by clicking the Run-button.
23+
_ScalaFiddle_ is integrated with some of the code examples in this documentation; if you see a __Run__ button in a code example below, click it to directly experiment with the code.
2724

2825
## Expressions
2926

30-
Expressions are computable statements.
27+
Expressions are computable statements:
3128
```
3229
1 + 1
3330
```
34-
You can output results of expressions using `println`.
31+
You can output the results of expressions using `println`:
3532

3633
{% scalafiddle %}
3734
```tut
@@ -44,7 +41,7 @@ println("Hello," + " world!") // Hello, world!
4441

4542
### Values
4643

47-
You can name results of expressions with the `val` keyword.
44+
You can name the results of expressions using the `val` keyword:
4845

4946
```tut
5047
val x = 1 + 1
@@ -54,13 +51,13 @@ println(x) // 2
5451
Named results, such as `x` here, are called values. Referencing
5552
a value does not re-compute it.
5653

57-
Values cannot be re-assigned.
54+
Values cannot be re-assigned:
5855

5956
```tut:fail
6057
x = 3 // This does not compile.
6158
```
6259

63-
Types of values can be inferred, but you can also explicitly state the type, like this:
60+
The type of a value can be omitted and [inferred](https://docs.scala-lang.org/tour/type-inference.html), or it can be explicitly stated:
6461

6562
```tut
6663
val x: Int = 1 + 1
@@ -78,7 +75,7 @@ x = 3 // This compiles because "x" is declared with the "var" keyword.
7875
println(x * x) // 9
7976
```
8077

81-
As with values, you can explicitly state the type if you want:
78+
As with values, the type of a variable can be omitted and [inferred](https://docs.scala-lang.org/tour/type-inference.html), or it can be explicitly stated:
8279

8380
```tut
8481
var x: Int = 1 + 1
@@ -89,7 +86,7 @@ var x: Int = 1 + 1
8986

9087
You can combine expressions by surrounding them with `{}`. We call this a block.
9188

92-
The result of the last expression in the block is the result of the overall block, too.
89+
The result of the last expression in the block is the result of the overall block, too:
9390

9491
```tut
9592
println({
@@ -100,17 +97,17 @@ println({
10097

10198
## Functions
10299

103-
Functions are expressions that take parameters.
100+
Functions are expressions that have parameters, and take arguments.
104101

105-
You can define an anonymous function (i.e. no name) that returns a given integer plus one:
102+
You can define an anonymous function (i.e., a function that has no name) that returns a given integer plus one:
106103

107104
```tut
108105
(x: Int) => x + 1
109106
```
110107

111108
On the left of `=>` is a list of parameters. On the right is an expression involving the parameters.
112109

113-
You can also name functions.
110+
You can also name functions:
114111

115112
{% scalafiddle %}
116113
```tut
@@ -119,7 +116,7 @@ println(addOne(1)) // 2
119116
```
120117
{% endscalafiddle %}
121118

122-
Functions may take multiple parameters.
119+
A function can have multiple parameters:
123120

124121
{% scalafiddle %}
125122
```tut
@@ -128,7 +125,7 @@ println(add(1, 2)) // 3
128125
```
129126
{% endscalafiddle %}
130127

131-
Or it can take no parameters.
128+
Or it can have no parameters at all:
132129

133130
```tut
134131
val getTheAnswer = () => 42
@@ -139,7 +136,7 @@ println(getTheAnswer()) // 42
139136

140137
Methods look and behave very similar to functions, but there are a few key differences between them.
141138

142-
Methods are defined with the `def` keyword. `def` is followed by a name, parameter lists, a return type, and a body.
139+
Methods are defined with the `def` keyword. `def` is followed by a name, parameter list(s), a return type, and a body:
143140

144141
{% scalafiddle %}
145142
```tut
@@ -148,9 +145,9 @@ println(add(1, 2)) // 3
148145
```
149146
{% endscalafiddle %}
150147

151-
Notice how the return type is declared _after_ the parameter list and a colon `: Int`.
148+
Notice how the return type is declared _after_ the parameter list and the `: Int`.
152149

153-
Methods can take multiple parameter lists.
150+
A method can take multiple parameter lists:
154151

155152
{% scalafiddle %}
156153
```tut
@@ -159,16 +156,16 @@ println(addThenMultiply(1, 2)(3)) // 9
159156
```
160157
{% endscalafiddle %}
161158

162-
Or no parameter lists at all.
159+
Or no parameter lists at all:
163160

164161
```tut
165162
def name: String = System.getProperty("user.name")
166163
println("Hello, " + name + "!")
167164
```
168165

169-
There are some other differences, but for now, you can think of them as something similar to functions.
166+
There are some other differences, but for now, you can think of methods as something similar to functions.
170167

171-
Methods can have multi-line expressions as well.
168+
Methods can have multi-line expressions as well:
172169

173170
{% scalafiddle %}
174171
```tut
@@ -180,21 +177,21 @@ println(getSquareString(2.5)) // 6.25
180177
```
181178
{% endscalafiddle %}
182179

183-
The last expression in the body is the method's return value. (Scala does have a `return` keyword, but it's rarely used.)
180+
The last expression in the body is the method's return value. (Scala does have a `return` keyword, but it is rarely used.)
184181

185182
## Classes
186183

187-
You can define classes with the `class` keyword followed by its name and constructor parameters.
184+
You can define classes with the `class` keyword, followed by its name and constructor parameters:
188185

189186
```tut
190187
class Greeter(prefix: String, suffix: String) {
191188
def greet(name: String): Unit =
192189
println(prefix + name + suffix)
193190
}
194191
```
195-
The return type of the method `greet` is `Unit`, which says there's nothing meaningful to return. It's used similarly to `void` in Java and C. (A difference is that because every Scala expression must have some value, there is actually a singleton value of type Unit, written (). It carries no information.)
192+
The return type of the method `greet` is `Unit`, which signifies that there is nothing meaningful to return. It is used similarly to `void` in Java and C. (A difference is that, because every Scala expression must have some value, there is actually a singleton value of type Unit, written (). It carries no information.)
196193

197-
You can make an instance of a class with the `new` keyword.
194+
You can make an instance of a class with the `new` keyword:
198195

199196
```tut
200197
val greeter = new Greeter("Hello, ", "!")
@@ -205,21 +202,23 @@ We will cover classes in depth [later](classes.html).
205202

206203
## Case Classes
207204

208-
Scala has a special type of class called a "case" class. By default, case classes are immutable and compared by value. You can define case classes with the `case class` keywords.
205+
Scala has a special type of class called a "case" class. By default, case classes are immutable, and they are compared by value (unlike classes, which are compared by reference). This makes them additionally useful for [pattern matching](https://docs.scala-lang.org/tour/pattern-matching.html#matching-on-case-classes).
206+
207+
You can define case classes with the `case class` keywords:
209208

210209
```tut
211210
case class Point(x: Int, y: Int)
212211
```
213212

214-
You can instantiate case classes without `new` keyword.
213+
You can instantiate case classes without the `new` keyword:
215214

216215
```tut
217216
val point = Point(1, 2)
218217
val anotherPoint = Point(1, 2)
219218
val yetAnotherPoint = Point(2, 2)
220219
```
221220

222-
And they are compared by value.
221+
Case classes are compared by value, not by reference:
223222

224223
```tut
225224
if (point == anotherPoint) {
@@ -235,13 +234,13 @@ if (point == yetAnotherPoint) {
235234
} // Point(1,2) and Point(2,2) are different.
236235
```
237236

238-
There is a lot more to case classes that we'd like to introduce, and we are convinced you will fall in love with them! We will cover them in depth [later](case-classes.html).
237+
There is a lot more to case classes that we would like to introduce, and we are convinced you will fall in love with them! We will cover them in depth [later](case-classes.html).
239238

240239
## Objects
241240

242241
Objects are single instances of their own definitions. You can think of them as singletons of their own classes.
243242

244-
You can define objects with the `object` keyword.
243+
You can define objects with the `object` keyword:
245244

246245
```tut
247246
object IdFactory {
@@ -253,7 +252,7 @@ object IdFactory {
253252
}
254253
```
255254

256-
You can access an object by referring to its name.
255+
You can access an object by referring to its name:
257256

258257
```tut
259258
val newId: Int = IdFactory.create()
@@ -266,17 +265,17 @@ We will cover objects in depth [later](singleton-objects.html).
266265

267266
## Traits
268267

269-
Traits are types containing certain fields and methods. Multiple traits can be combined.
268+
Traits are abstract data types containing certain fields and methods. In Scala inheritance, a class can only extend one other class, but it can extend multiple traits.
270269

271-
You can define traits with `trait` keyword.
270+
You can define traits with the `trait` keyword:
272271

273272
```tut
274273
trait Greeter {
275274
def greet(name: String): Unit
276275
}
277276
```
278277

279-
Traits can also have default implementations.
278+
Traits can also have default implementations:
280279

281280
{% scalafiddle %}
282281
```tut
@@ -286,7 +285,7 @@ trait Greeter {
286285
}
287286
```
288287

289-
You can extend traits with the `extends` keyword and override an implementation with the `override` keyword.
288+
You can extend traits with the `extends` keyword and override an implementation with the `override` keyword:
290289

291290
```tut
292291
class DefaultGreeter extends Greeter
@@ -305,17 +304,17 @@ customGreeter.greet("Scala developer") // How are you, Scala developer?
305304
```
306305
{% endscalafiddle %}
307306

308-
Here, `DefaultGreeter` extends only a single trait, but it could extend multiple traits.
307+
Here, `DefaultGreeter` extends only one single trait, but it could extend multiple traits.
309308

310309
We will cover traits in depth [later](traits.html).
311310

312311
## Main Method
313312

314-
The main method is an entry point of a program. The Java Virtual
315-
Machine requires a main method to be named `main` and take one
316-
argument, an array of strings.
313+
The main method is the entry point of a Scala program. The Java Virtual
314+
Machine requires a main method, named `main`, that takes one
315+
argument: an array of strings.
317316

318-
Using an object, you can define a main method as follows:
317+
Using an object, you can define the main method as follows:
319318

320319
```tut
321320
object Main {

_tour/tour-of-scala.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Scala is a modern multi-paradigm programming language designed to express common
2727
Scala is a pure object-oriented language in the sense that [every value is an object](unified-types.html). Types and behaviors of objects are described by [classes](classes.html) and [traits](traits.html). Classes can be extended by subclassing, and by using a flexible [mixin-based composition](mixin-class-composition.html) mechanism as a clean replacement for multiple inheritance.
2828

2929
## Scala is functional ##
30-
Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](basics.html#functions) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and it supports [currying](multiple-parameter-lists.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html) model algebraic types are used in many functional programming languages. [Singleton objects](singleton-objects.html) provide a convenient way to group functions that aren't members of a class.
30+
Scala is also a functional language in the sense that [every function is a value](unified-types.html). Scala provides a [lightweight syntax](basics.html#functions) for defining anonymous functions, it supports [higher-order functions](higher-order-functions.html), it allows functions to be [nested](nested-functions.html), and it supports [currying](multiple-parameter-lists.html). Scala's [case classes](case-classes.html) and its built-in support for [pattern matching](pattern-matching.html) provide the functionality of algebraic types, which are used in many functional languages. [Singleton objects](singleton-objects.html) provide a convenient way to group functions that aren't members of a class.
3131

3232
Furthermore, Scala's notion of pattern matching naturally extends to the [processing of XML data](https://github.com/scala/scala-xml/wiki/XML-Processing) with the help of [right-ignoring sequence patterns](regular-expression-patterns.html), by way of general extension via [extractor objects](extractor-objects.html). In this context, [for comprehensions](for-comprehensions.html) are useful for formulating queries. These features make Scala ideal for developing applications like web services.
3333

0 commit comments

Comments
 (0)