In many past projects, I observed that people tend to keep database column name as two or three words separated with '_', for example : first_name. However the same column is mapped to Java bean's variable : firstName.
I don't know why people don't keep database field names like firstName but tend to use _ in between. Even if we use iBatis, it is an additional work to define resultmap mapping.
Regards, Jatan
Many databases have case insensitive column and table names (and this used to be even more the case than it is these days), so if you typed camelCasedColumnName
, what you actually ended up with was CAMELCASEDCOLUMNNAME
. Using underscores in your identifiers was much more readable in those databases, and a good practice even in case sensitive ones if you want to be able to change your backend database with a minimum of headaches.
On the code side, camelCase is the convention in Java for field identifiers, but in many other languages underscores are the convention for variable and method names. And there are tools that can convert between CamelCasedNames, underscored_names, or other formats without any additional effort on the developer's part when dealing with databases. (Ruby's ActiveRecord, for example, knows that a NameLikeThis
for a class maps to a name_like_this
for a table in your database.)