Closed
Description
In modifying loadsave.py
for CIFTI
file format, I found three design choices that made it more challenging for me to understand and modify code:
- The logic for whether a file is of each Image type is contained in a single function, not modularized into each image (yet the load/save functionality is).
- Image type / file extension associations is duplicated between
load
andsave
functions. - The list of available file formats is duplicated (in imports, then again in the explicit logic of
load
andsave
, each).
I propose the following redesign (which I think is relatively simple):
- Each Image class should declare class variable
valid_ext
(valid filename extensions) and class functionis_image(filename)
(which returnsTrue
if the given filename is of the Image class. loadsave.py
should have a global tuple of all image classes.load
andsave
should simply loop through this list, should not have any image-specific code.
Pros:
- This should improve code modularity, readability, maintainability, and avoid errors in adding new formats.
- It gives a clear interface for determining file Image type.
Cons:
- This design will have a small time cost in opening files when a file extension is ambiguous about the file type, and the file type isn't the most common for that file extension.
- It gives more structure to determining image type, which could be detrimental in the future.
Thoughts?
Metadata
Metadata
Assignees
Labels
No labels