Open ivan-pi opened 2 years ago
Maybe we should also make the return code more concrete and have info
point to the incorrect argument rather than just raising a general input error (similar like done in Lapack).
I'm generally in favor of making the error codes more specific. The only downside I see is this will likely "invalidate" the current usage instructions and also won't necessarily be back compatible, requiring consumers to modify their programs; essentially we'd be breaking the API.
Any breaking changes would have to be communicated clearly.
We could introduce a compile time DEBUG
flag (via the preprocessor), which would produce verbose error output if enabled. This would not break the established error codes.
From Recommendations To Write (Slightly More) Readable And (Thus) Robust Code 7:
(originally a suggestion from @interkosmos posted at Discourse)
The current modularized minpack source code, includes sections for checking the input parameters like this one taken from
lmder1
:Here in the "easy" driver there is only level of indentation, so it's not as problematic, but for the actual routines which do the work, getting rid of one level of indentation would make them easier on the eye.
The solution is to return early, per the advice above:
Since Fortran does not short-circuit expressions I guess it also makes sense to separate the condition. (For correct input parameters, all the conditionals should be false, but in the case not, we might save a few evaluations and exit early.) This might also just by a personal preference of mine, that is I dislike long logical expressions and/or line continuation: