Re: `new Foo` vs `new Foo()`
Jon Pretty <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <CAE45xchx9X_baUx8G3MNjbtxr4KByERcwX46YLdKYB=rAcyQHQ@mail.gmail.com> |
I tend to include the parentheses for a couple of reasons: firstly because case classes require the parens, and by association I justify that classes should too, and secondly because instantiating a new instance of a class is side-effecting, so the "method" which does that (i.e. the constructor) should look like a side-effecting method. Additionally, for some reason, I prefer to write `new Foo().bar` rather than `(new Foo).bar`. I think the reason is that I have a slight discomfort at starting an expression with an opening parenthesis, and I've taught myself to give the `new` in `new Foo().bar` higher precedence than the `.`, even though this is counterintuitive to other parsing rules. Jon On 13 July 2015 at 21:20, Rex Kerr <[email protected]> wrote: > That's the convention I use. I've seen both with and without parens in > e.g. the Scala library code base. > > --Rex > > On Mon, Jul 13, 2015 at 12:06 PM, Seth Tisue <[email protected]> wrote: > >> Is there consensus on this? Not sure whether to merge. >> >> https://github.com/scala/scala.github.com/pull/344 >> >> Seth >> >> -- >> You received this message because you are subscribed to the Google Groups >> "scala-language" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/d/optout. >> > > -- > You received this message because you are subscribed to the Google Groups > "scala-language" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- Jon Pretty | @propensive -- You received this message because you are subscribed to the Google Groups "scala-language" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.