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. Is this an acceptable practice?

Is this an acceptable practice?

Scheduled Pinned Locked Moved The Lounge
jsonquestion
55 Posts 16 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 Colborne_Greg

    It is only one line of code, broken into multiple lines via the _ character.

    <System.Runtime.Serialization.DataMember>
    Private mLastUpdated As DateTime, mLastUpdatedBy As String, mClearanceRequired As Int64, mClearanceIsRequired As Boolean

    D Offline
    D Offline
    Dave Kreskowiak
    wrote on last edited by
    #22

    So what? It seems like you're doing this and your looking for absolution from the community. Again, it's a matter of opinion and in a real environment with coding standards, what you've done may be outlawed.

    A guide to posting questions on CodeProject

    How to debug small programs
    Dave Kreskowiak

    C 1 Reply Last reply
    0
    • C Colborne_Greg

      <System.Runtime.Serialization.DataMember>
      Private mLastUpdated As DateTime, _
      mLastUpdatedBy As String, _
      mClearanceRequired As Int64, _
      mClearanceIsRequired As Boolean

      Visual basic code; class members for serialization - declaring a group of variables as data members.

      F Offline
      F Offline
      Fabio Franco
      wrote on last edited by
      #23

      I don't see any problem with it, as a matter of fact it actually reminds me of C++ member declaration.

      To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

      C 1 Reply Last reply
      0
      • C Colborne_Greg

        <System.Runtime.Serialization.DataMember>
        Private mLastUpdated As DateTime, _
        mLastUpdatedBy As String, _
        mClearanceRequired As Int64, _
        mClearanceIsRequired As Boolean

        Visual basic code; class members for serialization - declaring a group of variables as data members.

        D Offline
        D Offline
        Dan Neely
        wrote on last edited by
        #24

        "It is a vessel of fertilizer, and none may abide its strength."

        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

        C 1 Reply Last reply
        0
        • C Colborne_Greg

          <System.Runtime.Serialization.DataMember>
          Private mLastUpdated As DateTime, _
          mLastUpdatedBy As String, _
          mClearanceRequired As Int64, _
          mClearanceIsRequired As Boolean

          Visual basic code; class members for serialization - declaring a group of variables as data members.

          G Offline
          G Offline
          Gates VP
          wrote on last edited by
          #25

          At a first glance, I find this confusing. In particular because the DataMember attribute actually accepts a constructor parameter. - So if I set the constructor parameter, which field does it apply to? - Likewise, if you want to switch out serializers and use something like Protocol Buffers this syntax simply won't translate. You would need to break out each one as the constructor is required. - On top of this all, there's a mixing of types. I'm not a big fan of the "multi-declaration" syntax, especially when it doesn't save any actual lines like this example. But there are some cases where it is useful. That stated, if you're mixing types on the "multi-declarations", it's time split them out. I wouldn't call this "unacceptable" practice, especially in the context of firing someone over this. I would however call this "non-standard" and "confusing" and ask that it be changed.

          C F 2 Replies Last reply
          0
          • C Colborne_Greg

            Its valid code. Coding practices is the topic.

            P Offline
            P Offline
            patbob
            wrote on last edited by
            #26

            Colborne_Greg wrote:

            Coding practices is the topic

            Coding practices are a form of communication to the next developer to assist them in their understanding of the code. There are no absolutes -- a syntax acceptable to one group might not be acceptable to another group. In general though, use of an oddball syntax in one place in the code is a poor practice. So, the only realistic answer to your question is "it depends". It depends on whether that's the common syntax used throughout the rest of the code, or an oddball one.

            Colborne_Greg wrote:

            Its valid code

            I have three words by way of countering this line of thought: Obfuscated C Contest.

            We can program with only 1's, but if all you've got are zeros, you've got nothing.

            C 1 Reply Last reply
            0
            • P patbob

              Colborne_Greg wrote:

              Coding practices is the topic

              Coding practices are a form of communication to the next developer to assist them in their understanding of the code. There are no absolutes -- a syntax acceptable to one group might not be acceptable to another group. In general though, use of an oddball syntax in one place in the code is a poor practice. So, the only realistic answer to your question is "it depends". It depends on whether that's the common syntax used throughout the rest of the code, or an oddball one.

              Colborne_Greg wrote:

              Its valid code

              I have three words by way of countering this line of thought: Obfuscated C Contest.

              We can program with only 1's, but if all you've got are zeros, you've got nothing.

              C Offline
              C Offline
              Colborne_Greg
              wrote on last edited by
              #27

              I keep a common structure, thank you for a straight answer.

              1 Reply Last reply
              0
              • G Gates VP

                At a first glance, I find this confusing. In particular because the DataMember attribute actually accepts a constructor parameter. - So if I set the constructor parameter, which field does it apply to? - Likewise, if you want to switch out serializers and use something like Protocol Buffers this syntax simply won't translate. You would need to break out each one as the constructor is required. - On top of this all, there's a mixing of types. I'm not a big fan of the "multi-declaration" syntax, especially when it doesn't save any actual lines like this example. But there are some cases where it is useful. That stated, if you're mixing types on the "multi-declarations", it's time split them out. I wouldn't call this "unacceptable" practice, especially in the context of firing someone over this. I would however call this "non-standard" and "confusing" and ask that it be changed.

                C Offline
                C Offline
                Colborne_Greg
                wrote on last edited by
                #28

                This is what it looked like before

                <System.Runtime.Serialization.DataMember>
                Private mLastUpdated As DateTime

                    <System.Runtime.Serialization.DataMember>
                    Private mLastUpdatedBy As String
                
                    <System.Runtime.Serialization.DataMember>
                    Private mClearanceRequired As Int64
                
                    <System.Runtime.Serialization.DataMember>
                    Private mClearanceIsRequired As Boolean
                

                The first example I wrote, stands on in the document, where writing datamember so many times with the word private seems to be a waste of space.

                G D 2 Replies Last reply
                0
                • D Dan Neely

                  "It is a vessel of fertilizer, and none may abide its strength."

                  Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                  C Offline
                  C Offline
                  Colborne_Greg
                  wrote on last edited by
                  #29

                  Refrain for abusive comments

                  D 1 Reply Last reply
                  0
                  • F Fabio Franco

                    I don't see any problem with it, as a matter of fact it actually reminds me of C++ member declaration.

                    To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                    C Offline
                    C Offline
                    Colborne_Greg
                    wrote on last edited by
                    #30

                    right on

                    1 Reply Last reply
                    0
                    • D Dave Kreskowiak

                      So what? It seems like you're doing this and your looking for absolution from the community. Again, it's a matter of opinion and in a real environment with coding standards, what you've done may be outlawed.

                      A guide to posting questions on CodeProject

                      How to debug small programs
                      Dave Kreskowiak

                      C Offline
                      C Offline
                      Colborne_Greg
                      wrote on last edited by
                      #31

                      White space. It's more important to people. Also as a programmer if you do not understand how a compiler is going to handle your code, you might consider another profession.

                      D 1 Reply Last reply
                      0
                      • D Dave Kreskowiak

                        Considering I wasn't commenting on that at all, your post makes no sense. I was merely commenting that the compiler is never responsible for supporting the application, YOU are.

                        A guide to posting questions on CodeProject

                        How to debug small programs
                        Dave Kreskowiak

                        C Offline
                        C Offline
                        Colborne_Greg
                        wrote on last edited by
                        #32

                        I see yes the context of how someone takes a sentence is important. The code is flawless, again the question was about coding practices.

                        D 1 Reply Last reply
                        0
                        • G Gates VP

                          At a first glance, I find this confusing. In particular because the DataMember attribute actually accepts a constructor parameter. - So if I set the constructor parameter, which field does it apply to? - Likewise, if you want to switch out serializers and use something like Protocol Buffers this syntax simply won't translate. You would need to break out each one as the constructor is required. - On top of this all, there's a mixing of types. I'm not a big fan of the "multi-declaration" syntax, especially when it doesn't save any actual lines like this example. But there are some cases where it is useful. That stated, if you're mixing types on the "multi-declarations", it's time split them out. I wouldn't call this "unacceptable" practice, especially in the context of firing someone over this. I would however call this "non-standard" and "confusing" and ask that it be changed.

                          F Offline
                          F Offline
                          Fabio Franco
                          wrote on last edited by
                          #33

                          Gates VP wrote:

                          That stated, if you're mixing types on the "multi-declarations", it's time split them out.

                          They are clearly separated by lines, if they were in the same line, then I would agree with you. As I said in my reply, it resembles a lot C++ declaration like:

                          private:
                          int x;
                          double y;
                          .
                          .
                          .

                          The underscore even act as C++ semi-colon. It doesn't hurt readability as you can clearly see the types at the end of each line. I don't see any confusion, except that someone may be in doubt if the attribute applies only to the first variable or all of them.

                          To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                          G C 2 Replies Last reply
                          0
                          • C Colborne_Greg

                            <System.Runtime.Serialization.DataMember>
                            Private mLastUpdated As DateTime, _
                            mLastUpdatedBy As String, _
                            mClearanceRequired As Int64, _
                            mClearanceIsRequired As Boolean

                            Visual basic code; class members for serialization - declaring a group of variables as data members.

                            D Offline
                            D Offline
                            dg6yhw11
                            wrote on last edited by
                            #34

                            I would say it is not acceptable because your intent is not clear, which makes the code difficult to maintain.

                            C 1 Reply Last reply
                            0
                            • C Colborne_Greg

                              Refrain for abusive comments

                              D Offline
                              D Offline
                              Dan Neely
                              wrote on last edited by
                              #35

                              Refrain from abusive code.

                              Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                              1 Reply Last reply
                              0
                              • D dg6yhw11

                                I would say it is not acceptable because your intent is not clear, which makes the code difficult to maintain.

                                C Offline
                                C Offline
                                Colborne_Greg
                                wrote on last edited by
                                #36

                                The comment above the code in a must inherit class Authorization data members: If Clearance Is Required the user attempting to change the value will have their clearance level validated against the clearance required. Collects who and when this class was last updated by - for data merging such as offline files.

                                1 Reply Last reply
                                0
                                • F Fabio Franco

                                  Gates VP wrote:

                                  That stated, if you're mixing types on the "multi-declarations", it's time split them out.

                                  They are clearly separated by lines, if they were in the same line, then I would agree with you. As I said in my reply, it resembles a lot C++ declaration like:

                                  private:
                                  int x;
                                  double y;
                                  .
                                  .
                                  .

                                  The underscore even act as C++ semi-colon. It doesn't hurt readability as you can clearly see the types at the end of each line. I don't see any confusion, except that someone may be in doubt if the attribute applies only to the first variable or all of them.

                                  To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                  G Offline
                                  G Offline
                                  Gates VP
                                  wrote on last edited by
                                  #37

                                  If you have 35 or 40 of these grouped into one segment, they're going to flow off the screen. If you want to mark just one of them as "public", do you copy/paste this to some other part of the file entirely? How does this affect the attributes? Remember, after you copy/paste the private variable to the public section, the original attributes are on a completely different screen. And you're not instinctively moving the attribute along with the variable.

                                  Quote:

                                  I don't see any confusion, except that someone may be in doubt if the attribute applies only to the first variable or all of them.

                                  That's still confusion. And it's not really useful or purposeful confusion. You save a small number of characters and compile to the exact same IL code (hopefully) while introducing uncertainty for developers. This is the equivalent of doing C++ / C# if blocks without braces. You come back to this problem that actually caused real production issues on iOs: https://www.imperialviolet.org/2014/02/22/applebug.html[^]

                                  C 1 Reply Last reply
                                  0
                                  • D Duncan Edwards Jones

                                    As a general rule, explicit intent is better coding practice than implied intent.

                                    C Offline
                                    C Offline
                                    Colborne_Greg
                                    wrote on last edited by
                                    #38

                                    I rather have white space, but agreed.

                                    1 Reply Last reply
                                    0
                                    • F Fabio Franco

                                      Gates VP wrote:

                                      That stated, if you're mixing types on the "multi-declarations", it's time split them out.

                                      They are clearly separated by lines, if they were in the same line, then I would agree with you. As I said in my reply, it resembles a lot C++ declaration like:

                                      private:
                                      int x;
                                      double y;
                                      .
                                      .
                                      .

                                      The underscore even act as C++ semi-colon. It doesn't hurt readability as you can clearly see the types at the end of each line. I don't see any confusion, except that someone may be in doubt if the attribute applies only to the first variable or all of them.

                                      To alcohol! The cause of, and solution to, all of life's problems - Homer Simpson ---- Our heads are round so our thoughts can change direction - Francis Picabia

                                      C Offline
                                      C Offline
                                      Colborne_Greg
                                      wrote on last edited by
                                      #39

                                      This is actually one line of code, but that is why I break it into multiple lines using the _ character to cheat a little bit, so I only have to write the serialization tag once.

                                      1 Reply Last reply
                                      0
                                      • G Gates VP

                                        If you have 35 or 40 of these grouped into one segment, they're going to flow off the screen. If you want to mark just one of them as "public", do you copy/paste this to some other part of the file entirely? How does this affect the attributes? Remember, after you copy/paste the private variable to the public section, the original attributes are on a completely different screen. And you're not instinctively moving the attribute along with the variable.

                                        Quote:

                                        I don't see any confusion, except that someone may be in doubt if the attribute applies only to the first variable or all of them.

                                        That's still confusion. And it's not really useful or purposeful confusion. You save a small number of characters and compile to the exact same IL code (hopefully) while introducing uncertainty for developers. This is the equivalent of doing C++ / C# if blocks without braces. You come back to this problem that actually caused real production issues on iOs: https://www.imperialviolet.org/2014/02/22/applebug.html[^]

                                        C Offline
                                        C Offline
                                        Colborne_Greg
                                        wrote on last edited by
                                        #40

                                        I write generics my classes are never more then 300 lines of code and if I need more then 4 or so data members I am doing something wrong Also I would never declare a member of a class public, I use properties to expose members. The only reason these are grouped together is so I do not have to write the serialization tag out for each, its cheating a bit.

                                        1 Reply Last reply
                                        0
                                        • C Colborne_Greg

                                          This is what it looked like before

                                          <System.Runtime.Serialization.DataMember>
                                          Private mLastUpdated As DateTime

                                              <System.Runtime.Serialization.DataMember>
                                              Private mLastUpdatedBy As String
                                          
                                              <System.Runtime.Serialization.DataMember>
                                              Private mClearanceRequired As Int64
                                          
                                              <System.Runtime.Serialization.DataMember>
                                              Private mClearanceIsRequired As Boolean
                                          

                                          The first example I wrote, stands on in the document, where writing datamember so many times with the word private seems to be a waste of space.

                                          G Offline
                                          G Offline
                                          Gates VP
                                          wrote on last edited by
                                          #41

                                          So to clarify, you're saying that "saving space" is more important than "providing clarity" and "avoiding bugs"? If you're trying to save space why are you: 1. Using Private at all? That's the default, just take it out. 2. Using that little "m" in the prefix. Why not just lower-case the first letter? ("lastUpdated") 3. Using full words when you could abbreviate everything? ("lstUpd") 4. Not importing the System.Runtime.Serialization on the file? Then you could just type ""! If "saving space" is really important, why aren't you doing it everywhere? And at the end of the day, all of this code is functionally equivalent, right? So it all compiles to the same IL. I'm just not understanding the "save space" argument here.

                                          C 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