From d601a34e4d933642caba838760fe52540493b192 Mon Sep 17 00:00:00 2001 From: James Collier Date: Sun, 1 Sep 2019 12:01:22 +0100 Subject: [PATCH] reason for should not use app --- README.md | 1 + sections/2-language-rules.md | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba71b6e..ef7627d 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/sections/2-language-rules.md b/sections/2-language-rules.md index 21c525d..4cc96e7 100644 --- a/sections/2-language-rules.md +++ b/sections/2-language-rules.md @@ -785,4 +785,24 @@ Example: ```scala final case class User(name: String, id: Long) -``` \ No newline at end of file +``` + +### 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!") +} +```