Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Naming conventions: Object ID

Naming conventions: Object ID

Scheduled Pinned Locked Moved The Lounge
c++comarchitecturequestion
45 Posts 30 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Chris Maunder

    In our datebase we have a table called Object and it has a primary key ObjectID. In our code we have an object called Object and it has an ID field called Id. Part of me wants to stay consistent and have the object in code have an ID field Object.ObjectId, while part of me says this is a tautology. What do you guys use?

    cheers, Chris Maunder

    CodeProject.com : C++ MVP

    C Offline
    C Offline
    cmk
    wrote on last edited by
    #41

    I used to use: DB: Object.Id Code: Object.Id Now i use (last 4-5 yrs): DB: Object.ObjectId Code: Object.ObjectId I can't remember the reason for the switch, but there was one. Aside from whatever the reason was, i find Ta.TaId == Tb.TaId gives me a warm fuzzy. The lack of symmetry in Ta.Id == Tb.TaId bothers me. As far as DB vs Code, i don't see a compelling reason to change the name going from one to the other. It also makes script gen-ing one from the other a bit of a pain.

    ...cmk Save the whales - collect the whole set

    1 Reply Last reply
    0
    • C Chris Maunder

      In our datebase we have a table called Object and it has a primary key ObjectID. In our code we have an object called Object and it has an ID field called Id. Part of me wants to stay consistent and have the object in code have an ID field Object.ObjectId, while part of me says this is a tautology. What do you guys use?

      cheers, Chris Maunder

      CodeProject.com : C++ MVP

      J Offline
      J Offline
      Jasmine2501
      wrote on last edited by
      #42

      I generally do this application-wide. If something represents the exact same thing, then it has the exact same name. I have contact_id in my database and it's used as a primary key and foreign key, but as long as it represents the ID of a contact, that's what I call it, and I never use the name contact_id for anything else. If I add a special context to it, I keep the base, but add to the variable name (sender_contact_id, recipient_contact_id, etc.). I keep this convention in stored procs and application client code as well. Makes it kinda funny when you see: where contact_id = @contact_id ... but any SQL programmer worth a damn should understand that.

      "Quality Software since 1983!"
      http://www.smoothjazzy.com/ - see the "Programming" section for freeware tools and articles.

      1 Reply Last reply
      0
      • C Chris Maunder

        In our datebase we have a table called Object and it has a primary key ObjectID. In our code we have an object called Object and it has an ID field called Id. Part of me wants to stay consistent and have the object in code have an ID field Object.ObjectId, while part of me says this is a tautology. What do you guys use?

        cheers, Chris Maunder

        CodeProject.com : C++ MVP

        A Offline
        A Offline
        andy_fcm
        wrote on last edited by
        #43

        As an example, this is what I do: class Customer Customer.Id Customer.Name Customer.Address Customer.Stuff Customer.DifferentStuff class Order Order.Id Order.CustomerId Order.Quantity Order.Stuff Order.DifferentStuff So, as you can see, Id is the primary key of Customer and CustomerId is the FK of Order

        1 Reply Last reply
        0
        • C Chris Maunder

          In our datebase we have a table called Object and it has a primary key ObjectID. In our code we have an object called Object and it has an ID field called Id. Part of me wants to stay consistent and have the object in code have an ID field Object.ObjectId, while part of me says this is a tautology. What do you guys use?

          cheers, Chris Maunder

          CodeProject.com : C++ MVP

          J Offline
          J Offline
          JohnGriffiths101
          wrote on last edited by
          #44

          Chris Maunder wrote:

          Part of me wants to stay consistent and have the object in code have an ID field Object.ObjectId

          ---- I try to be totally consistent:- ---- [table_name].[field_name] [class_name].[field_name] Product.Id Product.Name Order.Id Order.Product_Id * foreign key becomes [table_name].[foreign_table_name]_[field_name] [class_name].[foreign_class_name]_[field_name] * Notice how . becomes _ ---- * field names Id type is unique number By type is person ie Order.CreatedBy Date type is datetime ie Order.CreatedDate ----

          1 Reply Last reply
          0
          • L Leah_Garrett

            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

            T Offline
            T Offline
            Tim Schwallie
            wrote on last edited by
            #45

            I usually ask the psycho guy...what's his name...Freud.;P

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups