decimal icon indicating copy to clipboard operation
decimal copied to clipboard

Zero should not be exposed to the public

Open Yuanwe opened this issue 3 years ago • 5 comments

Zero should not be exposed to the public, which will lead to someone being able to modify Zero, it is recommended to adjust

Yuanwe avatar Dec 25 '21 03:12 Yuanwe

It's debatable, but probably you are right. At least such constant/variable should not be used in any of decimal methods. Currently, I see a single usage of this const in ExpTaylor method. As making this const/var private would be considered as breaking change, I will probably refactor all places in code where it was used.

mwoss avatar Dec 26 '21 22:12 mwoss

It's debatable, but probably you are right. At least such constant/variable should not be used in any of decimal methods. Currently, I see a single usage of this const in ExpTaylor method. As making this const/var private would be considered as breaking change, I will probably refactor all places in code where it was used.

Thanks !

Yuanwe avatar Dec 27 '21 02:12 Yuanwe

This really is debatable. In principle I would agree. However, the Go standard library has widespread use of var "constants" (that are not constant) and all sorts of things will go wrong if you meddle with their values. The understanding is that you should not; if you do it's your responsibility.

So exposing Zero seems consistent with most other Go APIs. It might also be helpful to expose One as well.

rickb777 avatar Jan 20 '22 11:01 rickb777

(aside: ideally Go would have immutable values that would allow such var expressions to be really constant; however the language does not have this capability)

rickb777 avatar Jan 20 '22 11:01 rickb777

Thanks for explaining how it looks like in the std lib Rick! :) Now I wonder what would be the best idea here, as at one point this library would probably have other constants like Pi, E, One, etc as global variables.

mwoss avatar Jan 25 '22 00:01 mwoss