views:

222

answers:

7

We are going to develop a new system over a legacy database(using .NET C#).There are approximately 500 tables. We have choosen to use an ORM tool for our data access layer. The problem is with namig convention for the entities.

The tables in the database have names like TB_CUST - table with customer data, or TP_COMP_CARS - company cars. The first letter of prefix defines the modul and the second letter defines its relations to other tables.

I would like to name the entities more meaningful. Like TB_CUST just Customer or CustomerEntity. Of course there would be a comment pointing to its table name.

But the DBA and programer in one person, dont want names like this. He wants to have the entities names exactly the same to the table names. He is saying that he would have to remember two names and it would be difficult and messy. I have to say his not really familiar with the principles of OOP.

But in case of an entity name like TP_COMP_CARS there should be methods names like Get TP_COMP_CARS or SaveTP_COMP_CARS..I think this is unreadable and ugly.

So please tell me your opinion. Who is right and why.

Thank you in advance

+6  A: 

The whole Idea of ORM tools, is to avoid the need of remmembering database objects. We Usually create a database class with all the table and column names, so no one needs to remmeber anything, and the ORM should map database "names" to normal entities.

Although it is subjective, in my opinion you are right and he is wrong....

Dani
+1 That's the point of ORM: Getting rid of braindead table naming conventions :)
Yann Schwartz
it is some pain for the existing DBA/Programmer guy, he has his nice world and for him it's change. But in this case I value carefully chosen domain names in the Business Logic over saving him some work.
djna
A: 

Who is going to work mostly with the new code? That person should decide the naming convention IMHO.

Personally of course I would go for your solution because as has already been mentioned, if you use ORM you don't need to hit the DB directly often.

Petros
I don't agree with the first part. What if the person who's going to work with the code changes?
Bruno Rothgiesser
Look I am the first who would choose to change the names to fit the paradigm. I just wanted to pinpoint this side of the coin too. I am not insisting on this though. I hope I don't get more negatives for my opinion :-)
Petros
+1 Why a down vote? Person has just expressed his opinion, which precisely is your question. Misinformation may be a down-vote, but disagreements are not supposed to be a down-vote.
KMan
A: 

As a compromise you could use names like TB_CUST where act directly with the database but then use names like Customer for your Data Transfer Objects. Writing good code involves creating an abstraction of any datasources you might be working with. Have GetTB_CUST() throughout your code is a little like having GetTB_CUSTFromThatSQLDatabaseWeHave() dotted around the place.

jammus
A: 

The naming conventions used in two different domains simply don't align. Java, for example, hasa very well defined rules/conventions for Class names and field names, where capitalisation is significant. In general, your application may be ported to a completely different Database with a different naming standard, it's not reasonable to demand alignment of names in Business Logic with names in Database. Consider a slightly more complex mapping, one Entity may not correspond to one Table.

And, really, come on ...

 Customer == TB_CUST

That is just not so hard! I'm with you, makes the names meaningful in the code and map in the ORM. The learning for the DBA/Programmer should not be that painful, my guess is that it's one of those things that feels much worse in the anticipation than the reality.

djna
and what about GC_SU and S_OE or TB_FAKOE ?? I have no idea whats in there :-)
Thats precisely why you should get rid of the original names from the DB. If it requires to look up some out of date doc to know the meaning of a field, it's likely you'll make mistakes while coding. So you can see the ORM mapping as the actual doc on the meaning of the fields. Much better.
Yann Schwartz
A: 

I personally hate table names like that, but it's a legacy system and I'm sure the DBA doesn't feel like renaming the tables. Renaming the tables could be an option. You would just have to create views representing the old table names so that your legacy system keeps running while you develop your new system. If this is not an option you can use the ORM to map table names to entity names. Or you can abstract your ORM away in a data access layer and define nice entity names in your domain model, having your DAL do the name conversion.

klausbyskov
A: 

"I have to say his not really familiar with the principles of OOP.

But in case of an entity name like TP_COMP_CARS there should be methods names like Get TP_COMP_CARS or SaveTP_COMP_CARS..I think this is unreadable and ugly.

So please tell me your opinion. Who is right and why."

Which names are given to the things your IT systems manages has absolutely nothing to do with "the principles of OOP".

The same holds for which names are given to "standard" "getter and setter" methods : those are just agreements and conventions, not "principles of OOP".

The issue is a certain kind of "ergonomics" (and thus also the self-documenting value) of the code.

It is true that getTP_COMP_CARS looks ugly (though not, as you claim, "unreadable"). It is also true that if you start adhering to "more modern" naming conventions, then there will have to be someone somewhere who will have to maintain a mapping between the names that are synonymous. (And it is untrue that names such as TP_COMP_CARS are less self-documenting than full "natural-language-words" names : usually such names are constructed from a VERY SMALL set of mnemonic words that are used over and over again with the same meaning, making it more than easy enough for anyone to remember them.)

There is no right and wrong about this. Names like that were the usual convention in the days before the ones we live in now. At least, those names usually had the benefit of being case-insensitive, as opposed to the braindead (because case-sensitive) naming rules that are imposed upon us by so-called "more modern" systems.

Twenty years from now, people will call the naming conventions we use these days "braindead" too.

Erwin Smout
A: 

If there are 500 tables in the database - you've already got a challenge keeping those names straight. Hopefully, you've got metadata and some graphical models that describe them more meaningfully.

When you create the next 500 ORM objects - you'll have another challenge. Even if you give them meaningful names it's still too many to really hope that all will be obvious. So, now you've got 2 problems.

If there's no way to link those two sets of 500 tables together - then you've got 3 problems. Think about debugging performance of queries in the ORM, and going to the DBA with names that he doesn't recognize. Think about your carefully crafted names - that then must be ignored when you create reports that hit the database directly.

So, I'd try very hard to use the database names in the ORM. But I would tweak a few things:

  • if a name is too cryptic to understand - I'd work with the DBA to improve its name. An easy way to transition to better names is through views. Ideally you get rid of the original confusing name eventually tho.
  • changing from underscores to camelcase, etc shouldn't be considered a change to the name - it's just a change to the separator. So, use the appropriate name for your language.
  • the database prefixes can probably be dropped - they're actually just attributes of the table name that have been "denormalized" and grafted onto the name. They may be necessary to avoid duplication if they indicate a subsection of the model, but in general may be be as important.
KenFar