Skip to content
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

indentation explanation for scala 3 book #2445

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

Shorla
Copy link
Contributor

@Shorla Shorla commented Jun 23, 2022

This solves the issue at #2266

Copy link
Contributor

@julienrf julienrf left a comment

Choose a reason for hiding this comment

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

Thank you for opening a PR @Shorla.

I am a bit confused, however, because I thought you would introduce the fact that the indentation is significant in Scala 3, but you mostly talk about code style best practices. I would expect to see a discussion about braces being optional, as explained here: https://docs.scala-lang.org/scala3/reference/other-new-features/indentation.html

_overviews/scala3-book/taste-indentation.md Outdated Show resolved Hide resolved
_overviews/scala3-book/taste-indentation.md Outdated Show resolved Hide resolved
_overviews/scala3-book/taste-indentation.md Outdated Show resolved Hide resolved
_overviews/scala3-book/taste-indentation.md Outdated Show resolved Hide resolved
_overviews/scala3-book/taste-indentation.md Outdated Show resolved Hide resolved
_overviews/scala3-book/taste-indentation.md Outdated Show resolved Hide resolved
@SethTisue SethTisue changed the title indentaion explaination for scala 3 book indentation explanation for scala 3 book Jun 28, 2022
@bishabosha
Copy link
Member

Hi @Shorla, thank you for opening this PR. I noticed that you marked @julienrf comments as resolved, do you have some extra commits to push? The points about updating the metadata in other markdown files is important otherwise the documentation will not render correctly.

@Shorla
Copy link
Contributor Author

Shorla commented Jul 6, 2022

@bishabosha I made the adjustments for the metadata, but I'm yet to push it because I'm trying to conclude on the article. But I should push the full changes before the end of the week.

@bishabosha
Copy link
Member

I made the adjustments for the metadata, but I'm yet to push it because I'm trying to conclude on the article. But I should push the full changes before the end of the week.

Ok great :), let us know if you want any more reviews

@Shorla
Copy link
Contributor Author

Shorla commented Jul 19, 2022

hi @bishabosha @julienrf, I couldn't add all of the information on optional braces. I added a part then a link to the Scala 3 reference article.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

Some structural notes.

next-page: taste-control-structures
---

Indentation refers to the increase or decrease of space between the left and right margin of a paragraph.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a cogent sentence.

class Foo {
def fourspaces = {
val x = 4
..
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if there is a local style for "omitted code" and whether it is styled, but there ought to be.

}
}

The Scala language encourages a startling amount of nested scopes and
Copy link
Contributor

Choose a reason for hiding this comment

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

"Users accustomed to Java might be startled by how deeply constructs can be nested in Scala."

The "Coming from Java" should come first. The syntax itself is not startling per se.


When it is absolutely necessary to wrap an expression across more than
one line, each successive line should be indented two spaces from the
*first*. Also remember that Scala requires each "wrap line" to either
Copy link
Contributor

Choose a reason for hiding this comment

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

Scala 3 or Scala 2 -Xsource:3 supports leading infix operator on the next line.

I'd suggest presenting the problematic code and then the solution (scalafmt or whatever).


val result = 1 + 2 + 3 + 4 + 5 + 6 +
7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 +
15 + 16 + 17 + 18 + 19 + 20
Copy link
Contributor

Choose a reason for hiding this comment

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

a verbose snippet


## Methods with Numerous Arguments

it is best practice to avoid any method which takes more than two or
Copy link
Contributor

Choose a reason for hiding this comment

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

"It". A paragraph about usual styles of method invocation would be helpful, including when to use named args (such as with boolean constants, f(recurse = true)). It would be most succinct to refer to a scalafmt config and show the output.

the length of the line. More specifically, such an invocation should be
avoided when each parameter would have to be indented more than 50
spaces to achieve alignment. In such cases, the invocation itself should
be moved to the next line and indented two spaces:
Copy link
Contributor

Choose a reason for hiding this comment

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

This happens often. It's very annoying. There is no good solution except scalafmt, which I don't use, but I'd like to see the config that will format to some standard, and also see an example. I'm not likely to memorize rules.

- An `<outdent>` is also inserted if the next token following a statement sequence starting with an `<indent>` closes an indentation region, i.e. is one of `then`, `else`, `do`, `catch`, `finally`, `yield`, `}`, `)`, `]` or `case`.

- An `<outdent>` is finally inserted in front of a comma that follows a statement sequence starting with an `<indent>` if the indented region is itself enclosed in parentheses.

Copy link
Contributor

Choose a reason for hiding this comment

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

The preceding is more like spec. I can't review that ATM, but I think some guidance about "when do I need to think about indentation" would be worthwhile. That is, normally, it should just work. When does it not just work?

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.

4 participants