Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
107 views31 pages

Scala Style Guide

Scala style guide to help write better scala code
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views31 pages

Scala Style Guide

Scala style guide to help write better scala code
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Scala Style Guide Documentation

Release 1.3.1

Scala Community

December 04, 2011

CONTENTS

1 2

Overview Indentation 2.1 Line Wrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Methods with Numerous Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Naming Conventions 3.1 Classes/Traits . . . . . . . . . 3.2 Objects . . . . . . . . . . . . 3.3 Packages . . . . . . . . . . . 3.4 Methods . . . . . . . . . . . 3.5 Values, Variable and Methods 3.6 Type Parameters (generics) . 3.7 Type Aliases . . . . . . . . . 3.8 Annotations . . . . . . . . . . 3.9 Special Note on Brevity . . . Types 4.1 Inference . . . . 4.2 Annotations . . . 4.3 Ascription . . . 4.4 Functions . . . . 4.5 Structural Types

3 5 5 5 7 7 7 7 7 8 8 8 8 8 9 9 9 9 9 10 11 11 11 13 13 13 13 13 14 15 15 15 15

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

Nested Blocks 5.1 Curly Braces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Declarations 6.1 Ordering Of Class Elements 6.2 Methods . . . . . . . . . . 6.3 Fields . . . . . . . . . . . . 6.4 Spacing . . . . . . . . . . . 6.5 Multi-Expression Functions

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

Control Structures 7.1 Curly-Braces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Comprehensions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.3 Trivial Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Method Invocation 8.1 Arity-0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.2 Arity-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3 Symbolic methods/Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Files 9.1 Multi-Unit Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

17 17 17 17 19 19 21 23 25 27

10 Scaladoc 11 Changelog 12 License 13 Indices and tables

ii

Scala Style Guide Documentation, Release 1.3.1

The style guide has been adopted by the maintainers of Scala. You can read it online at http://docs.scala-lang.org/style and the source can be forked from https://github.com/scala/scala.github.com Contents:

CONTENTS

Scala Style Guide Documentation, Release 1.3.1

CONTENTS

CHAPTER

ONE

OVERVIEW
Moved to http://docs.scala-lang.org/style/overview.html

Scala Style Guide Documentation, Release 1.3.1

Chapter 1. Overview

CHAPTER

TWO

INDENTATION
Moved to http://docs.scala-lang.org/style/indentation.html

2.1 Line Wrapping


Moved to http://docs.scala-lang.org/style/indentation.html

2.2 Methods with Numerous Arguments


Moved to http://docs.scala-lang.org/style/indentation.html

Scala Style Guide Documentation, Release 1.3.1

Chapter 2. Indentation

CHAPTER

THREE

NAMING CONVENTIONS
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.1 Classes/Traits
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.2 Objects
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.3 Packages
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.4 Methods
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.4.1 Accessors/Mutators
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.4.2 Parentheses
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.4.3 Symbolic Method Names


Moved to http://docs.scala-lang.org/style/naming-conventions.html

Scala Style Guide Documentation, Release 1.3.1

3.5 Values, Variable and Methods


Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.6 Type Parameters (generics)


Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.6.1 Higher-Kinds and Parameterized Type parameters


Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.7 Type Aliases


Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.8 Annotations
Moved to http://docs.scala-lang.org/style/naming-conventions.html

3.9 Special Note on Brevity


Moved to http://docs.scala-lang.org/style/naming-conventions.html

Chapter 3. Naming Conventions

CHAPTER

FOUR

TYPES
4.1 Inference
Moved to http://docs.scala-lang.org/style/types.html

4.1.1 Function Values


Moved to http://docs.scala-lang.org/style/types.html

4.1.2 Void Methods


Moved to http://docs.scala-lang.org/style/types.html

4.2 Annotations
Moved to http://docs.scala-lang.org/style/types.html

4.3 Ascription
Moved to http://docs.scala-lang.org/style/types.html

4.4 Functions
Moved to http://docs.scala-lang.org/style/types.html

4.4.1 Arity-1
Moved to http://docs.scala-lang.org/style/types.html

Scala Style Guide Documentation, Release 1.3.1

4.5 Structural Types


Moved to http://docs.scala-lang.org/style/types.html

10

Chapter 4. Types

CHAPTER

FIVE

NESTED BLOCKS
5.1 Curly Braces
Moved to http://docs.scala-lang.org/style/nested-blocks.html

5.2 Parentheses
Moved to http://docs.scala-lang.org/style/nested-blocks.html

11

Scala Style Guide Documentation, Release 1.3.1

12

Chapter 5. Nested Blocks

CHAPTER

SIX

DECLARATIONS
Moved to http://docs.scala-lang.org/style/declarations.html

6.1 Ordering Of Class Elements


Moved to http://docs.scala-lang.org/style/declarations.html

6.2 Methods
Moved to http://docs.scala-lang.org/style/declarations.html

