Skip to content

Commit 7527841

Browse files
Merge pull request #7480 from dotty-staging/20-release-blog
20th Release Blog Article
2 parents 332c831 + b55b919 commit 7527841

File tree

1 file changed

+203
-0
lines changed

1 file changed

+203
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
---
2+
layout: blog-page
3+
title: Announcing Dotty 0.20.0-RC1 – `with` starting indentation blocks, inline given specializations and more
4+
author: Anatolii Kmetiuk
5+
authorImg: /images/anatolii.png
6+
date: 2019-11-04
7+
---
8+
9+
Greetings! We are excited to announce the 20th release of Dotty. This release brings a bunch of improvements to the language, such as `with` keyword starting an indentation block, normal parameters after given parameters, inline givens specialization and more.
10+
11+
This release serves as a technology preview that demonstrates new
12+
language features and the compiler supporting them.
13+
14+
Dotty is the project name for technologies that are being considered for
15+
inclusion in Scala 3. Scala has pioneered the fusion of object-oriented and
16+
functional programming in a typed setting. Scala 3 will be a big step towards
17+
realising the full potential of these ideas. Its main objectives are to
18+
19+
- become more opinionated by promoting programming idioms we found to work well,
20+
- simplify where possible,
21+
- eliminate inconsistencies and surprising behaviours,
22+
- build on strong foundations to ensure the design hangs together well,
23+
- consolidate language constructs to improve the language’s consistency, safety, ergonomics, and
24+
performance.
25+
26+
You can learn more about Dotty on our [website](https://dotty.epfl.ch).
27+
28+
<!--more-->
29+
30+
# What’s new in the 0.20.0-RC1 technology preview?
31+
## Syntax change for type parameters of extension methods
32+
When writing extension methods with type parameters, the type parameters must come first, e.g.:
33+
34+
```scala
35+
def [T](xs: List[T]) append (ys: List[T]): List[T] = ...
36+
```
37+
38+
Previously, the same would have been written as:
39+
40+
```scala
41+
def (xs: List[T]) append [T] (ys: List[T]): List[T] = ...
42+
```
43+
44+
An argument for the old syntax is that it aligns the definition and call syntax. On the other hand, the new syntax maintains the general rule that parameter introductions always come before parameter uses. The decisive argument to switch is to be consistent with the new collective parameter syntax, where `append` would be written like this:
45+
46+
```scala
47+
given [T](xs: List[T])
48+
def append (ys: List[T]): List[T] = ...
49+
```
50+
51+
To avoid misalignment of type parameters between definition and call syntax, we considered disallowing explicit type parameters for extension methods altogether, and to require that the method is called as a normal method instead. But that would not work for anonymous givens as in the last example above.
52+
53+
## Infer `private[this]`
54+
We now infer the `private[this]` modifier for variables if all the accesses to a variable are via this. Explicit `private[this]` and `protected[this]` in code are deprecated under the `-strict` flag.
55+
56+
The main reasons for dropping `private[this]` are:
57+
58+
- It is syntactically an irregular case. A pair of brackets usually encloses a type, but `this` is a value.
59+
- Its effect over `private` is purely local and can be easily inferred.
60+
- It leads to bike shedding: should I use `private` or `private[this]`? One is shorter but the other might be more efficient.
61+
62+
`protected[this]` by now influences compiler decisions in no way at all. Hence it is is reasonable to drop it.
63+
64+
## `with` keyword's new role
65+
`with` keyword can now optionally precede the class body. So that you can write your classes as follows:
66+
67+
```scala
68+
trait A with {
69+
def f: Int
70+
}
71+
class C(x: Int) extends A with {
72+
def f = x
73+
}
74+
type T = A with {
75+
def f: Int
76+
}
77+
```
78+
79+
Or, equivalently:
80+
81+
```scala
82+
trait A with
83+
def f: Int
84+
class C(x: Int) extends A with
85+
def f = x
86+
type T = A with
87+
def f: Int
88+
```
89+
90+
The problem this change solves is that it is very easy to accidentally outdent a class member – and it will end up outside the class. The benefit of the new `with` is that starts an indentation block. Since the compiler knows for sure an indentation block must follow, it will emit an error if you forget to indent your statement.
91+
92+
## Inline `given` specialization
93+
It is now possible to specialize `inline given`s with the help of `<:` as follows:
94+
95+
```scala
96+
trait A
97+
class B extends A
98+
99+
inline given tc <: A = B()
100+
101+
val x: B = summon[A]
102+
```
103+
104+
This change brings `given`s even with the ordinary `inline def`s.
105+
106+
## Normal parameters can follow `given` parameters
107+
Previously normal parameters after `given` parameter was disallowed mainly because they looked awkward with the old syntax. With the syntax being improved, this restriction is now lifted and you can write, e.g., the following program:
108+
109+
```scala
110+
class C(val x: Int)
111+
def f(x: Int)(given c: C)(y: Int) = x + c.x + y
112+
```
113+
114+
## `then` is optional at line end
115+
So the following is now legal:
116+
117+
```scala
118+
val y1 =
119+
if x > 0
120+
1
121+
else
122+
2
123+
```
124+
125+
It is easy to forget to put `then` at the end of the line if nothing else follows it, but also easy to infer that it must be inserted there.
126+
127+
## Metaprogramming Progress
128+
We are making a steady progress developing and improving the metaprogramming features of Dotty. Here are metaprogramming highlights of this release:
129+
130+
- Fix #7189: Do not try to load contents if file does not exist [#7476](https://github.com/lampepfl/dotty/pull/7476)
131+
- Add customizable names for definitions in quotes [#7346](https://github.com/lampepfl/dotty/pull/7346)
132+
- Rename scala.quoted.matching.{Bind => Sym} [#7332](https://github.com/lampepfl/dotty/pull/7332)
133+
- Replace AsFunction implicit class with Expr.reduce [#7299](https://github.com/lampepfl/dotty/pull/7299)
134+
135+
# Let us know what you think!
136+
137+
If you have questions or any sort of feedback, feel free to send us a message on our
138+
[Gitter channel](https://gitter.im/lampepfl/dotty). If you encounter a bug, please
139+
[open an issue on GitHub](https://github.com/lampepfl/dotty/issues/new).
140+
141+
## Contributing
142+
143+
Thank you to all the contributors who made this release possible!
144+
145+
According to `git shortlog -sn --no-merges 0.19.0-RC1..0.20.0-RC1` these are:
146+
147+
```
148+
99 Martin Odersky
149+
64 Nicolas Stucki
150+
16 Nikita Eshkeev
151+
15 Guillaume Martres
152+
9 Robert Stoll
153+
8 Anatolii
154+
5 Liu Fengyun
155+
5 Olivier Blanvillain
156+
3 Miles Sabin
157+
2 Aggelos Biboudis
158+
2 Jamie Thompson
159+
2 Antoine Brunner
160+
2 Ben Elliott
161+
2 Guillaume R
162+
1 noti0na1
163+
1 Ashwin Bhaskar
164+
1 Batanick
165+
1 Bojan Dunaj
166+
1 Harpreet Singh
167+
1 Lucas
168+
1 Lucas Jenß
169+
1 Martijn Hoekstra
170+
1 bishabosha
171+
1 brunnerant
172+
```
173+
174+
If you want to get your hands dirty and contribute to Dotty, now is a good time to get involved!
175+
Head to our [Getting Started page for new contributors](https://dotty.epfl.ch/docs/contributing/getting-started.html),
176+
and have a look at some of the [good first issues](https://github.com/lampepfl/dotty/issues?q=is%3Aissue+is%3Aopen+label%3Aexp%3Anovice).
177+
They make perfect entry points into hacking on the compiler.
178+
179+
We are looking forward to having you join the team of contributors.
180+
181+
## Library authors: Join our community build
182+
183+
Dotty now has a set of widely-used community libraries that are built against every nightly Dotty
184+
snapshot. Currently, this includes ScalaPB, algebra, scalatest, scopt and squants.
185+
Join our [community build](https://github.com/lampepfl/dotty-community-build)
186+
to make sure that our regression suite includes your library.
187+
188+
[Scastie]: https://scastie.scala-lang.org/?target=dotty
189+
190+
[@odersky]: https://github.com/odersky
191+
[@DarkDimius]: https://github.com/DarkDimius
192+
[@smarter]: https://github.com/smarter
193+
[@felixmulder]: https://github.com/felixmulder
194+
[@nicolasstucki]: https://github.com/nicolasstucki
195+
[@liufengyun]: https://github.com/liufengyun
196+
[@OlivierBlanvillain]: https://github.com/OlivierBlanvillain
197+
[@biboudis]: https://github.com/biboudis
198+
[@allanrenucci]: https://github.com/allanrenucci
199+
[@Blaisorblade]: https://github.com/Blaisorblade
200+
[@Duhemm]: https://github.com/Duhemm
201+
[@AleksanderBG]: https://github.com/AleksanderBG
202+
[@milessabin]: https://github.com/milessabin
203+
[@anatoliykmetyuk]: https://github.com/anatoliykmetyuk

0 commit comments

Comments
 (0)