- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Scala code style document
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
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










Re: Scala code style document
Gee, I wonder who. :-)
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.
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
Re: Scala code style document
Oops.
Yes. I very much meant the other way round. Sorry for any confusion.
Re: Scala code style document
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
That's exactly what we have by default.
Thanks.
Kind regards,
Ilya
2009/2/12 David MacIver <david [dot] maciver [at] gmail [dot] com>
Re: Scala code style document
Yes, I'd assumed that.
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.
Re: Scala code style document
On Thu, Feb 12, 2009 at 1:22 PM, David MacIver <david [dot] maciver [at] gmail [dot] com> wrote:
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
Re: Scala code style document
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.