Reputation: 1472
Hi this is more of a style question. I have a small script that works with a socket, and I have constants (i know they are not real constants, but heyy, at least they are in capital) that declare some properties,
# Port address for the serial port to read the weight from PADDR = '/dev/ttyUSB0' # socket address uri, backlog, and buffer SADDR = 'localhost:28000' BACKLG = 0 BUFF = 1024 # for cross platform compatibility use epoch in unix time EPOCH_START = datetime(1970, 1, 1)
I however might add functionality to change these by parsing arguments. So the question is, should I just change these directly when parsing arguments?
or should I be nice and use the above constants as defaults and change the options which I would then pass around to functions who need them? This seems a bit too much, but then again, I don't want to write code that will be frowned upon :)
Upvotes: 2
Views: 119
Reputation: 198294
Have DEFAULT_PADDR
as a constant; but paddr
as a variable with DEFAULT_PADDR
as its default value. Do not change a "constant", even if it is just a matter of style - your code becomes cryptic.
I.e. for now, do this:
DEFAULT_PADDR = '/dev/ttyUSB0'
# ...
paddr = DEFAULT_PADDR
then you can change paddr
when you add argument parsing.
Upvotes: 3