One of the biggest things we need to deal with in applications is trust in other parts of the system. How much trust do you have in the calling application? How much trust do you have in the common routines that you call?
For instance, you've created a method that will take an XML stream and use it to update a row in a table. How much faith do you have that the calling application has sent you the proper types? Should you check everything to ensure that strings are strings and numbers are numbers? Do you double check to ensure that dates are actually valid dates and that the time listed actually exists?
I used to work for a manager that insisted that every time your method gets invoked it should double check all of the data being passed in before it did any work: verification was the first thing you did. Being young and full of myself, I didn't follow that rule because, well, to be honest, I was writing both sides and I knew what I was passing myself!!! Fast forward a couple of years and someone else is maintaining the code. Well, they made some changes that didn't follow the rules and, in production, it blew up horribly because the method did not verify that the correct type of data was being passed. Being on the support side I was called in to troubleshoot and instantly recognized what the problem was and the solution that was required. A quick compile and test and the application no longer died horribly, but gave a nice, easy to understand error message.
With today's modern languages much of this work is taken care of for you by the development tool during design time as you need to ensure that you are calling with the correct types, or the the compiler won't even compile your application for you. However, there is a problem when you are using XML or if you are taking in a string and attempting to use it as a numeric value. This is of particular concern to user interfaces as pretty much everything you retrieve from the UI is a string that you need to convert and use.
A user interface should place no trust in the end user entering in the correct type of data into the text box. But, how much trust do you place in one piece of code calling another piece of code? I guess that depends on whether or not you are going to be the person maintaining the code for the lifetime of the application. If you are, then I guess you can trust the code. If you aren't then being paranoid may be beneficial.
No comments:
Post a Comment