Lack of switch alternative
Closed this issue · 1 comments
uroboro commented
The if-elif alternative for the lack of a switch statement in Python forces the construction of blocks of code like the following:
https://github.com/wstyres/carify-python/blob/master/carify.py#L74-L104
https://github.com/wstyres/carify-python/blob/master/carify.py#L131-L160
I'd like to suggest the usage of dictionaries to replace these blocks with structures presented next.
Using lines 74-81 as replacement example,
if width == 20:
insertAppIconIntoDictionaryForSize(imagePath, data, "20x20", "ipad", "1x", outputPath);
elif width == 29:
insertAppIconIntoDictionaryForSize(imagePath, data, "29x29", "ipad", "1x", outputPath);
elif width == 40:
insertAppIconIntoDictionaryForSize(imagePath, data, "20x20", "iphone", "2x", outputPath);
insertAppIconIntoDictionaryForSize(imagePath, data, "20x20", "ipad", "2x", outputPath);
insertAppIconIntoDictionaryForSize(imagePath, data, "40x40", "ipad", "1x", outputPath);
dictionary = {
"20": [( "20x20", "ipad", "2x" )],
"29": [( "29x29", "ipad", "2x" )],
"40": [( "20x20", "iphone", "2x" ), ( "20x20", "ipad", "2x" ), ( "40x40", "ipad", "1x" )],
}
values = dictionary.get(f"{width}")
for value in values:
dims, model, scale = value
insertAppIconIntoDictionaryForSize(imagePath, data, dims, model, scale, outputPath);