6.2.1 Modiers
Moved to http://docs.scala-lang.org/style/declarations.html

6.2.2 Multiple Parameter Lists


Moved to http://docs.scala-lang.org/style/declarations.html

6.2.3 Higher-Order Functions


Moved to http://docs.scala-lang.org/style/declarations.html

6.3 Fields
Moved to http://docs.scala-lang.org/style/declarations.html

6.4 Spacing
Moved to http://docs.scala-lang.org/style/declarations.html

13

Scala Style Guide Documentation, Release 1.3.1

6.5 Multi-Expression Functions


Moved to http://docs.scala-lang.org/style/declarations.html

14

Chapter 6. Declarations

CHAPTER

SEVEN

CONTROL STRUCTURES
Moved to http://docs.scala-lang.org/style/control-structures.html

7.1 Curly-Braces
Moved to http://docs.scala-lang.org/style/control-structures.html

7.2 Comprehensions
Moved to http://docs.scala-lang.org/style/control-structures.html

7.3 Trivial Conditionals


Moved to http://docs.scala-lang.org/style/control-structures.html

15

Scala Style Guide Documentation, Release 1.3.1

16

Chapter 7. Control Structures

CHAPTER

EIGHT

METHOD INVOCATION
Moved to http://docs.scala-lang.org/style/method-invocation.html

8.1 Arity-0
Moved to http://docs.scala-lang.org/style/method-invocation.html

8.1.1 Sufx Notation


Moved to http://docs.scala-lang.org/style/method-invocation.html

8.2 Arity-1
Moved to http://docs.scala-lang.org/style/method-invocation.html

8.2.1 Higher-Order Functions


Moved to http://docs.scala-lang.org/style/method-invocation.html

8.3 Symbolic methods/Operators


Moved to http://docs.scala-lang.org/style/method-invocation.html

17

Scala Style Guide Documentation, Release 1.3.1

18

Chapter 8. Method Invocation

CHAPTER

NINE

FILES
Moved to http://docs.scala-lang.org/style/les.html

9.1 Multi-Unit Files


Moved to http://docs.scala-lang.org/style/les.html

19

Scala Style Guide Documentation, Release 1.3.1

20

Chapter 9. Files

CHAPTER

TEN

SCALADOC
Moved to http://docs.scala-lang.org/style/scaladoc.html

21

Scala Style Guide Documentation, Release 1.3.1

22

Chapter 10. Scaladoc

CHAPTER

ELEVEN

CHANGELOG
v1.3.1 - 9/19/2011 Restored sane and canonical scaladoc format Changed naming convention of type parameters, per @jsuereth Use term symbolic methods instead of operators, per @soc Additional operator overloading warning, per @djswpiewak Notes on calling and declaring mehtods with default parameters, per @djspiewak Other cleanups, clarications, and rewordings, per @jsuereth v1.2.6 - 6/12/2011 Added CC license v1.2.5 - 4/13/2011 Expanded multiple-parameter list styles to include formatting for long parameter lists Added a changelog v1.2.4 - 2/13/2011 Reworked the currying section to be about multiple parameter lists, based on community feedback v1.2.3 - 1/2/2011 Reworded bit about short parameter names based on community feedback v1.2.2 - 12/30/2010 Spelling mistakes v1.2.1 - 10/2/2010 Removing special note about IntelliJ that no longer applies Slight cleanup of scaladoc section and added an example for object scaladoc v1.2.0 - 10/2/2010 Claried how packages work in light of Scala 2.8 Added new section on writing scaladoc v1.1.0 - 1/26/2010 Claried the use for for comprehensions Documented avoidance of /: and similar operators

23

Scala Style Guide Documentation, Release 1.3.1

Possibly other changes v1.0.0 Similar to Daniel Spiewaks initial version; possibly slight changes

24

Chapter 11. Changelog

CHAPTER

TWELVE

LICENSE
This work is licensed under the Creative Commons license Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0). Please see the link for the specics of the license, but, in short, this means: You are free: to Share to copy, distribute and transmit the work to Remix to adapt the work to make commercial use of the work Under the following conditions: Attribution You must attribute the work in the manner specied by the author or licensor (but not in any way that suggests that they endorse you or your use of the work). Share Alike If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one. With the understanding that: Waiver Any of the above conditions can be waived if you get permission from the copyright holder. Public Domain Where the work or any of its elements is in the public domain under applicable law, that status is in no way affected by the license. Other Rights In no way are any of the following rights affected by the license: Your fair dealing or fair use rights, or other applicable copyright exceptions and limitations; The authors moral rights; Rights other persons may have either in the work itself or in how the work is used, such as publicity or privacy rights. Notice For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.

25

Scala Style Guide Documentation, Release 1.3.1

26

Chapter 12. License

CHAPTER

THIRTEEN

INDICES AND TABLES


genindex search

27

You might also like