osx-config-check icon indicating copy to clipboard operation
osx-config-check copied to clipboard

Why use const?

Open Cabalist opened this issue 9 years ago • 3 comments

I have never seen const.py used before in Python. I am curious as to why you are using this instead of say globals or a config file?

Genuinely curious, this is not meant as criticism.

Cabalist avatar Jul 16 '16 04:07 Cabalist

Globals or a config file would work fine. One thing I like about this const class is that it's actually immutable, and can't be reassigned in some underhanded way, making secure code review easier.

http://code.activestate.com/recipes/65207-constants-in-python/?in=user-97991

What do you think -- does it make the code better or worse?

kristovatlas avatar Jul 16 '16 15:07 kristovatlas

Personally it seems pretty un-pythonic (which is a slippery term) and unnecessarily complicates this code. I don't think there is any danger in having a mutable object for the config. The code that you linked is from a different era of python.

If immutable-ness is still important look into a namedtuple to store config values. That said I would really recommend the configparser module. It will separate your config variables out into a file and integrate well into turning this into an app that takes arguments on the command line.

My 2¢

Cabalist avatar Jul 19 '16 17:07 Cabalist

I see. Thanks for the feedback! I will mull it over a bit.

I've used configparser before, but will probably put off using it since it takes a lot more development time than to read from sys.argv, and there's only demand for a single command-line arg so far.

kristovatlas avatar Jul 19 '16 18:07 kristovatlas