Normalization function

Here is the concept from the DB normalization theory:

The third normal form is violated when the non-key field is a fact about another non-key field.

Does it make sense to use a similar concept for functions / function parameters?


Consider the following function:

function validate(field, rule_name, rule_value);

// Usage

validate("password", "min_length", 6);
validate("password", "matches_regex", "/^\S+$/");

In this exemplary function, the third parameter describes the second and does not seem to be β€œrelated” to the first. This is like a denormalized function.

I don’t know if I am articulating this right, but I can notice an analogy between table names and table fields in DB, function names and function parameters.

If such an analogy makes sense, wouldn't it also make sense for function designers to borrow concepts from DB normalization theory?

+5
3

"", . , / , .

-, , :

function validate(field, rule);

// Usage

validate("password", MinLengthRule(6));
validate("password", RegExRule("/^\S+$/"));
+3

. ( , ), Rule, .

+1

. 6 min_length. - .

, , .

0
source

All Articles