I want to arrange to compute a value that will not change after initialization.
I'd use const, but Go restricts consts to built-in types, IIUC.
So I figured I'd use var
, and compute their initial values in init()
var (
// ScreenBounds is the visible screen
ScreenBounds types.Rectangle
// BoardBounds is the total board space
BoardBounds types.Rectangle
)
func init() {
ScreenBounds := types.RectFromPointSize(
types.Pt(-ScreenWidth/2, 0),
types.Pt(ScreenWidth, ScreenHeight))
BoardBounds := ScreenBounds
BoardBounds.Max.Y += TankSpeed * TotalFrames
}
Which is pretty good - but is there a way to "lock" the values once computed, other than to change the vars to unexported names, and then uses function-accessors to return their values?