Naming conventions: Object ID
-
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
-
John Cardinal wrote:
I name the database and code *exactly* the same
That makes sense technically, but from a readability point of view it's difficult because code allows namespaces, table naming doesn't. So we name our tables
ModuleObject
and the codenamespace Module
{
class Object
{
...cheers, Chris Maunder
CodeProject.com : C++ MVP
Hey whatever works for you! :) I need to do a *lot* of dynamic sql in my code so I have a lot of mixed sql and code all over in my business objects layers and I've never found readability a problem but the main thing is to have some sort of standard and stick to it rather than the exact way it's done. Note also that I keep things short because I work in several different db layers and I'm up against a limitation of (IIRC) 30 something characters for FireBird so I'm always using lowest common denominator standards.
-
Well, clearly I'm not actually calling the table and object "Object" :D. Close your eyes and pretend that I wrote "
CarefullyAndCleverlyNamedObject
" everywhere you read "Object
" ;) We stick to Object.ObjectID for the following reason: Object hasObject.ObjectID
Object.Stuff
Object.AnotherObjectID
(FK) AnotherObject hasAnotherObject.AnotherObjectID
AnotherObject.DifferentStuff
FK naming is then all nice and neat and obvious.cheers, Chris Maunder
CodeProject.com : C++ MVP
Yeah the best way to solve naming convention issues is to ask the opinons of more developers. ;-) Having had to detangle some odd FK naming I like the consistant PK and FK naming approach. Consistant naming in layers is also very helpful. But consistancy is the key, so if someone is using ID for PK then I will use that. -- Leah
-
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
Welcome to War Database x OOP :laugh: I like of the second approach (Object.ObjectId and NOT Object.Id). If you use Object.ObjectId and to another fields you use the exact naming of table fields, do you will by example, use one List in a ASP.Net GridView directly, and update your database table without need worry about mapping of the field names, and a lot of another advantages what, if you wish I can list to you. :rolleyes:
:sigh: Still searching for a good resource to LEARN English grammar ... :~
For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.(John 3:16) :badger: -
Yeah the best way to solve naming convention issues is to ask the opinons of more developers. ;-) Having had to detangle some odd FK naming I like the consistant PK and FK naming approach. Consistant naming in layers is also very helpful. But consistancy is the key, so if someone is using ID for PK then I will use that. -- Leah
Leah_Garrett wrote:
Yeah the best way to solve naming convention issues is to ask the opinons of more developers
lol.
cheers, Chris Maunder
CodeProject.com : C++ MVP
-
You ever tried selling the "we'll use this convention here, and a different convention over there" to Dmitry*? :D * Dmitry is one of the devs working the The Rewrite. He accepts no compromise. He scares us.
cheers, Chris Maunder
CodeProject.com : C++ MVP
No, I generally try more productive pursuits, such as walking on water and reversing gravity.
Christian Graus - C++ MVP 'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
-
In every table that has a generic auto-increment PK I call the field the same name. I always use ThisTableSucksTheDBAIsOnGlueAndNeedsADrugTest as my primary key.
- I guarantee it's unique.
- It's certainly meaningful.
- It's always right. (Even if I'm the DBA.)
- It's very easy to remember.
- Nobody ever asks what it is or what it means. They know it's the primary key and it's never up for debate.
- What I say is final.
- There are no warranties at all express, applied, explicit, implicit or profane.
- My naming convention is inviolate handed down from my fathers, father a Jedi Knight for a 1000 generations who was always known as Darth Constraint.
Questions? Comments? Good!:laugh: For the record: This is post 4,918 :cool:
code-frog wrote:
In every table that has a generic auto-increment PK I call the field the same name. I always use ThisTableSucksTheDBAIsOn_Glue_AndNeedsADrugTest as my primary key. * I guarantee it's unique. * It's certainly meaningful. * It's always right. (Even if I'm the DBA.) * It's very easy to remember. * Nobody ever asks what it is or what it means. They know it's the primary key and it's never up for debate. * What I say is final. * There are no warranties at all express, applied, explicit, implicit or profane. * My naming convention is inviolate handed down from my fathers, father a Jedi Knight for a 1000 generations who was always known as Darth Constraint. Questions? Comments? Good!:laugh: For the record: This is post 4,918 :cool:
:laugh::laugh::laugh: Glue? ouch! bad stuff... On a serious note, it's worse than any kind of muscle relaxant...i know the effects from making the mistake of working with several types the solvent-based chemicals indoors(all at different times). Most of that stuff affects the nervous system, sort of like a shock that comes in one wave and dislodges all emotions, as well as relaxing the muscles at the same time. The effect that causes the loss of muscle tone is actually pretty well documented. Other side effects are pretty product-specific, like some permanent markers (i remember they had the word "king" on the package as a part of the brand name, but i'm not sure if i remember it right) cause shortness of breath, and over a period of several days after the exposure lungs will respond and cause further breathing problems... Roswell
"Angelinos -- excuse me. There will be civility today."
Antonio VillaRaigosa
City Mayor, Los Angeles, CA -
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
I used to use ID however consistency won over and I now use Id. database field: customer_id database table: customer member: customerId; property: CustomerId; Another solution I use often is to provide an interface for objects from the db. In your case all objects would have the following interface: Int64? Id{get;set;} Of course this would not match the db. The reason the db needs the full prefix in the case of id columns is because of joins. You don't want to have to alias every join!
File Not Found
-
code-frog wrote:
In every table that has a generic auto-increment PK I call the field the same name. I always use ThisTableSucksTheDBAIsOn_Glue_AndNeedsADrugTest as my primary key. * I guarantee it's unique. * It's certainly meaningful. * It's always right. (Even if I'm the DBA.) * It's very easy to remember. * Nobody ever asks what it is or what it means. They know it's the primary key and it's never up for debate. * What I say is final. * There are no warranties at all express, applied, explicit, implicit or profane. * My naming convention is inviolate handed down from my fathers, father a Jedi Knight for a 1000 generations who was always known as Darth Constraint. Questions? Comments? Good!:laugh: For the record: This is post 4,918 :cool:
:laugh::laugh::laugh: Glue? ouch! bad stuff... On a serious note, it's worse than any kind of muscle relaxant...i know the effects from making the mistake of working with several types the solvent-based chemicals indoors(all at different times). Most of that stuff affects the nervous system, sort of like a shock that comes in one wave and dislodges all emotions, as well as relaxing the muscles at the same time. The effect that causes the loss of muscle tone is actually pretty well documented. Other side effects are pretty product-specific, like some permanent markers (i remember they had the word "king" on the package as a part of the brand name, but i'm not sure if i remember it right) cause shortness of breath, and over a period of several days after the exposure lungs will respond and cause further breathing problems... Roswell
"Angelinos -- excuse me. There will be civility today."
Antonio VillaRaigosa
City Mayor, Los Angeles, CARoswellNX wrote:
i remember they had the word "king" on the package as a part of the brand name
Eh, those stink. The ones that smell like banana mash are much nicer.
---- Scripts i’ve known... CPhog 1.8.2 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.2 - printer-friendly forums Expand all 1.0 - Expand all messages In-place Delete 1.0 - AJAX-style post delete Syntax 0.1 - Syntax highlighting for code blocks in the forums
-
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
I got to the point where I named a key StinkinKey, but now I tend to use KeyId.
-
In every table that has a generic auto-increment PK I call the field the same name. I always use ThisTableSucksTheDBAIsOnGlueAndNeedsADrugTest as my primary key.
- I guarantee it's unique.
- It's certainly meaningful.
- It's always right. (Even if I'm the DBA.)
- It's very easy to remember.
- Nobody ever asks what it is or what it means. They know it's the primary key and it's never up for debate.
- What I say is final.
- There are no warranties at all express, applied, explicit, implicit or profane.
- My naming convention is inviolate handed down from my fathers, father a Jedi Knight for a 1000 generations who was always known as Darth Constraint.
Questions? Comments? Good!:laugh: For the record: This is post 4,918 :cool:
-
Judah Himango wrote:
FxCop says something.ID (note the all caps) is wrong.
Yep, so I use .ID in SQL where FxCop can't give me a hard time, and Id in code. ;)
cheers, Chris Maunder
CodeProject.com : C++ MVP
Chris Maunder wrote:
Id in code
Blech. For some reason, I've always disliked '
Id
' and 'id
'; it's supposed to be 'ID
', dammit. Sorry. I just finished doing my taxes X|. I'm feeling all middle-aged and irascible :mad:.
Software Zen:
delete this;
-
code-frog wrote:
In every table that has a generic auto-increment PK I call the field the same name. I always use ThisTableSucksTheDBAIsOn_Glue_AndNeedsADrugTest as my primary key. * I guarantee it's unique. * It's certainly meaningful. * It's always right. (Even if I'm the DBA.) * It's very easy to remember. * Nobody ever asks what it is or what it means. They know it's the primary key and it's never up for debate. * What I say is final. * There are no warranties at all express, applied, explicit, implicit or profane. * My naming convention is inviolate handed down from my fathers, father a Jedi Knight for a 1000 generations who was always known as Darth Constraint. Questions? Comments? Good!:laugh: For the record: This is post 4,918 :cool:
:laugh::laugh::laugh: Glue? ouch! bad stuff... On a serious note, it's worse than any kind of muscle relaxant...i know the effects from making the mistake of working with several types the solvent-based chemicals indoors(all at different times). Most of that stuff affects the nervous system, sort of like a shock that comes in one wave and dislodges all emotions, as well as relaxing the muscles at the same time. The effect that causes the loss of muscle tone is actually pretty well documented. Other side effects are pretty product-specific, like some permanent markers (i remember they had the word "king" on the package as a part of the brand name, but i'm not sure if i remember it right) cause shortness of breath, and over a period of several days after the exposure lungs will respond and cause further breathing problems... Roswell
"Angelinos -- excuse me. There will be civility today."
Antonio VillaRaigosa
City Mayor, Los Angeles, CAA friend of mine (M.S. in Mathematics) paid for an entire year of grad school in two weeks. His job to put on this chemical suit and tear down an old chemistry solvent lab. He said it was horrible. The stench came through the suit at times. They had to stop every hour or so and drink a liter of water. (Texas in the summer.) Then suit back up and go back at it. He said the glue and solvents were the worst.:omg:
-
I think I just need to work less. Did you know I'm planning to take over the universe.:-D Rumor has it that you can do it with Linux.:rolleyes::doh:
-
I think I just need to work less. Did you know I'm planning to take over the universe.:-D Rumor has it that you can do it with Linux.:rolleyes::doh:
code-frog wrote:
Rumor has it that you can do it with Linux
That's related to that whole world-domination-by-the-Teletubbies thing, isn't it?
Software Zen:
delete this;
-
code-frog wrote:
Rumor has it that you can do it with Linux
That's related to that whole world-domination-by-the-Teletubbies thing, isn't it?
Software Zen:
delete this;
I think that's what happened to that one group in Waco who tried it with a Mac.:rolleyes:
-
A friend of mine (M.S. in Mathematics) paid for an entire year of grad school in two weeks. His job to put on this chemical suit and tear down an old chemistry solvent lab. He said it was horrible. The stench came through the suit at times. They had to stop every hour or so and drink a liter of water. (Texas in the summer.) Then suit back up and go back at it. He said the glue and solvents were the worst.:omg:
code-frog wrote:
He said it was horrible. The stench came through the suit at times. They had to stop every hour or so and drink a liter of water. (Texas in the summer.) Then suit back up and go back at it. He said the glue and solvents were the worst.:omg:
Well, i'd gladly take the job if it weren't just smells and hot weather. I'm actually pretty immune to chemical smells, but it's a different story with the effects the fumes themselves have on me. I've become almost allergic to a lot of solvents now, since i wasn't careful working with them at first. Like I can't tolerate nail polish because of the acetone. About the same with paint thinner... Roswell
"Angelinos -- excuse me. There will be civility today."
Antonio VillaRaigosa
City Mayor, Los Angeles, CA -
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
Since you asked.. my approach is usually KISS and try not to mangle stuff for the sake of mangling it unless there is a real benefit. I always name tables as plurals. "Customers" contains customers, not 'a single customer' - that's a single ROW of the table. So in your case my table is called "Objects", and PK is ObjectID as in your example. The data layer generates code for classes but converts the plurals to singulars, so the class is called "Object" but the field is still called "ObjectID", and there is a collection class which is called "ObjectCollection", which represents the table. I guess Object.ObjectID is a tautology but this is code we're writing, not English so it doesn't matter. It makes for a few more keystrokes but it keeps things clearer on what you're referring to.. This link http://vyaskn.tripod.com/object_naming.htm[^] was one I looked at when designing my current DB. I avoided using the underscore from their approach as this causes the CLR problems as it's not CLS compliant for names. I do however try to prefix all tables with a similar name to keep them together, e.g. Customers, CustomerServices, CustomerOrders etc.
'Howard
-
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
It gives me a good feeling to know that in far Australia people argue about exactly the same question we have been discussing in Norway today :) We decided to use "XxxxxID" on the fields that come from the database. In other words - "ID", not "Id". Just to have common style. Screw FxCop!
Вагиф Абилов MCP (Visual C++) Oslo, Norway If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them. Jack Handey.
-
In our datebase we have a table called
Object
and it has a primary keyObjectID
. In our code we have an object calledObject
and it has an ID field calledId
. Part of me wants to stay consistent and have the object in code have an ID fieldObject.ObjectId
, while part of me says this is a tautology. What do you guys use?cheers, Chris Maunder
CodeProject.com : C++ MVP
IMHO I would never 'prepend' the name of the object to it like ObjectID or ObjectId as Object.ObjectId is redundant. If I'm asking for a member of that object, I already know I'm in the object. I also tend to always use 'm_' as then all the members are together in suggestion boxes, although I use Visual Assist X with which you can just toggle only members on. I really don't like using the 'm_', and may drop that convention as my experience increases. I would definately try to be consistent with all the objects so you can "know" what it will be named by convention.