|
Trying to understand an idiomatic approach to a set-once lazy value for a struct. I have a simple struct: code:
Should I: 1. Pass in an instance of a seeded *rand.Rand() to IsShiny and only calculate it if o.shiny == nil 2. Create a constructor that accepts *rand.Rand() and do the dice roll during construction My goal is to be able to test the IsSiny function and make sure the `shiny` field can't be changed after it's set. edit: also, the dice roll does not need to be perfectly random Fluue fucked around with this message at 03:56 on Sep 5, 2021 |
# ¿ Sep 5, 2021 03:51 |
|
|
# ¿ May 11, 2024 07:26 |
|
Thank you both! Good suggestion to use an internal constructor.
|
# ¿ Sep 5, 2021 16:51 |