Convention over configuration

January 26, 2011 by: Xavier Perez

Ok, we are sure that convention over configuration it’s the best practice to reduce time, gaining simplicity, and increasing its readibility.

But, what moore ?

I have been working with ORM’s that offers simplicity and also scalability, giving a lot of tools and making easy a complex queries. But… I need more…

Why I must to tell the ORM all the tables I use ?

Why I must to tell the ORM any table/column changes made ?

Why I must to tell the ORM that a column named ’email’ must to be processed as an email, valitated as an email and is a required field ?

Why I must to tell the ORM how to set/get values ?

Why I must to tell the ORM how to get/set a double number, a phone number (varchar), a zip code, a password, a boolean, etc.. etc… etc…

I think that convention must to take care over this, convention must to be the most ussed and most common uses, convention must to be more conventional, leaving the definition any other no conventional matter.

Let’s see an example:

Table Users:

`id` int(11) NOT NULL AUTO_INCREMENT,
`pai_id` int(11) DEFAULT ’34’,
`ent_id` int(11) DEFAULT NULL,
`name` varchar(32) DEFAULT NULL,
`surname` varchar(32) DEFAULT NULL,
`email` varchar(50) DEFAULT NULL,
`telephone` varchar(20) DEFAULT NULL,
`telephone2` varchar(20) DEFAULT NULL,
`address` varchar(50) DEFAULT NULL,
`postal_code` varchar(6) DEFAULT NULL,
`prv_id` int(11) DEFAULT NULL,
`pob_id` int(11) DEFAULT NULL

By default, any field end by ???_id will be a foreing key.
By default, any field as ‘%email%’ will be managed as ’email’ rules.
By default, any field as ‘%telephone% will be managed as ‘phone number’ rules.
By default, any field as ‘%postal_code% will be managed as ‘postal code’ rules.

Only special fields, as ‘international_postal_code’ could be different as normal ‘postal code’. International postal code can have any prefix (2 code language, 3 code language, 2/3 code internation call, etc), adn will the only field that you must to configure to tell that this must NOT to be as supposed.

Continue next week….

Filed under: Other

Leave a Reply