I'm developing an application with Python. I want to have a Boolean variable that represent whether something is buy
or sell
but I'm not sure how I should name it. Here are my current ideas:
actually I like the last one the most although it's somehow the ugliest because it tells you all you need to know about it with certainty. However I thought I'd ask some more experienced people to see what is the actual python convention for such situations.
Don't use a Boolean. Use an enum. E.g TransactionType
with instances Buy
and Sell
.
That is unambiguous and far easier to understand.
If you want to persist the data efficiently, the boolean can be a good solution as long as there are only two instances in the enum. However, your code need not be efficient at that level of detail (that's the interpreters job); it needs to be very understandable. The enum achieves that goal far better.