Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
GeneralRe: I'm in a weird mood ... PinmvpRichard MacCutchan14-Dec-12 4:41 
GeneralRe: I'm in a weird mood ... PinmemberRoger Wright14-Dec-12 5:09 
GeneralHow do you do it... PinmemberMarco Bertschi14-Dec-12 4:09 
GeneralRe: How do you do it... PinmemberDeathByChocolate14-Dec-12 4:15 
JokeRe: How do you do it... PinmemberMarco Bertschi14-Dec-12 4:18 
GeneralRe: How do you do it... PinmemberDeathByChocolate14-Dec-12 4:19 
GeneralRe: How do you do it... PinmemberNagy Vilmos14-Dec-12 4:20 
GeneralRe: How do you do it... PinmvpOriginalGriff14-Dec-12 4:42 
GeneralRe: How do you do it... Pinmember d@nish 14-Dec-12 4:17 
GeneralRe: How do you do it... PinmemberDeathByChocolate14-Dec-12 4:18 
GeneralRe: How do you do it... Pinmember d@nish 14-Dec-12 4:23 
GeneralRe: How do you do it... PinmvpRichard MacCutchan14-Dec-12 4:41 
GeneralRe: How do you do it... PinmemberMarco Bertschi14-Dec-12 5:08 
GeneralRe: How do you do it... PinprotectorMarc Clifton14-Dec-12 4:52 
So, the first non-flippant response:
 
First, recognize that validating inputs is a "pattern" for which you might want a general purpose solution. Second, recognize that there are a variety of solutions that you may want to support, resulting in several kinds of implementations:
 
1) Use the input control to ensure that non-valid data is never entered - create specialized controls that let you do things like range checking, excluding invalid characters, validation by regex, etc.
 
2) Use metadata to specify in the code itself what the validation logic should be, either "constants" to specify things like ranges or "typeof" that instantiates a validator class containing a validation method.
 
3) If the class maps to a database, provide enough information to the underlying ORM to perform the validation when the record is created.
 
4) Use the database itself, either in the schema definition (which is limited) or with PL/SQL code and insert / update triggers.
 
5) Create a "class-schema", possibly in XML, which maps the fields of the class to methods or validation information.
 
6) Use self-validating types. Rather than "string", use a type that defines exactly what the behavior is that you want for that string. So, for example, you might have a type "Phone" that obviously is going to do very different validation than "surname."
 
Some of these approaches require reflection, some do not, and depending where the data needs to validated (on user input for example, or validating millions of records in a DB) the performance hit of reflection is acceptable, in other scenarios it is not, so you want something else.
 
My preference is to push the issue to the source - whatever is generating the data (user input, for example) should perform the validation there so that you can guarantee that the data being put into the object is already correct, and also to use more concrete types that define the validation, formatting, etc., rather than the more abstract and general-purpose types like "string" or "int".
 
Marc

AnswerRe: How do you do it... PinmemberRavi Bhavnani14-Dec-12 5:39 
GeneralA little weekend- optimization contest PinmemberVuNic14-Dec-12 3:47 
GeneralRe: A little weekend- optimization contest Pinmemberharold aptroot14-Dec-12 4:02 
GeneralRe: A little weekend- optimization contest Pinmember_Peeves14-Dec-12 4:05 
GeneralRe: A little weekend- optimization contest PinmemberChris Meech14-Dec-12 4:07 
GeneralRe: A little weekend- optimization contest PinmemberSimon_Whale14-Dec-12 4:08 
GeneralRe: A little weekend- optimization contest PinmemberChris Meech14-Dec-12 4:37 
GeneralRe: A little weekend- optimization contest PinmemberBig Daddy Farang14-Dec-12 7:12 
GeneralRe: A little weekend- optimization contest PinmemberChris Meech14-Dec-12 7:50 
GeneralRe: A little weekend- optimization contest PinmemberDeathByChocolate14-Dec-12 4:20 
JokeRe: A little weekend- optimization contest PinmemberVuNic14-Dec-12 4:30 
GeneralRe: A little weekend- optimization contest PinmvpOriginalGriff14-Dec-12 4:09 
GeneralRe: A little weekend- optimization contest PinmemberSimon_Whale14-Dec-12 4:12 
GeneralRe: A little weekend- optimization contest PinmemberDeathByChocolate14-Dec-12 4:16 
GeneralRe: A little weekend- optimization contest PinmvpOriginalGriff14-Dec-12 4:24 
GeneralRe: A little weekend- optimization contest PinmemberDeathByChocolate16-Dec-12 18:42 
JokeRe: A little weekend- optimization contest PinmemberVuNic14-Dec-12 4:33 
GeneralRe: A little weekend- optimization contest PinmvpOriginalGriff14-Dec-12 4:40 
GeneralRe: A little weekend- optimization contest PinmvpJohn Simmons / outlaw programmer14-Dec-12 4:27 
GeneralRe: A little weekend- optimization contest PinmemberVuNic14-Dec-12 4:28 
GeneralRe: A little weekend- optimization contest Pinmemberpeterchen14-Dec-12 4:32 
GeneralRe: A little weekend- optimization contest PinprotectorMarc Clifton14-Dec-12 4:54 
GeneralRe: A little weekend- optimization contest [modified] PinmemberDexterus14-Dec-12 5:15 
GeneralRe: A little weekend- optimization contest PinmemberBert Mitton14-Dec-12 5:24 
GeneralRe: A little weekend- optimization contest PinmemberPIEBALDconsult14-Dec-12 22:40 
GeneralRe: A little weekend- optimization contest [modified] PinmemberPIEBALDconsult14-Dec-12 16:44 
GeneralWhy is it that when I see "View Unanswered Questions" on the menu ... PinmemberDeathByChocolate14-Dec-12 3:30 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberNagy Vilmos14-Dec-12 3:42 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberDeathByChocolate14-Dec-12 3:48 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberProgramFOX14-Dec-12 3:52 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberSimon_Whale14-Dec-12 4:02 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberDeathByChocolate14-Dec-12 4:09 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberSimon_Whale14-Dec-12 4:11 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... PinmemberDeathByChocolate14-Dec-12 4:12 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pinmember_Peeves14-Dec-12 4:07 
GeneralRe: Why is it that when I see "View Unanswered Questions" on the menu ... Pinmember d@nish 14-Dec-12 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.141220.1 | Last Updated 20 Dec 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid