Hi, all,
I have a ‘pad’ method which returns a justified string, with rjust being the default. Either a ‘match’ or multi-if statement can be used to test for the desired justification, and I’m not sure if there should be three tests: ‘c’; ‘l’; ‘_’ / ‘else’; or, four: ‘r’; ‘c’; ‘l’; ‘_’ / ‘else’.
The concern is overhead (granted, tiny, but potentially present). Since rjust is the default, with the ‘3’ test match we’re almost always making more comparisons before settling on the pad direction. With the ‘4’ test match, we’re repeating the ‘r’ code.
Though repetitive code is not explicitly discussed in PEP 8, the ‘3’ test match looks to be more ‘Pythonic’.
Performance-wise, though, the ‘4’ test match might be better to use.
Thoughts?