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. C# code survey

C# code survey

Scheduled Pinned Locked Moved The Lounge
csharpquestioncomtestinghelp
47 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.
  • S Super Lloyd

    Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

    public class FooDto
    {
    public T1 Property1 { get; set; }
    // ....
    public T24 Property24 { get; set; }
    }
    // ....
    class MyFooClass
    {
    private T1 property1;
    // ....
    private T24 property24;

    public FooDto ToDto()
    {
        return new FooDto()
        {
            Property1 = property1,
            //....
            Property24 = property24,
        };
    }
    

    }

    how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

    public class FooDto
    {
    public FooDto(T1 value1 /** 24 values later */, T24 value24)
    {
    Property1 = value1;
    // .....
    Property24 = value24;
    }

    public T1 Property1 { get; }
    // ....
    public T24 Property24 { get; }
    }
    // ....
    class MyFooClass
    {
    private T1 property1;
    // ....
    private T24 property24;

    public FooDto ToDto()
    {
        return new FooDto(property1 /\*\* \*/, property24);
    }
    

    }

    In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

    G Offline
    G Offline
    GuyThiebaut
    wrote on last edited by
    #5

    I would go for option 1. I would also look at having some sort of mapping functionality so that the values can be populated 'automatically' by passing the DTO to some form of orchestrator together with the data source to populate it. The following in option 2 is a huge code smell:

    public FooDto(T1 value1 /** 24 values later */, T24 value24)

    I have done this myself in the past but it is generally accepted nowadays that a large number of parameters in a signature is a bad idea.

    “That which can be asserted without evidence, can be dismissed without evidence.”

    ― Christopher Hitchens

    1 Reply Last reply
    0
    • S Super Lloyd

      Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

      public class FooDto
      {
      public T1 Property1 { get; set; }
      // ....
      public T24 Property24 { get; set; }
      }
      // ....
      class MyFooClass
      {
      private T1 property1;
      // ....
      private T24 property24;

      public FooDto ToDto()
      {
          return new FooDto()
          {
              Property1 = property1,
              //....
              Property24 = property24,
          };
      }
      

      }

      how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

      public class FooDto
      {
      public FooDto(T1 value1 /** 24 values later */, T24 value24)
      {
      Property1 = value1;
      // .....
      Property24 = value24;
      }

      public T1 Property1 { get; }
      // ....
      public T24 Property24 { get; }
      }
      // ....
      class MyFooClass
      {
      private T1 property1;
      // ....
      private T24 property24;

      public FooDto ToDto()
      {
          return new FooDto(property1 /\*\* \*/, property24);
      }
      

      }

      In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

      J Offline
      J Offline
      Jorgen Andersson
      wrote on last edited by
      #6

      I fail to see what the big deal is about, but if I get to choose I prefer 1. I don't like huge constructors, they are slightly more error prone.

      Wrong is evil and must be defeated. - Jeff Ello

      1 Reply Last reply
      0
      • C CPallini

        When a method has more than, say, four arguments, I strongly dislike it, its author, and the Italian governement. :)

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #7

        CPallini wrote:

        dislike ... the Italian governement.

        I thought that was mandatory in Italy, regardless.

        Wrong is evil and must be defeated. - Jeff Ello

        C 1 Reply Last reply
        0
        • J Jorgen Andersson

          CPallini wrote:

          dislike ... the Italian governement.

          I thought that was mandatory in Italy, regardless.

          Wrong is evil and must be defeated. - Jeff Ello

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #8

          You thought right.

          1 Reply Last reply
          0
          • S Super Lloyd

            Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

            public class FooDto
            {
            public T1 Property1 { get; set; }
            // ....
            public T24 Property24 { get; set; }
            }
            // ....
            class MyFooClass
            {
            private T1 property1;
            // ....
            private T24 property24;

            public FooDto ToDto()
            {
                return new FooDto()
                {
                    Property1 = property1,
                    //....
                    Property24 = property24,
                };
            }
            

            }

            how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

            public class FooDto
            {
            public FooDto(T1 value1 /** 24 values later */, T24 value24)
            {
            Property1 = value1;
            // .....
            Property24 = value24;
            }

            public T1 Property1 { get; }
            // ....
            public T24 Property24 { get; }
            }
            // ....
            class MyFooClass
            {
            private T1 property1;
            // ....
            private T24 property24;

            public FooDto ToDto()
            {
                return new FooDto(property1 /\*\* \*/, property24);
            }
            

            }

            In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

            G Offline
            G Offline
            GKP1992
            wrote on last edited by
            #9

            Option 1 because it is cleaner, more understandable and more extensible of the two options.

            1 Reply Last reply
            0
            • S Super Lloyd

              Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

              public class FooDto
              {
              public T1 Property1 { get; set; }
              // ....
              public T24 Property24 { get; set; }
              }
              // ....
              class MyFooClass
              {
              private T1 property1;
              // ....
              private T24 property24;

              public FooDto ToDto()
              {
                  return new FooDto()
                  {
                      Property1 = property1,
                      //....
                      Property24 = property24,
                  };
              }
              

              }

              how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

              public class FooDto
              {
              public FooDto(T1 value1 /** 24 values later */, T24 value24)
              {
              Property1 = value1;
              // .....
              Property24 = value24;
              }

              public T1 Property1 { get; }
              // ....
              public T24 Property24 { get; }
              }
              // ....
              class MyFooClass
              {
              private T1 property1;
              // ....
              private T24 property24;

              public FooDto ToDto()
              {
                  return new FooDto(property1 /\*\* \*/, property24);
              }
              

              }

              In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

              T Offline
              T Offline
              thatraja
              wrote on last edited by
              #10

              Option 1. Agree that Too much parameters in Option 2 is terrible one. Too much parameters require changes in other places(Ex: Business Logic layer, Code-behind, etc.,) when you need to remove/add parameters later.

              thatraja

              Coming soon1 | Coming soon2 | Coming soon3New

              1 Reply Last reply
              0
              • S Super Lloyd

                Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                public class FooDto
                {
                public T1 Property1 { get; set; }
                // ....
                public T24 Property24 { get; set; }
                }
                // ....
                class MyFooClass
                {
                private T1 property1;
                // ....
                private T24 property24;

                public FooDto ToDto()
                {
                    return new FooDto()
                    {
                        Property1 = property1,
                        //....
                        Property24 = property24,
                    };
                }
                

                }

                how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                public class FooDto
                {
                public FooDto(T1 value1 /** 24 values later */, T24 value24)
                {
                Property1 = value1;
                // .....
                Property24 = value24;
                }

                public T1 Property1 { get; }
                // ....
                public T24 Property24 { get; }
                }
                // ....
                class MyFooClass
                {
                private T1 property1;
                // ....
                private T24 property24;

                public FooDto ToDto()
                {
                    return new FooDto(property1 /\*\* \*/, property24);
                }
                

                }

                In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #11

                Really blow his mind. Make the constructor accept a Tuple instead.

                This space for rent

                S 1 Reply Last reply
                0
                • S Super Lloyd

                  Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                  public class FooDto
                  {
                  public T1 Property1 { get; set; }
                  // ....
                  public T24 Property24 { get; set; }
                  }
                  // ....
                  class MyFooClass
                  {
                  private T1 property1;
                  // ....
                  private T24 property24;

                  public FooDto ToDto()
                  {
                      return new FooDto()
                      {
                          Property1 = property1,
                          //....
                          Property24 = property24,
                      };
                  }
                  

                  }

                  how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                  public class FooDto
                  {
                  public FooDto(T1 value1 /** 24 values later */, T24 value24)
                  {
                  Property1 = value1;
                  // .....
                  Property24 = value24;
                  }

                  public T1 Property1 { get; }
                  // ....
                  public T24 Property24 { get; }
                  }
                  // ....
                  class MyFooClass
                  {
                  private T1 property1;
                  // ....
                  private T24 property24;

                  public FooDto ToDto()
                  {
                      return new FooDto(property1 /\*\* \*/, property24);
                  }
                  

                  }

                  In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                  N Offline
                  N Offline
                  Nathan Minier
                  wrote on last edited by
                  #12

                  Super Lloyd wrote:

                  In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values.

                  Yeah, initialization does not inherently mean useful values, so why force lazy coders to initialize meaningless values?

                  var dto = new FooDto(actualT1Val,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);

                  "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                  S 2 Replies Last reply
                  0
                  • N Nathan Minier

                    Super Lloyd wrote:

                    In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values.

                    Yeah, initialization does not inherently mean useful values, so why force lazy coders to initialize meaningless values?

                    var dto = new FooDto(actualT1Val,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);

                    "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                    S Offline
                    S Offline
                    Super Lloyd
                    wrote on last edited by
                    #13

                    :laugh:

                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                    1 Reply Last reply
                    0
                    • N Nathan Minier

                      Super Lloyd wrote:

                      In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values.

                      Yeah, initialization does not inherently mean useful values, so why force lazy coders to initialize meaningless values?

                      var dto = new FooDto(actualT1Val,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null);

                      "Never attribute to malice that which can be explained by stupidity." - Hanlon's Razor

                      S Offline
                      S Offline
                      Super Lloyd
                      wrote on last edited by
                      #14

                      I think I might add a couple of unit test just like that, for giggle... :laugh:

                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                      1 Reply Last reply
                      0
                      • P Pete OHanlon

                        Really blow his mind. Make the constructor accept a Tuple instead.

                        This space for rent

                        S Offline
                        S Offline
                        Super Lloyd
                        wrote on last edited by
                        #15

                        that's a good one! :D in fact it might the easiest way how to go about it.. by that I mean I can implement that with some quick copy paste... whereas implementing the constructor is going to be manually intensive and bug prone! :~

                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                        1 Reply Last reply
                        0
                        • S Super Lloyd

                          Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                          public class FooDto
                          {
                          public T1 Property1 { get; set; }
                          // ....
                          public T24 Property24 { get; set; }
                          }
                          // ....
                          class MyFooClass
                          {
                          private T1 property1;
                          // ....
                          private T24 property24;

                          public FooDto ToDto()
                          {
                              return new FooDto()
                              {
                                  Property1 = property1,
                                  //....
                                  Property24 = property24,
                              };
                          }
                          

                          }

                          how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                          public class FooDto
                          {
                          public FooDto(T1 value1 /** 24 values later */, T24 value24)
                          {
                          Property1 = value1;
                          // .....
                          Property24 = value24;
                          }

                          public T1 Property1 { get; }
                          // ....
                          public T24 Property24 { get; }
                          }
                          // ....
                          class MyFooClass
                          {
                          private T1 property1;
                          // ....
                          private T24 property24;

                          public FooDto ToDto()
                          {
                              return new FooDto(property1 /\*\* \*/, property24);
                          }
                          

                          }

                          In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                          M Offline
                          M Offline
                          MadMyche
                          wrote on last edited by
                          #16

                          I don't mind either option, but I think I like v1 better. When it comes to long lists of assignments I generally copy/paste back and forth with an instance of Excel.


                          Director of Transmogrification Services Shinobi of Query Language Master of Yoda Conditional

                          1 Reply Last reply
                          0
                          • S Super Lloyd

                            Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                            public class FooDto
                            {
                            public T1 Property1 { get; set; }
                            // ....
                            public T24 Property24 { get; set; }
                            }
                            // ....
                            class MyFooClass
                            {
                            private T1 property1;
                            // ....
                            private T24 property24;

                            public FooDto ToDto()
                            {
                                return new FooDto()
                                {
                                    Property1 = property1,
                                    //....
                                    Property24 = property24,
                                };
                            }
                            

                            }

                            how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                            public class FooDto
                            {
                            public FooDto(T1 value1 /** 24 values later */, T24 value24)
                            {
                            Property1 = value1;
                            // .....
                            Property24 = value24;
                            }

                            public T1 Property1 { get; }
                            // ....
                            public T24 Property24 { get; }
                            }
                            // ....
                            class MyFooClass
                            {
                            private T1 property1;
                            // ....
                            private T24 property24;

                            public FooDto ToDto()
                            {
                                return new FooDto(property1 /\*\* \*/, property24);
                            }
                            

                            }

                            In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                            A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                            Z Offline
                            Z Offline
                            ZurdoDev
                            wrote on last edited by
                            #17

                            Super Lloyd wrote:

                            select your favourite of 2 options.

                            I prefer favorite.

                            Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                            S H 2 Replies Last reply
                            0
                            • S Super Lloyd

                              Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                              public class FooDto
                              {
                              public T1 Property1 { get; set; }
                              // ....
                              public T24 Property24 { get; set; }
                              }
                              // ....
                              class MyFooClass
                              {
                              private T1 property1;
                              // ....
                              private T24 property24;

                              public FooDto ToDto()
                              {
                                  return new FooDto()
                                  {
                                      Property1 = property1,
                                      //....
                                      Property24 = property24,
                                  };
                              }
                              

                              }

                              how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                              public class FooDto
                              {
                              public FooDto(T1 value1 /** 24 values later */, T24 value24)
                              {
                              Property1 = value1;
                              // .....
                              Property24 = value24;
                              }

                              public T1 Property1 { get; }
                              // ....
                              public T24 Property24 { get; }
                              }
                              // ....
                              class MyFooClass
                              {
                              private T1 property1;
                              // ....
                              private T24 property24;

                              public FooDto ToDto()
                              {
                                  return new FooDto(property1 /\*\* \*/, property24);
                              }
                              

                              }

                              In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                              A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

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

                              Neither. One does not "force" all or none. The constructor-parameters are added for all variables that the object needs before it can initialize. Any other option that can be set later should be a public property. If you have more than three parameters, consider creating a class for them and to pass the thing to the constructor.

                              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                              S 1 Reply Last reply
                              0
                              • L Lost User

                                Neither. One does not "force" all or none. The constructor-parameters are added for all variables that the object needs before it can initialize. Any other option that can be set later should be a public property. If you have more than three parameters, consider creating a class for them and to pass the thing to the constructor.

                                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                S Offline
                                S Offline
                                Super Lloyd
                                wrote on last edited by
                                #19

                                it's a DTO, i.e. all those could be field really (except it would sparkle another argument). No code is either run into that class, just a bag of well known property....

                                A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                L 1 Reply Last reply
                                0
                                • Z ZurdoDev

                                  Super Lloyd wrote:

                                  select your favourite of 2 options.

                                  I prefer favorite.

                                  Everyone is born right handed. Only the strongest overcome it. Fight for left-handed rights and hand equality.

                                  S Offline
                                  S Offline
                                  Super Lloyd
                                  wrote on last edited by
                                  #20

                                  I live in Australia..... I am giving in the local area grammar Nazi... :sigh: :((

                                  A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                  1 Reply Last reply
                                  0
                                  • S Super Lloyd

                                    it's a DTO, i.e. all those could be field really (except it would sparkle another argument). No code is either run into that class, just a bag of well known property....

                                    A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

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

                                    The same still applies; anything that is required should be there in the constructor. If it is not required for the objects existence, then it becomes a property. For a DTO, I'd expect an Id-field, and without an Id such object should not exist.

                                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                    1 Reply Last reply
                                    0
                                    • S Super Lloyd

                                      Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                                      public class FooDto
                                      {
                                      public T1 Property1 { get; set; }
                                      // ....
                                      public T24 Property24 { get; set; }
                                      }
                                      // ....
                                      class MyFooClass
                                      {
                                      private T1 property1;
                                      // ....
                                      private T24 property24;

                                      public FooDto ToDto()
                                      {
                                          return new FooDto()
                                          {
                                              Property1 = property1,
                                              //....
                                              Property24 = property24,
                                          };
                                      }
                                      

                                      }

                                      how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                                      public class FooDto
                                      {
                                      public FooDto(T1 value1 /** 24 values later */, T24 value24)
                                      {
                                      Property1 = value1;
                                      // .....
                                      Property24 = value24;
                                      }

                                      public T1 Property1 { get; }
                                      // ....
                                      public T24 Property24 { get; }
                                      }
                                      // ....
                                      class MyFooClass
                                      {
                                      private T1 property1;
                                      // ....
                                      private T24 property24;

                                      public FooDto ToDto()
                                      {
                                          return new FooDto(property1 /\*\* \*/, property24);
                                      }
                                      

                                      }

                                      In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                                      A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                      M Offline
                                      M Offline
                                      Marc Clifton
                                      wrote on last edited by
                                      #22

                                      Neither. It shouldn't be the responsiblity of MyFooClass to return a FooDto, it should be FooDto's class to take a MyFooClass and convert it to a FooDto. So you have instead:

                                      public class FooDto
                                      {
                                      public static FooDto From(MyFooClass c)
                                      {
                                      // ...mapping...
                                      }
                                      }

                                      And to make this more re-usable for different data objects and to avoid repeating From for every type of "from - to" conversion, use interfaces:

                                      public class FooDto : IFooDto
                                      {
                                      public static IFooDto From(IFooClass c)
                                      {
                                      // ...mapping...
                                      }
                                      }

                                      This promotes consistency between properties in FooDto and properties in the "from" class that can be mapped to FooDto.

                                      Latest Article - A Concise Overview of Threads Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802

                                      1 Reply Last reply
                                      0
                                      • S Super Lloyd

                                        Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                                        public class FooDto
                                        {
                                        public T1 Property1 { get; set; }
                                        // ....
                                        public T24 Property24 { get; set; }
                                        }
                                        // ....
                                        class MyFooClass
                                        {
                                        private T1 property1;
                                        // ....
                                        private T24 property24;

                                        public FooDto ToDto()
                                        {
                                            return new FooDto()
                                            {
                                                Property1 = property1,
                                                //....
                                                Property24 = property24,
                                            };
                                        }
                                        

                                        }

                                        how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                                        public class FooDto
                                        {
                                        public FooDto(T1 value1 /** 24 values later */, T24 value24)
                                        {
                                        Property1 = value1;
                                        // .....
                                        Property24 = value24;
                                        }

                                        public T1 Property1 { get; }
                                        // ....
                                        public T24 Property24 { get; }
                                        }
                                        // ....
                                        class MyFooClass
                                        {
                                        private T1 property1;
                                        // ....
                                        private T24 property24;

                                        public FooDto ToDto()
                                        {
                                            return new FooDto(property1 /\*\* \*/, property24);
                                        }
                                        

                                        }

                                        In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                                        A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

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

                                        Of the two choices given, I'd take 1; but would prefer a third option.:

                                        public class FooDto
                                        {
                                        public FooDto(MyFooClass foo)
                                        {
                                        Property1 = foo.property1;
                                        // .....
                                        Property24 = foo.property24;
                                        }

                                        public T1 Property1 { get; }
                                        // ....
                                        public T24 Property24 { get; }
                                        }
                                        // ....
                                        class MyFooClass
                                        {
                                        private T1 property1;
                                        // ....
                                        private T24 property24;
                                        }

                                        If for some reason I

                                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing 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
                                        • S Super Lloyd

                                          Yes it's a programming question, but wait a moment, I am NOT asking to solve any problem here, I am asking to select your favourite of 2 options. I think what they want me to do here at work is disgusting. I have to suck it up anyway, since it's the guy who accepts pull request that tells me to do it, period. But I am curious whether or not I am in good company with my prejudice. It's about DTO, constructors with zillion of parameters and all private properties. code I prefer and put in my pull request, with 24 properties (i.e large number of properties)

                                          public class FooDto
                                          {
                                          public T1 Property1 { get; set; }
                                          // ....
                                          public T24 Property24 { get; set; }
                                          }
                                          // ....
                                          class MyFooClass
                                          {
                                          private T1 property1;
                                          // ....
                                          private T24 property24;

                                          public FooDto ToDto()
                                          {
                                              return new FooDto()
                                              {
                                                  Property1 = property1,
                                                  //....
                                                  Property24 = property24,
                                              };
                                          }
                                          

                                          }

                                          how I have asked to rewrite the code, feels disgusting to me, but curious how many people share, or dislike, my opinion

                                          public class FooDto
                                          {
                                          public FooDto(T1 value1 /** 24 values later */, T24 value24)
                                          {
                                          Property1 = value1;
                                          // .....
                                          Property24 = value24;
                                          }

                                          public T1 Property1 { get; }
                                          // ....
                                          public T24 Property24 { get; }
                                          }
                                          // ....
                                          class MyFooClass
                                          {
                                          private T1 property1;
                                          // ....
                                          private T24 property24;

                                          public FooDto ToDto()
                                          {
                                              return new FooDto(property1 /\*\* \*/, property24);
                                          }
                                          

                                          }

                                          In his defence he has an argument. If someone use that DTO as well, the compiler will force them to initialise all values. Though one could counter argument that we got unit test for just that. At any rate, which of those 2 is your favourite code style?

                                          A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!

                                          F Offline
                                          F Offline
                                          Foothill
                                          wrote on last edited by
                                          #24

                                          If you really want to bake their noodle, put all the value maps in Attributes and then have the object built via Reflection such as in this article[^]. It's a super complicated way to do simple tasks :laugh:

                                          if (Object.DividedByZero == true) { Universe.Implode(); }

                                          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