This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Scala code style document

7 replies
Ilya Sergey
Joined: 2009-02-02,
User offline. Last seen 42 years 45 weeks ago.
Hello, all.

From some people I heard about mythical document with Scala code conventions.
If it really exists we would like to make such formatting options default fo IntelliJ plugin. So, could someone provide it?
Thanks.

Kind regards,
Ilya
DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document
On Thu, Feb 12, 2009 at 8:42 PM, Ilya Sergey <ilya [dot] sergey [at] jetbrains [dot] com> wrote:
Hello, all.

From some people I heard about mythical document with Scala code conventions.

Gee, I wonder who. :-)
 

If it really exists we would like to make such formatting options default fo IntelliJ plugin. So, could someone provide it?
Thanks.

Kind regards,
Ilya

I think it's called "the compiler source code" I'm afraid. At least that's what I seem to recall being told when I started committing.

The big things I'm aware of are:

- tabs, not spaces
- two space indents
- open braces don't start a new line
-  /* */ comments are only used for scaladoc method comments, line comments are used elsewhere (the cynical might note that "comments are not used elsewhere" could also reasonably be inferred from parts of the compiler source code)
- type annotations are spaced as foo: Bar

Not sure what else.
Ilya Sergey
Joined: 2009-02-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document
Hi, David.

Gee, I wonder who. :-)

I meant this post by David Pollak (to be precise, its last part with suggestions :).
http://blog.lostlake.org/index.php?/archives/91-IntelliJ-update-its-still-a-piece-of-junk-but-Scala-support-isnt-bad.html

- tabs, not spaces
- two space indents
- open braces don't start a new line
- type annotations are spaced as foo: Bar

That's exactly what we have by default.
Thanks.

Kind regards,
Ilya

2009/2/12 David MacIver <david [dot] maciver [at] gmail [dot] com>
On Thu, Feb 12, 2009 at 8:42 PM, Ilya Sergey <ilya [dot] sergey [at] jetbrains [dot] com> wrote:
Hello, all.

From some people I heard about mythical document with Scala code conventions.

Gee, I wonder who. :-)
 

If it really exists we would like to make such formatting options default fo IntelliJ plugin. So, could someone provide it?
Thanks.

Kind regards,
Ilya

I think it's called "the compiler source code" I'm afraid. At least that's what I seem to recall being told when I started committing.

The big things I'm aware of are:

- tabs, not spaces
- two space indents
- open braces don't start a new line
-  /* */ comments are only used for scaladoc method comments, line comments are used elsewhere (the cynical might note that "comments are not used elsewhere" could also reasonably be inferred from parts of the compiler source code)
- type annotations are spaced as foo: Bar

Not sure what else.

DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document
On Thu, Feb 12, 2009 at 9:18 PM, Ilya Sergey <ilya [dot] sergey [at] jetbrains [dot] com> wrote:
Hi, David.

Gee, I wonder who. :-)

I meant this post by David Pollak (to be precise, its last part with suggestions :).
http://blog.lostlake.org/index.php?/archives/91-IntelliJ-update-its-still-a-piece-of-junk-but-Scala-support-isnt-bad.html

Yes, I'd assumed that.
 

- tabs, not spaces
- two space indents
- open braces don't start a new line
- type annotations are spaced as foo: Bar

That's exactly what we have by default.

Don't know what David was thinking of then! You'll have to ask him.

Oh, for what it's worth, one thing I've noticed is that people tend not to use semicolons. This is pretty inconsistently applied though.
David Pollak
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document


On Thu, Feb 12, 2009 at 1:22 PM, David MacIver <david [dot] maciver [at] gmail [dot] com> wrote:
On Thu, Feb 12, 2009 at 9:18 PM, Ilya Sergey <ilya [dot] sergey [at] jetbrains [dot] com> wrote:
Hi, David.

Gee, I wonder who. :-)

I meant this post by David Pollak (to be precise, its last part with suggestions :).
http://blog.lostlake.org/index.php?/archives/91-IntelliJ-update-its-still-a-piece-of-junk-but-Scala-support-isnt-bad.html

Yes, I'd assumed that.
 

- tabs, not spaces
- two space indents
- open braces don't start a new line
- type annotations are spaced as foo: Bar

That's exactly what we have by default.

Don't know what David was thinking of then! You'll have to ask him.

Oh, for what it's worth, one thing I've noticed is that people tend not to use semicolons. This is pretty inconsistently applied though.

Apparently Julien Wetterwald wrote one when he was at EPFL.  When he joined the Lift project, he advocated use of the document.  He wrote a post about it here: http://groups.google.com/group/liftweb/msg/b02f9cd72e9fe78a?hl=en

I've pinged Julien and introduced him to Ilya, but Julie hasn't followed up.

Thanks,

David



--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document
On Thu, Feb 12, 2009 at 9:35 PM, David Pollak <feeder [dot] of [dot] the [dot] bears [at] gmail [dot] com> wrote:
Don't know what David was thinking of then! You'll have to ask him.

Oh, for what it's worth, one thing I've noticed is that people tend not to use semicolons. This is pretty inconsistently applied though.

Apparently Julien Wetterwald wrote one when he was at EPFL.  When he joined the Lift project, he advocated use of the document.  He wrote a post about it here: http://groups.google.com/group/liftweb/msg/b02f9cd72e9fe78a?hl=en

I'm not sure this can really be regarded as canonical. Particularly given that this is the first time I've seen anything resembling it. :-) Additionally, it doesn't seem to be followed at all closely in the compiler or standard library sources.

1. A brief inspection suggests that this is not the way matches are aligned in the compiler. The convention seems to be
def foo(stuff : Stuff) = stuff match {
  case Thing => ... 
}

So the indentation is as described but the line breaking is not.

2. This definitely isn't adhered to. New lines and same line cases are mixed all over the place. (I'm fine with that. It looks totally reasonable to me.)

3. Couldn't say off the top of my head. It's not IDE relevant anyway.

4. No. The standard convention I've seen most people use (including the library and compiler sources) is that toStuff and isThing are used but setName and getName are not. Not really IDE relevant unless the refactoring support in IDEA is much further along than I thought.

Other 4. Sure. This seems good practice. I'm not sure if the compiler actually uses it, but it's common enough. Again not IDE relevant.

5. Whether or not it's standard (I'm not sure it is. It's certainly *used*, but I don't know that it's used at all consistently), this is a pretty controversial one. Also not IDE relevant.
Iulian Dragos 2
Joined: 2009-02-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document

On Feb 12, 2009, at 10:11 PM, David MacIver wrote:

> The big things I'm aware of are:
>
> - tabs, not spaces

I always thought it's the other way around! :)

iulian

>
> - two space indents
>
> - open braces don't start a new line
> - /* */ comments are only used for scaladoc method comments, line
> comments are used elsewhere (the cynical might note that "comments
> are not used elsewhere" could also reasonably be inferred from parts
> of the compiler source code)
> - type annotations are spaced as foo: Bar

>
>
> Not sure what else.

--
Iulian Dragos
--
http://lamp.epfl.ch/~dragos

DRMacIver
Joined: 2008-09-02,
User offline. Last seen 42 years 45 weeks ago.
Re: Scala code style document
On Fri, Feb 13, 2009 at 8:24 AM, Iulian Dragos <iulian [dot] dragos [at] epfl [dot] ch> wrote:

On Feb 12, 2009, at 10:11 PM, David MacIver wrote:

The big things I'm aware of are:

- tabs, not spaces

I always thought it's the other way around! :)


Oops.

Yes. I very much meant the other way round. Sorry for any confusion.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland