Standard Java getter and setter convention
We should either use getXXX() or XXX() consistently throughout NOVA.
I'm a fan of getXXX() myself.
As scala dev (same as @calclavia) we were promoting xxx() if there is not setter and getXxx()/setXxx(value) in case that setter exists.
I much prefer getXXX() and setXXX() because:
- It's java convention: this is not a scala framework,
- Groovy transforms getters/setters into properties
What we could do:
Use set and get for everything in NOVA. Create implicit wrappers in Scala.
I don't know if that is possible only with implicit but some macro blackmagic might work.
:+1: for @calclavia's suggestion. Groovy can mixin to classes, I assume scala can too? Implicit classes?
implicit class SomethingWrapper(peer: Something){
def xxx: X = peer.getX
def xxx_=(x: X) = peer.setX(x)
def yyy: Y = peer.getY
def yyy_=(y: Y) = peer.setY(y)
}
import nova.Something
import novascala.SomethingWrapper
val something = new Something(xx, yy)
something.xxx = null
println(something.yyy)
There is also a BeanProperty annotation in Scala, but it's work in other way, adds Beans getters/setters to val/var 's
@anti344 problem is that you would need wrapper per class. Macros should be able to solve it.
Not a macros then, full-blown scalac plugin, for converting field/field_= calls to getField/setField calls where possible. Also think of IDE support for this
Macros are supported by all Scala IDEs and it is much cleaner solution as it is just code generation (it has nothing in common with C macros).
From the scala docs I don't see a way to add methods with macros...
You cam write implicit classes/methods with macros.
But how would you.., oh i see on IRC, m-kay
Use overloaded XXX. XXX() for getter, XXX(YYY) for setter.
Alright, so I think we should settle for standard Java conventions. setX() getX()
I agree with Calclavia, after all, NOVA is written in Java (primarily). This was already talked about a lot and whole NOVA team agreed that getXXX() and setXXX(YYY) will be used (correct me if I'm wrong).
On 10 September 2015 at 20:15, Calclavia [email protected] wrote:
Alright, so I think we should settle for standard Java conventions. setX() getX()
— Reply to this email directly or view it on GitHub https://github.com/NOVA-Team/NOVA-Core/issues/175#issuecomment-139332043 .
I personally prefer variable() for getters of immutable (final) values and getVariable()/setVariable(value) for getters/setters of mutable variables.