python - Should class-specific "constants" still be declared at module level? -
in pep 8, it's stated "constants defined on module level […]". makes sense standard library, constants tend pertain entire module rather particular class (e.g. zlib.max_wbits
or re.unicode
). i'm writing module, however, constants related individual classes.
the module designed allow python programs work application-specific serialization format in blocks of data arranged "chunks" , chunks further arranged "regions". dimensions of chunks , regions useful constants expose, , had been doing class properties until chanced across line in pep 8.
i'm inclined leave them (pep 8 also says "foolish consistency hobgoblin of little minds", after all), want make sure won't too badly breaking users' expectations doing so. (the module hasn't yet been released, backwards compatibility isn't issue.)
for reference, "pep 8" style…
chunk_size_x = 16 chunk_size_z = 16 region_size_x = 32 region_size_z = 32 def chunk(object): # magic happens here def region(object): # magic happens here
…and current, "class-based" style…
def chunk(object): size_x = 16 size_z = 16 # magic happens here def region(object): size_x = 32 size_z = 32 # magic happens here
clearly, class-based constants belong in class. stick second example. remember pep8 not handed down almighty. it's ideas: tradition, reason , experience can temper meaning of scripture.
hungrarian_prefix_notation needless. that's 1 reason have classes.
Comments
Post a Comment