Skip to content

Grammar and wording changes to 'Basics' page. #1579

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
merged 49 commits into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e767bbd
Add colon before list
Nov 13, 2019
212dca7
Change ordered list to unordered list as items do not represent a seq…
Nov 13, 2019
e52b959
Change 'either' to 'whichever'
Nov 13, 2019
85af57b
Capitalise first letter of item in a list
Nov 13, 2019
702e32f
Add 'by' to clarifymeaning
Nov 13, 2019
1d8fe41
Add colon before a list
Nov 13, 2019
7f4efb3
Add missing word, and add a comma and a 'for' for clarity
Nov 13, 2019
af2b2e3
Change html lists to markdown for consistency with other lists
Nov 13, 2019
629075a
Change 'set up' verb to 'setup' adjective
Nov 13, 2019
761ca7d
Change 'smoothly' integrates to 'seamlessly' integrates, as 'seamless…
Nov 13, 2019
b47dd26
Flesh out the word 'that', to provide more clarity
Nov 13, 2019
8b1fdce
Change 'behavior' to 'behaviors' for clarity, as it may seem like al…
Nov 13, 2019
9d9a2b5
Change sentence slightly to clarify that subclassing and mixins are t…
Nov 13, 2019
1a4956b
Add it for consistency with the rest of the list
Nov 13, 2019
96711b4
Add missing word
Nov 13, 2019
46d0daf
Capitalise first letter of items in a list
Nov 13, 2019
d2e90e0
Change use of 'easy' and 'smoothly' to 'straightforward', as these tw…
Nov 13, 2019
06ab742
Change 'smooth' to 'seamless'
Nov 13, 2019
22b3f49
Change 'close' to 'closely', as 'close' relates to location in physic…
Nov 13, 2019
875ce74
Change grammar; should be 'as' instead of 'with'
Nov 13, 2019
5892a23
Remove reference to contents menu to prevent information overload; th…
Nov 13, 2019
41d2729
Add a colon directly preceding a list
Nov 13, 2019
e38d984
Remove unnecessary comma from list item
Nov 13, 2019
4991195
Add missing word
Nov 13, 2019
e0ec662
Add a colon before a list
Nov 13, 2019
ddf423d
Change words to increase clarity
Nov 13, 2019
627a552
Rearrange wording to increase clarity. Italicise 'ScalaFiddle'
Nov 13, 2019
0f9e44c
Italicise 'ScalaFiddle'. Reorganise sentences to group similar inform…
Nov 13, 2019
b03bf63
Add a colon when introducing a code example
Nov 13, 2019
7d66392
Add words for clarity and consistency
Nov 13, 2019
26e491b
Add more clarity around type inference
Nov 13, 2019
8e1428a
Add more clarity around type inference
Nov 13, 2019
c692abc
Update description of scala functions.
Nov 13, 2019
2567d1c
Add clarity to anonymous function description
Nov 13, 2019
6902608
Change 'parameter' to 'argument'
Nov 13, 2019
25bfca3
Change 'parameter' to 'argument'
Nov 13, 2019
121e24e
Add parenthesis around 's' to clarify that multiple parameter lists a…
Nov 13, 2019
d5ace9e
Remove redundancy of having the word 'colon' followed by the colon pu…
Nov 13, 2019
3279cbf
Clarify the description of 'Unit'
Nov 13, 2019
52e065b
Flesh out the definition of case classes
Nov 13, 2019
ba03182
Add missing word
Nov 13, 2019
4c50787
Add clarity to case class comparison
Nov 13, 2019
1671d4e
Add missing word
Nov 13, 2019
48f1e8f
Flesh out the description of traits for clarity
Nov 13, 2019
675528b
Clarify the definition of a main method
Nov 13, 2019
bcf565c
Tidy up: add commas and clarifications
Nov 13, 2019
b13084c
Remove contractions
Nov 13, 2019
7502ee9
Make changes requested in PR comments
Dec 6, 2019
006dafc
Merge branch 'master' into basics
SethTisue Dec 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions _getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@ includeTOC: true
redirect_from: "/getting-started.html"
---

<div style="font-size: 1.25rem; color: #073642; font-weight: 400; font-family: 'Roboto Slab', serif; margin-bottom: 18px;"> There are <strong>two</strong> main ways people prefer to work in Scala.</div>
There are __two__ main ways people prefer to work in Scala:

