Scala question.
I create constants to use in place of strings for session variables, so I can avoid typos and leverage code completion. But the definition of those constants feels like it could be better. Less redundant.
`
trait CommonSessionConstants {
def $( s : String ) = “${” + s + “}”
// debug
val REQUEST_URI = “REQUEST_URI”
val RESPONSE_STATUS = “RESPONSE_STATUS”
val RESPONSE_BODY = “RESPONSE_BODY”
val REDIRECT_TO = “REDIRECT_TO”
// other
val DATETIME = “DATETIME”
}
`
`
object SessionConstants extends CommonSessionConstants {
// project-specific constants
}
`
Usage:
`
import SessionConstants._
.check( header(“Location”).saveAs( REDIRECT_TO ) )
…
http( … ).get( $(REDIRECT_TO) )
`
I like the way it is used. But I wonder if there is a better way of defining the constants. What is the most scala-esque way of doing this?