Redundant () on non-mutating calls.
strelec opened this issue · 2 comments
Since Scala 3 enforces the distinction between calls without brackets, and with empty parameter list, some calls become somewhat ugly.
For example:
hasChildNodes()
hasAttributes()
It would probably make sense to revisit all methods that use empty parameter lists and unify. Generally, if the method is non-mutating, it should drop the brackets.
Thanks for reporting.
Generally, if the method is non-mutating, it should drop the brackets.
Yes, this is generally good practice for Scala code. However, for Scala.js facades the brackets are an important distinction:
var
,val
anddef
definitions without parentheses all map to field access in JavaScript, whereasdef
definitions with parentheses (even empty) map to method calls in JavaScript.
Via https://www.scala-js.org/doc/interoperability/facade-types.html
Because these are method calls in JavaScript (and not field accesses), we have no choice but to put the brackets.
Indeed, declaring a method with or without ()
makes a semantic difference. Declaring them without ()
would break the meaning of the facade wrt. the JavaScript code behind it. So this very much as designed and must not be changed.