accessor naming convention.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

accessor naming convention.

Rama Patria Himawan-2
I was wondering if there's a good naming convention to write an accessor of class constructor
since 
def x = x
doesn't work
but 
class Point(x: Int, y: Int){
def getX
def getY
}
doesn't feel really fit either.

and 
class Point(_x: Int, _y: Int){
def x = _x
def y = _y
}
also doesn't seem well.

Is there any better suggestion?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: accessor naming convention.

Muhammet Alay
Just make them val or use case classes.

class Point(val x: Int, va y: Int)
val p
= new Point(1,2)
p
.x
p
.y
// or
case class Point(x: Int, y: Int)
val p
= Point(1,2)
p
.x
p
.y



6 Kasım 2014 Perşembe 08:40:20 UTC+2 tarihinde Rama Patria Himawan yazdı:
I was wondering if there's a good naming convention to write an accessor of class constructor
since 
def x = x
doesn't work
but 
class Point(x: Int, y: Int){
def getX
def getY
}
doesn't feel really fit either.

and 
class Point(_x: Int, _y: Int){
def x = _x
def y = _y
}
also doesn't seem well.

Is there any better suggestion?

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: accessor naming convention.

Rama Patria Himawan-2
In reply to this post by Rama Patria Himawan-2
Aw..., damn, what kind of sorcerry is this....
~back to refactoring ~(' - '~)

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: accessor naming convention.

Jerzy Muller
You can add any kind of 'description' in class primary constructor: 'val', 'var', 'protected[mypackage] val' or '@Annotated("Yay") private[this] val'. 

It's called "promoting constructor argument to field" and it's really handy.

On Thursday, November 6, 2014 10:46:40 AM UTC+1, Rama Patria Himawan wrote:
Aw..., damn, what kind of sorcerry is this....
~back to refactoring ~(' - '~)

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.