Scala最佳實踐
列出了采用Scala語言進行開發時的最佳實踐建議,總共分為5大類:
①Hygienic Rules
②Language Rules
③Application Architecture
④Concurrency and Parallelism⑤Akka Actors。
Scala Best Practices
A collection of best practices, friendly to people that want to contribute.
- Version:
0.4
- Updated at:
2014-10-24
Table of Contents
-
- 2.1. MUST NOT use "return"
- 2.2. SHOULD use immutable data structures
- 2.3. SHOULD NOT update a "var" using loops or conditions
- 2.4. SHOULD NOT define useless traits
- 2.5. MUST NOT use "var" inside a case class
- 2.6. SHOULD NOT declare abstract val or var or lazy val members
- 2.7. MUST NOT throw exceptions for validations of user input or flow control
- 2.8. MUST NOT catch Throwable
- 2.9. MUST NOT use "null"
- 2.10. MUST NOT use "Option.get"
- 2.11. MUST NOT use Java's Date or Calendar, instead use Joda-Time or JSR-310
- 2.12. SHOULD NOT use Any or AnyRef or isInstanceOf / asInstanceOf
- 2.13. MUST serialize dates as either Unix Timestamp or ISO 8601
- 2.14. MUST NOT use magic values
- 2.15. SHOULD NOT use "var" as shared state
- 2.16. Public functions SHOULD have an explicit return type
- 2.17. SHOULD NOT define case classes nested in other classes
-
4. Concurrency and Parallelism
- 4.1. SHOULD avoid concurrency like the plague it is
- 4.2. SHOULD use appropriate abstractions only where suitable
- 4.3. SHOULD NOT wrap purely CPU-bound operations in Futures
- 4.4. MUST use Scala's BlockContext on blocking I/O
- 4.5. SHOULD NOT block
- 4.6. SHOULD use a separate thread-pool for blocking I/O
- 4.7. All public APIs SHOULD BE thread-safe
- 4.8. SHOULD avoid contention on shared reads
- 4.9. MUST provide a clearly defined and documented protocol for each component or actor that communicates over async boundaries
- 4.10. SHOULD always prefer single producer scenarios
- 4.11. MUST NOT hard-code the thread-pool / execution context
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!