Spacing inside one line methods

Is it possible to configure formating so that spaces just after '{' and before '}' are placed for one line methods like this:

object Test {
  def func() {<space>println("test")<space>}
}

5 comments
Comment actions Permalink

I created an issue. http://youtrack.jetbrains.net/issue/SCL-2839

Best regards,
Alexander Podkhalyuzin.

0
Comment actions Permalink

Why use the braces at all? They're superfluous.


Randall Schulz

0
Comment actions Permalink

Do you mean that the following form is preffered:

object Test {
  def func() = println("test")
}

?

Actually I have a method that returns Unit, and it calls some other method returning Unit.

0
Comment actions Permalink

Andrey,

Yes, by many people it is. I usually put the body of single-expression methods on a separate line:


object Test {
  def func() =
    println("test")
}

Also, since I'm the pedantic sort:

  • The def keyword is for defining methods, not functions.
  • The empty parentheses are not needed, though if you omit then in the definition, you may not use them when calling the method while if you include them in the definition you may omit them when calling the method.
  • I most cases, it's advisable to be explicit about the return type of a method. One reason is that the inferred type can be too narrow. E.g., if you return a HashMap, that will be the method's inferred type, but you probably want it to be Map in that case.



Randall Schulz

0
Comment actions Permalink

All syntax purists may check this :)

0

Please sign in to leave a comment.