Validation techniques Flashcards
1
Q
In her source code, Cerie must perform three validation techniques on a specific input. What sequence should she follow, and what’s the reasoning behind it?
A
Cerie should prioritize the existence check, followed by the type check and then the range check.
Checking existence first prevents unnecessary type and range checks on empty inputs. Additionally, verifying the data type before the range check avoids potential runtime errors for incompatible data types.
2
Q
What are the three validation techniques?
A
Type:
Used to confirm the data type of a given input
Range:
Used to ensure that a given input falls within specific allowable limits or values
Existence:
Verifies if an input contains data