Erdaron
August 15th, 2008, 10:09 PM
I started working on a library (again - personal use and learning experience, I imagine other people have done the same thing and better) to deal with 3D vectors.
I decided that a good format would be a list [float, float, float, str] where the last str variable specifies to what coordinate system the vector belongs (spherical, cartesian, etc.).
But then I came across this problem - how rigorously should I check data passed to the library to make sure it's in the correct format?
As an added challenge, I wanted to catch errors, if possible, in the library, so I could pass the exception back with a helpful message as to what went wrong.
Pretty much every function checks to make sure that coordinate types match, because otherwise this would be a silent error, using something like this (library is in Python):
if v1[3] != v2[3]:
raise TypeError, 'Coordinate systems do not match.'
The tradeoff, it seems, is that if I rigorously check every vector to make sure it's in the right format, that would really slow down performance.
I also thought of using the try statement to execute various vector-vector operations, and if something goes wrong, use except clause to send offending vectors to an examining function.
So I guess I'm soliciting advice on how much care should I take, and how much freedom I should leave the programmer to screw up on his own.
I decided that a good format would be a list [float, float, float, str] where the last str variable specifies to what coordinate system the vector belongs (spherical, cartesian, etc.).
But then I came across this problem - how rigorously should I check data passed to the library to make sure it's in the correct format?
As an added challenge, I wanted to catch errors, if possible, in the library, so I could pass the exception back with a helpful message as to what went wrong.
Pretty much every function checks to make sure that coordinate types match, because otherwise this would be a silent error, using something like this (library is in Python):
if v1[3] != v2[3]:
raise TypeError, 'Coordinate systems do not match.'
The tradeoff, it seems, is that if I rigorously check every vector to make sure it's in the right format, that would really slow down performance.
I also thought of using the try statement to execute various vector-vector operations, and if something goes wrong, use except clause to send offending vectors to an examining function.
So I guess I'm soliciting advice on how much care should I take, and how much freedom I should leave the programmer to screw up on his own.