<ol style="margin-bottom: 24px;">
<li style="margin-bottom: 4px;">Using an IDE.</li>
<li style="margin-bottom: 4px;">Using the command line.</li>
</ol>
* Using an IDE.
* Using the command line.


The following tutorials will walk you through the set up process for either way
The following tutorials will walk you through the setup process for whichever way
you prefer.

However, if you just want to jump directly into Scala without installing anything, skip the guides on this page and check out:

<ul style="margin-bottom: 24px;">
<li style="margin-bottom: 4px;"><a href="https://www.scala-exercises.org/scala_tutorial/terms_and_types">our interactive introduction to Scala on scala-exercises.com</a>, or</li>
<li style="margin-bottom: 4px;"><a href="https://scastie.scala-lang.org/">Scastie</a>, Scala in the browser, with access to all Scala compilers and all published libraries!</li>
</ul>
* [Our interactive introduction to Scala on scala-exercises.com](https://www.scala-exercises.org/scala_tutorial/terms_and_types), or
* [Scastie](https://scastie.scala-lang.org/), Scala in the browser, with access to all Scala compilers and all published libraries!

## Setting up and getting started with Scala

Expand All @@ -43,7 +38,7 @@ unit tests!
### If you prefer working on the command line...

If you prefer using a text editor like emacs, Vim, Atom, or Sublime Text, then
the best way to compile, test, and run Scala code is using _sbt_, Scala's build
the best way to compile, test, and run Scala code is by using _sbt_, Scala's build
tool.

* [Getting Started with Scala and sbt on the Command Line](/getting-started/sbt-track/getting-started-with-scala-and-sbt-on-the-command-line.html)
Expand All @@ -55,12 +50,12 @@ the rest, so it's as easy as possible for someone else to compile and run your
Scala project. -->

## Next Steps
Once you've finished these tutorials, check out
Once you've finished these tutorials, check out:

* [The Tour of Scala](/tour/tour-of-scala.html) for bite-sized introductions to Scala's features.
* [The Scala Book](/overviews/scala-book/introduction.html), which provides a set of short lessons introducing Scala’s main features.
* [Learning Resources](/learn.html), which includes online interactive tutorials and courses.
* [Our list of some popular Scala books](/books.html).

## Getting Help
There are a multitude of mailing lists and real-time chat channels in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page a list of these resources and where to reach out for help.
There are a multitude of mailing lists and real-time chat channels in case you want to quickly connect with other Scala users. Check out our [community](https://scala-lang.org/community/) page for a list of these resources, and for where to reach out for help.
87 changes: 43 additions & 44 deletions _tour/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,25 @@ previous-page: tour-of-scala
redirect_from: "/tutorials/tour/basics.html"
---

In this page, we will cover basics of Scala.
In this page, we will cover the basics of Scala.

## Trying Scala in the Browser

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

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

This is an easy, zero-setup way to experiment with pieces of Scala code.

Many of the code examples in this documentation are also integrated with ScalaFiddle, so you
can directly experiment with them simply by clicking the Run-button.
_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.

## Expressions

Expressions are computable statements.
Expressions are computable statements:
```
1 + 1
```
You can output results of expressions using `println`.
You can output the results of expressions using `println`:

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

### Values

You can name results of expressions with the `val` keyword.
You can name the results of expressions using the `val` keyword:

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

Values cannot be re-assigned.
Values cannot be re-assigned:

```tut:fail
x = 3 // This does not compile.
```

Types of values can be inferred, but you can also explicitly state the type, like this:
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:

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

As with values, you can explicitly state the type if you want:
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:

```tut
var x: Int = 1 + 1
Expand All @@ -89,7 +86,7 @@ var x: Int = 1 + 1

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

The result of the last expression in the block is the result of the overall block, too.
The result of the last expression in the block is the result of the overall block, too:

```tut
println({
Expand All @@ -100,17 +97,17 @@ println({

## Functions

Functions are expressions that take parameters.
Functions are expressions that have parameters, and take arguments.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant. Having parameters is equivalent to taking arguments. The original is better. (Also, functions can take zero arguments, so the statement isn't even correct either way, but the new one is worse than the old one.)

Also, although "arguments" is more standard terminology, the parameters are called parameters in Scala, so it's probably better to leave it alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take your point about the functions having zero arguments, but the original statement saying a function can "take" parameters doesn't make sense either.

A function has parameters. When it says functions "take" parameters it sounds like "parameters" can be passed in. Arguments can be passed in, parameters can't.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, but I don't think the clarity of the text should rely upon the reader understanding that arguments are the passed-in version of parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a reader sees "functions can take parameters", they might wonder about the quality, and accuracy of the Scala documentation as a whole.

The information should be made as accurate as possible, regardless of the reader's level of understanding.

I think this a (living) language thing. Some languages call them two different types of parameters; English calls them parameters and arguments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge the PR regardless, but I lean more towards Rex's side here. I invite anyone interested to submit a followup PR with a different wording that we all like?


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

```tut
(x: Int) => x + 1
```

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

You can also name functions.
You can also name functions:

{% scalafiddle %}
```tut
Expand All @@ -119,7 +116,7 @@ println(addOne(1)) // 2
```
{% endscalafiddle %}

Functions may take multiple parameters.
A function can have multiple parameters:

{% scalafiddle %}
```tut
Expand All @@ -128,7 +125,7 @@ println(add(1, 2)) // 3
```
{% endscalafiddle %}

Or it can take no parameters.
Or it can have no parameters at all:

```tut
val getTheAnswer = () => 42
Expand All @@ -139,7 +136,7 @@ println(getTheAnswer()) // 42

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

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

{% scalafiddle %}
```tut
Expand All @@ -148,9 +145,9 @@ println(add(1, 2)) // 3
```
{% endscalafiddle %}

Notice how the return type is declared _after_ the parameter list and a colon `: Int`.
Notice how the return type is declared _after_ the parameter list and the `: Int`.

Methods can take multiple parameter lists.
A method can take multiple parameter lists:

{% scalafiddle %}
```tut
Expand All @@ -159,16 +156,16 @@ println(addThenMultiply(1, 2)(3)) // 9
```
{% endscalafiddle %}

Or no parameter lists at all.
Or no parameter lists at all:

```tut
def name: String = System.getProperty("user.name")
println("Hello, " + name + "!")
```

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

Methods can have multi-line expressions as well.
Methods can have multi-line expressions as well:

{% scalafiddle %}
```tut
Expand All @@ -180,21 +177,21 @@ println(getSquareString(2.5)) // 6.25
```
{% endscalafiddle %}

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

## Classes

You can define classes with the `class` keyword followed by its name and constructor parameters.
You can define classes with the `class` keyword, followed by its name and constructor parameters:

```tut
class Greeter(prefix: String, suffix: String) {
def greet(name: String): Unit =
println(prefix + name + suffix)
}
```
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.)
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.)

You can make an instance of a class with the `new` keyword.
You can make an instance of a class with the `new` keyword:

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

## Case Classes

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.
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).

You can define case classes with the `case class` keywords:

```tut
case class Point(x: Int, y: Int)
```

You can instantiate case classes without `new` keyword.
You can instantiate case classes without the `new` keyword:

```tut
val point = Point(1, 2)
val anotherPoint = Point(1, 2)
val yetAnotherPoint = Point(2, 2)
```

And they are compared by value.
Case classes are compared by value, not by reference:

```tut
if (point == anotherPoint) {
Expand All @@ -235,13 +234,13 @@ if (point == yetAnotherPoint) {
} // Point(1,2) and Point(2,2) are different.
```

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).
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).

## Objects

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

You can define objects with the `object` keyword.
You can define objects with the `object` keyword:

```tut
object IdFactory {
Expand All @@ -253,7 +252,7 @@ object IdFactory {
}
```

You can access an object by referring to its name.
You can access an object by referring to its name:

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

## Traits

Traits are types containing certain fields and methods. Multiple traits can be combined.
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.

You can define traits with `trait` keyword.
You can define traits with the `trait` keyword:

```tut
trait Greeter {
def greet(name: String): Unit
}
```

Traits can also have default implementations.
Traits can also have default implementations:

{% scalafiddle %}
```tut
Expand All @@ -286,7 +285,7 @@ trait Greeter {
}
```

You can extend traits with the `extends` keyword and override an implementation with the `override` keyword.
You can extend traits with the `extends` keyword and override an implementation with the `override` keyword:

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

Here, `DefaultGreeter` extends only a single trait, but it could extend multiple traits.
Here, `DefaultGreeter` extends only one single trait, but it could extend multiple traits.

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

## Main Method

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

Using an object, you can define a main method as follows:
Using an object, you can define the main method as follows:

```tut
object Main {
Expand Down
Loading