Skip to content

Commit

Permalink
reason for should not use app
Browse files Browse the repository at this point in the history
  • Loading branch information
Slakah committed Sep 1, 2019
1 parent 932f32d commit d601a34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ contribute.
- [2.19. SHOULD use head/tail and init/last decomposition only if they can be done in constant time and memory](sections/2-language-rules.md#219-should-use-head-tail-and-init-last-decomposition-only-if-they-can-be-done-in-constant-time-and-memory)
- [2.20. MUST NOT use `Seq.head`](sections/2-language-rules.md#210-must-not-use-seqhead)
- [2.21. Case classes SHOULD be final](sections/2-language-rules.md#221-case-classes-should-be-final)
- [2.22. SHOULD NOT use `scala.App`](sections/2-language-rules.md#222-should-not-use-scalaapp)

- [3. Application Architecture](sections/3-architecture.md)
- [3.1. SHOULD NOT use the Cake pattern](sections/3-architecture.md#31-should-not-use-the-cake-pattern)
Expand Down
22 changes: 21 additions & 1 deletion sections/2-language-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,24 @@ Example:

```scala
final case class User(name: String, id: Long)
```
```

### 2.22 SHOULD NOT use `scala.App`

`scala.App` is ofter used to denote the entrypoint of the application:

```scala
object HelloWorldApp extends App {
println("hello, world!")
}
```

`DelayedInit` one of the mechanisms used to implement `scala.App` [has been deprecated](https://github.com/scala/scala/pull/3563).
Any variables defined in the object body will be available as fields, unless the `private` access modifier is applied.
Prefer the simpler alternative of defining a main method:

```scala
object HelloWorldApp {
def main(args: Array[String]): Unit = println("hello, world!")
}
```

0 comments on commit d601a34

Please sign in to comment.