I was trained in SQL years ago and was encouraged to use lower-case
letters with words separated for emphasis using the underscore
character, for example:
customer_num, employee_id, invoice_line, transaction_code
I've stuck with this approach ever since, but now that I make use of
oo programming the general standard is to name oo instance variables
without underscores and capitalising all words except the first for
emphasis, such as:
customerNum, employeeId, invoiceLine, transactionCode
(I appreciate that this will mean quoting the identifiers in SQL
statements)
However, bridging the gap between relational databases and oo
programming means that when binding table column names to object
variable names, I really need to pick one or the other (you may
disagree but that's my aim).
So, when it comes to naming columns, what are most of you using?
Why?
I don't see a reason (nor a restriction) why you need to use the column names from the database as the variable names in your program.
Thomas
You're right, of course. I've partially implemented a Facade pattern
which takes care of the translation via a ColumnMap so that the
database column names are different from the program variable names.
> I've stuck with this approach ever since, but now that I make use of
> oo programming the general standard is to name oo instance variables
> without underscores and capitalising all words
Not really. In some languages, but they are despised in Python for
instance (see PEP8)
> except the first for emphasis, such as:
> customerNum, employeeId, invoiceLine, transactionCode
Don't do that, please :-)
If upper case identifiers are ugly in SQL, the mixed-case ones are
directly spawned by Cthulhu, and treated differently by each vendor.
> However, bridging the gap between relational databases and oo
> programming means that when binding table column names to object
> variable names, I really need to pick one or the other (you may
> disagree but that's my aim).
Unfortunately, we don't bridge any gap by directly mapping columns to
attributes/methods - or there wouldn't be any gap at all.
> So, when it comes to naming columns, what are most of you using?
I would use lower_case for object attributes as well, if there is no
sound reason to do otherwise.