Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Is there such a thing as too much data validation?

by dooberwah (Pilgrim)
on Jan 03, 2002 at 03:16 UTC ( [id://135842]=perlmeditation: print w/replies, xml ) Need Help??

Greetings,
  I'm working on two applications, a client and a server. Currently I have both of them checking to make sure user submitted value is legal. They check against duplicate user names and fields with nothing in it. Because I have it on both the client and the server I'm given a bit of redundancy, but I'm wondering what price I'm paying for it. I obviously want to have data validation on the server, or someone could modify the client to submit invalid data. Obviously if I only had it check once it would be faster. Is it possible to validate your data too much?

-Ben Jacobs (dooberwah)
http://dooberwah.perlmonk.org
"one thing i can tell you is you got to be free"

  • Comment on Is there such a thing as too much data validation?

Replies are listed 'Best First'.
Re: Is there such a thing as too much data validation?
by Masem (Monsignor) on Jan 03, 2002 at 03:33 UTC
    You can never go wrong in checking too much data, though as you state, there does become a tradeoff with efficiency and data validation. Ideally, every sub you write should thoroughly check the data that is submitted and error out if there is something wrong, but in practice, there are cases that are sufficiently harmless to warent skipping over those checks, such as allowing an undef value to go by if you are simply checking for non-zero values in a list of numbers.

    That said, it's probably most important to make sure that the data that is coming into the server to be correct, as opposed to delegating error checking in the client. As good examples, I refer to Quake 3 and any other multi-player game; because of widespread cheating, these engine are built not to trust anything that is on the client side, and thus initiates various checks on data that is sent, MD5-like checks on various libraries used, and similar features to make sure that the client version is only using what the server will accept.

    Similarly, if you are going to be collecting data from the outside world, you should make sure the server is tight on exactly what it will take, and let the format on the client side be a little slack. Obviously, you want to make sure the client format is tight enough not to cause the client side to have problems, and some checks may be useful to avoid repetitious and annoying resending of large data blocks, but otherwise, let the client format be loose.

    Doing it this way also means that if you change the server to improve or tighten certain restrictions, you don't have to worry about having clients change their systems; just have some preestiablished mechanism for allowing the clients to understand the new change and reporting the error.

    -----------------------------------------------------
    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
    "I can see my house from here!"
    It's not what you know, but knowing how to find it if you don't know that's important

      Wasn't "3-tier architecture" suppose to
      be the solution to this sort of thing?

      Another trade-off you make when you validate
      the heck out of everything is that you lose
      maintainability.
      It would be nice for people who will maintain
      your code that you do your validation in "one place"
      "One place" meaning that your validation code be
      easy to find and maintain.


      --
      Write all your code as if all your operations
      and maintenance programmers are axe murders that
      know your address!

      Never?

      Should the validation rules need to change, having the old ones exist in 5 places may be a maintainance problem. So you may wish to try to centralize where checks happen so that it is easier to centralize where the tests are stored. (Whether this is true depends on what you are doing, how your codebase is organized, etc.)

Re: Is there such a thing as too much data validation?
by jlongino (Parson) on Jan 03, 2002 at 05:10 UTC
    Both Masem and rbc make good points, but as in everything else to do with programming, there is no one solution fits all and there will always be tradeoffs involved.

    If you're writing a Web application that requires a good deal of validation and you implement none of it on the client side, then you better expect to take a considerably greater number of hits on your server than had you done a few simple checks on the client side. Not to mention floating all that data back and forth between the two and aggravating the hell out of end users with a slow connection.

    We shouldn't lose sight of the fact that customers pay our salaries and alienating them for the sake of programmer convenience is not good business (unless you happen work for Oracle).

    --Jim

Re: Is there such a thing as too much data validation?
by Rich36 (Chaplain) on Jan 03, 2002 at 05:10 UTC
    In addition to what's been stated, what you can gain by client side checking is better usability. Web forms are a good example. Using something like JavaScript, checking can be done very quickly on the client side. This saves on the number of calls to the server application by stopping the client from running the server application with incorrect data and allows the user to see their mistakes right away without having to wait for a process to run - which would display an error about the incorrect data - then having to go back and do it again.
    But like you point out, someone could modify the client (turn off JavaScript, etc.). So server-side checking remains very necessary as well.
    Rich36
    There's more than one way to screw it up...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://135842]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 14:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found