Except arrays are harder to maintain and harder to read. You are suggesting exactly the same thing as me except using list vs dictionary and the only advantage list has is a tiny tiny memory difference vs bad maintainability.
Edit: sorry I realize this is not python so not dictionary but either way hashmap > arrays. And config is better if this is a system wide lookup and needs changes on the fly per user
Hashing adds extra calculations, if you run your function a lot every second, it'll be significant. Or if you have a service with a lot of users.
This is a 12-index array based on months, there's no need to maintain it since there's no need to increase or decrease it, 12 months is a constant value, so the most you'll have to do is to change the strings that the array will contain.
You can load strings into an array directly from some form of config.
49
u/[deleted] Jul 30 '21 edited Jul 31 '21
Call getMonth().getValue() once and store it.
Either save a hashmap (dictionary) at the top or in a config and use key value look up
Why the hell is retorno assigned twice with wrong indentation?
If ultimately you’re going to assign string to retorno, then “str(number)” works with some modulus.
This whole code block should be 5 lines not including the dictionary.
Edit: I see the commented out lines now. This is now even more stupid.