I have been developing software for the past three years, but I just recently awoke to how ignorant I am of good practices. This has led me to begin reading the book Clean Code, which is turning my life upside for the better, but I am struggling to get insight into some of the best approaches for writing my programs.
I have a Python program in which I...
- use argparse
required=True
to enforce two arguments, which are both file names. the first is the input file name, the second is the output file name - have a function
readFromInputFile
which first checks to see that an input file name was entered - have a function
writeToOutputFile
which first checks to see that an output file name was entered
My program is small enough that I am lead to believe that the checking in #2 and #3 is redundant and should be removed, thus freeing both functions from an unnecessary if
condition. However, I have also been led to believe that "double-checking is ok" and may be the right solution in a program where the functions could be called from a different location where the parsing of arguments does not occur.
(Also, if the read or write fails, I have a try except
in each function to raise an appropriate error message.)
My question is: is it best to avoid all redundant condition checking? Should the logic of a program be so solid that checks need only be made once? Are there any good examples that illustrate this or the converse?
EDIT: Thank you all for the answers! I have learned something from each. Seeing so many perspectives gives me a much better understanding of how to approach this problem and determine a solution based on my requirements. Thank you!