NCommander / vaksina

MIT License
35 stars 5 forks source link

Why not use dict() instead of JSON for some code checks #18

Closed peseoane closed 2 years ago

peseoane commented 2 years ago

Hi,

Good afternoon,

A suggestion that comes to me to improve the code cleanliness and how to work with it.

    def get_vaccine_by_identifier(self, identifier):
        """Gets a vaccine by the identifier in the JSON file"""
        for vaccine in self._known_vaccine_list:
            if vaccine.vaccine_identifier == identifier:
                return vaccine

        raise ValueError("Unknown vaccine")

If we pass self._known_vaccine_list as a dict() we could just use

    def get_vaccine_by_identifier(self, identifier):
        """Gets a vaccine by the identifier in the JSON file"""
        if  vaccine.vaccine_identifier in VACCINE_DICTIONARY:
                return True, vaccine
        else:
                raise ValueError("Unknown vaccine")

And dictionaries can be changed to JSON whenever we want, but we gain speed and stability when working with them.

It's a suggestion, maybe it has a dark side that I don't see.

Let's not forget that dictionaries can also be serialised, stored and loaded from main memory to persistent memory.

Regards

peseoane commented 2 years ago

Ok, I had misunderstood a part of the code, it makes sense to me what is being done, I close the proposal.