There is a dictionary in my class with informative, short string constants as keys that identify certain parts of the solution, like "velocity", "death_star_power_output". My colleague suggested that I use VELOCITY="velocity"
and DEATH_STAR_POWER_OUTPUT="death_star_power_output"
to index into this dictionary throughout the program, because it's the practice.
While I know such practices from other programming languages, where they serve a pragmatic purpose - that is to fail-fast in case of misspelling of the string - in Python it's the same one way or the other. Both:
value = dictionary["death_star_powder_output"]
and
DEATH_STAR_POWER_OUTPUT="death_star_power_output" [...] value = dictionary[DEATH_STAR_POWDER_OUTPUT]
will fail at the same time. Please notice the misspelling of POWER
as POWDER
. Is there some official guideline pertaining to this kind of practice in Python?