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

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #15

    We use ID for the PK and a Ref postfix for FK's So Car.id is the PK Car.BrandRef is a FK to the Brand table

    System.IO.Path.IsPathRooted() does not behave as I would expect

    1 Reply Last reply
    0
    • C Chris Maunder

      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 code

      namespace Module
      {
      class Object
      {
      ...

      cheers, Chris Maunder

      CodeProject.com : C++ MVP

      M Offline
      M Offline
      Member 96
      wrote on last edited by
      #16

      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.

      1 Reply Last reply
      0
      • C Chris Maunder

        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 has Object.ObjectID Object.Stuff Object.AnotherObjectID (FK) AnotherObject has AnotherObject.AnotherObjectID AnotherObject.DifferentStuff FK naming is then all nice and neat and obvious.

        cheers, Chris Maunder

        CodeProject.com : C++ MVP

        L Offline
        L Offline
        Leah_Garrett
        wrote on last edited by
        #17

        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

        C T 2 Replies 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

          C Offline
          C Offline
          Clickok
          wrote on last edited by
          #18

          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:

          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

            C Offline
            C Offline
            Chris Maunder
            wrote on last edited by
            #19

            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

            1 Reply Last reply
            0
            • C Chris Maunder

              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

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #20

              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

              1 Reply Last reply
              0
              • C code frog 0

                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:

                R Offline
                R Offline
                RoswellNX
                wrote on last edited by
                #21

                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

                S C 2 Replies 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

                  E Offline
                  E Offline
                  Ennis Ray Lynch Jr
                  wrote on last edited by
                  #22

                  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

                  1 Reply Last reply
                  0
                  • R RoswellNX

                    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

                    S Offline
                    S Offline
                    Shog9 0
                    wrote on last edited by
                    #23

                    RoswellNX 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

                    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

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #24

                      I got to the point where I named a key StinkinKey, but now I tend to use KeyId.

                      1 Reply Last reply
                      0
                      • C code frog 0

                        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:

                        G Offline
                        G Offline
                        Gary R Wheeler
                        wrote on last edited by
                        #25

                        Rex: Decaf, man.


                        Software Zen: delete this;

                        Fold With Us![^]

                        C 1 Reply Last reply
                        0
                        • C Chris Maunder

                          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

                          G Offline
                          G Offline
                          Gary R Wheeler
                          wrote on last edited by
                          #26

                          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;

                          Fold With Us![^]

                          1 Reply Last reply
                          0
                          • R RoswellNX

                            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

                            C Offline
                            C Offline
                            code frog 0
                            wrote on last edited by
                            #27

                            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:

                            R 1 Reply Last reply
                            0
                            • G Gary R Wheeler

                              Rex: Decaf, man.


                              Software Zen: delete this;

                              Fold With Us![^]

                              C Offline
                              C Offline
                              code frog 0
                              wrote on last edited by
                              #28

                              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:

                              G 1 Reply Last reply
                              0
                              • C code frog 0

                                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:

                                G Offline
                                G Offline
                                Gary R Wheeler
                                wrote on last edited by
                                #29

                                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;

                                Fold With Us![^]

                                C 1 Reply Last reply
                                0
                                • G Gary R Wheeler

                                  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;

                                  Fold With Us![^]

                                  C Offline
                                  C Offline
                                  code frog 0
                                  wrote on last edited by
                                  #30

                                  I think that's what happened to that one group in Waco who tried it with a Mac.:rolleyes:

                                  1 Reply Last reply
                                  0
                                  • C code frog 0

                                    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:

                                    R Offline
                                    R Offline
                                    RoswellNX
                                    wrote on last edited by
                                    #31

                                    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

                                    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

                                      H Offline
                                      H Offline
                                      Howard Richards
                                      wrote on last edited by
                                      #32

                                      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

                                      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

                                        V Offline
                                        V Offline
                                        Vagif Abilov
                                        wrote on last edited by
                                        #33

                                        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.

                                        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

                                          S Offline
                                          S Offline
                                          Stick
                                          wrote on last edited by
                                          #34

                                          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.

                                          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