Skip to content

small changes to basics #751

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 1 commit into from
Apr 27, 2017
Merged

small changes to basics #751

merged 1 commit into from
Apr 27, 2017

Conversation

travissarles
Copy link
Contributor

No description provided.

Copy link
Member

@SethTisue SethTisue left a comment

Choose a reason for hiding this comment

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

LGTM — I have made some suggestions, but I don't insist on any of them.

@@ -136,7 +141,7 @@ def add(x: Int, y: Int): Int = x + y
println(add(1, 2)) // 3
```

Methods cannot be named with the `val` or `var` keywords.
Notice how the return type is declared _after_ the parameter list: `: Int`. Methods cannot be named with the `val` or `var` keywords.
Copy link
Member

Choose a reason for hiding this comment

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

Methods cannot be named with the val or var keywords.

not sure about this addition. is this really needed here? if so, I think you need to expand on this and be clearer. (else, omit?) if you want to include it, I would suggest stating it positively rather than negatively: "A method is always defined using the def keyword."

@@ -160,6 +165,16 @@ println("Hello, " + name + "!")

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

Method can have multi-line expressions as well.
Copy link
Member

Choose a reason for hiding this comment

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

"Methods" or "A method". Maybe "A method's body"?

square.toString
}
```
You can use the `return` but it is not necessary or idiomatic. Expressions
Copy link
Member

Choose a reason for hiding this comment

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

I would downplay and discourage return more strongly. Perhaps: "The last expression in the body is the method's return value. (Scala does have a return keyword, but it's rarely used.)"

@@ -170,6 +185,7 @@ class Greeter(prefix: String, suffix: String) {
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 but the main difference is that there is actually a singleton value of type `Unit`, written `()`.
Copy link
Member

Choose a reason for hiding this comment

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

perhaps:

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

@SethTisue SethTisue merged commit 0cdd508 into scala:master Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants