Skip to content

Commit aaa9d8b

Browse files
committed
discuss postfix notation second, since it's less important
1 parent a3732aa commit aaa9d8b

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

style/method-invocation.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,6 @@ readability and will make it much easier to understand at a glance the
5454
most basic operation of any given method. Resist the urge to omit
5555
parentheses simply to save two characters!
5656

57-
## Postfix Notation
58-
59-
Scala allows methods that take no arguments to be invoked using postfix notation:
60-
61-
// recommended
62-
names.toList
63-
64-
// discourage
65-
names toList
66-
67-
This style is unsafe, and should not be used. Since semicolons are
68-
optional, the compiler will attempt to treat it as an infix method
69-
if it can, potentially taking a term from the next line.
70-
71-
names toList
72-
val answer = 42 // will not compile!
73-
74-
This may result in unexpected compile errors at best, and happily
75-
compiled faulty code at worst. Although the syntax is used by some
76-
DSLs, it should be considered deprecated, and avoided.
77-
78-
Since Scala 2.10, using postfix operator notation will result in a
79-
compiler warning.
80-
8157
## Infix notation
8258

8359
Scala has a special punctuation-free syntax for invoking methods that
@@ -116,3 +92,27 @@ Such methods are fairly rare, however, and should normally be avoided
11692
during API design. For example, the use of the `/:` and `:\` methods
11793
should be avoided in preference to their better-known names,
11894
`foldLeft` and `foldRight`.
95+
96+
## Postfix Notation
97+
98+
Scala allows methods that take no arguments to be invoked using postfix notation:
99+
100+
// recommended
101+
names.toList
102+
103+
// discourage
104+
names toList
105+
106+
This style is unsafe, and should not be used. Since semicolons are
107+
optional, the compiler will attempt to treat it as an infix method
108+
if it can, potentially taking a term from the next line.
109+
110+
names toList
111+
val answer = 42 // will not compile!
112+
113+
This may result in unexpected compile errors at best, and happily
114+
compiled faulty code at worst. Although the syntax is used by some
115+
DSLs, it should be considered deprecated, and avoided.
116+
117+
Since Scala 2.10, using postfix operator notation will result in a
118+
compiler warning.

0 commit comments

Comments
 (0)