Editorials

Coding By Convention Pains

Would you mind if we changed the ID column in your database table SomeTable from SomeTableID to SomeTableId, or better yet, could we simply name it Id? This was a question I received from a developer writing an Object Relational Mapper (ORM) class, adapting objects from and to tables in my database. They were using an ORM tool that uses code by convention to determine the code design for the ORM.

Coding by Convention takes advantage of how things are designed, or named, to allow it to determine how it should behave. This capability is used in many different programming techniques when enhancing or integrating other code with yours.

Personally, I like naming the primary key of my tables using a naming convention of [TableName]ID. I can live with [TableName]Id. But that wasn’t my database convention at the time. I use that naming convention with intention. When using this table as a foreign key in another table, the foreign key column name 9s the same, [TableName]ID, where [TableName] is the name of the foreign table.

Using this naming convention, I don’t have confusion as to what the relationship is between tables. The name of the linking column is the same in both the parent and child table. I can always find which table is the parent because it will be the one having [TableName]ID as the primary key. When diagraming, I don’t have to align relationship lines directly with the columns in the table in order to know what columns are participating in the relationship, nor do I have to modify the column name in the child table to include a prefix of the parent table (as some database schema designers do).

So, I guess I’m a rebel. It seems that if a database is already designed and implemented, it would be easier/better to change your mapping code or template to synchronize with an established convention. Or, maybe I’m just getting old an cranky; unwilling to bend for the good of the crew.

What do you think? Would you change your database schema to simplify an ORM project, or would you ask them to change their convention? Share your thoughts in our comments, or drop an Email to btaylor@sswug.org.

Cheers,

Ben