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. Simple... wandering of mind on a tiny bit of code style...

Simple... wandering of mind on a tiny bit of code style...

Scheduled Pinned Locked Moved The Lounge
csharpcomhelpquestion
14 Posts 11 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 Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #1

    There was some piece of C# code I am refactoring (+ fixing small bug) where, at some stage, an expression like a.b.c is replaced by (private method) GetBc(A a). When I refactored that, I ignored GetBc(a) and wrote a.b.c instead, because I like it better that way. One of the code reviewers complained I was not using GetBc(a). Whatever, I updated my code to use GetBc(a) again. Now I wonder, mm.. how many people would care about that kind of detail and what kind of expression they would prefer?

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

    Sander RosselS M S P L 5 Replies Last reply
    0
    • S Super Lloyd

      There was some piece of C# code I am refactoring (+ fixing small bug) where, at some stage, an expression like a.b.c is replaced by (private method) GetBc(A a). When I refactored that, I ignored GetBc(a) and wrote a.b.c instead, because I like it better that way. One of the code reviewers complained I was not using GetBc(a). Whatever, I updated my code to use GetBc(a) again. Now I wonder, mm.. how many people would care about that kind of detail and what kind of expression they would prefer?

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

      Sander RosselS Offline
      Sander RosselS Offline
      Sander Rossel
      wrote on last edited by
      #2

      How would that work? GetBC(A a) => (a.b, a.c);? GetBC(A a) => new { a.b, a.c };? In both cases I'd prefer a.b.c. I don't see the added value of GetBC :~

      Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

      S 1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        How would that work? GetBC(A a) => (a.b, a.c);? GetBC(A a) => new { a.b, a.c };? In both cases I'd prefer a.b.c. I don't see the added value of GetBC :~

        Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

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

        C GetBc(A a) => a.b.c;

        The only "real advantage" (in the day of yore before intellisense) is that it's more like

        SomeClass GetBc(AnotherClass a) => a.LongPropertyName.OtherLongPropertyName;

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

        Sander RosselS T 2 Replies Last reply
        0
        • S Super Lloyd

          There was some piece of C# code I am refactoring (+ fixing small bug) where, at some stage, an expression like a.b.c is replaced by (private method) GetBc(A a). When I refactored that, I ignored GetBc(a) and wrote a.b.c instead, because I like it better that way. One of the code reviewers complained I was not using GetBc(a). Whatever, I updated my code to use GetBc(a) again. Now I wonder, mm.. how many people would care about that kind of detail and what kind of expression they would prefer?

          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
          #4

          I would ask the code reviewer, why not GetC(GetB(a)) as that is really the logical extreme he/she is going to and points out the ludicracy of not doing a.b.c

          Latest Article:
          SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples

          M E 2 Replies Last reply
          0
          • M Marc Clifton

            I would ask the code reviewer, why not GetC(GetB(a)) as that is really the logical extreme he/she is going to and points out the ludicracy of not doing a.b.c

            Latest Article:
            SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples

            M Offline
            M Offline
            MarkTJohnson
            wrote on last edited by
            #5

            Only problem with that is the reviewer might be one of those "letter of the law" people who would then demand that exact thing. Considering they had the problem in the first place, I wouldn't bet against their desire for the extreme.

            I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

            1 Reply Last reply
            0
            • S Super Lloyd

              There was some piece of C# code I am refactoring (+ fixing small bug) where, at some stage, an expression like a.b.c is replaced by (private method) GetBc(A a). When I refactored that, I ignored GetBc(a) and wrote a.b.c instead, because I like it better that way. One of the code reviewers complained I was not using GetBc(a). Whatever, I updated my code to use GetBc(a) again. Now I wonder, mm.. how many people would care about that kind of detail and what kind of expression they would prefer?

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

              S Offline
              S Offline
              Slacker007
              wrote on last edited by
              #6

              Is this a coding standard to use regular Methods such as in your example? Is this really not up to the code reviewer, but more in line with enforcing consistency and standards that your dev shop has?

              1 Reply Last reply
              0
              • S Super Lloyd

                There was some piece of C# code I am refactoring (+ fixing small bug) where, at some stage, an expression like a.b.c is replaced by (private method) GetBc(A a). When I refactored that, I ignored GetBc(a) and wrote a.b.c instead, because I like it better that way. One of the code reviewers complained I was not using GetBc(a). Whatever, I updated my code to use GetBc(a) again. Now I wonder, mm.. how many people would care about that kind of detail and what kind of expression they would prefer?

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

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

                Only the idgit what wrote GetBc would care. Mark the method and its writer as Obsolete. On the other hand, it may help when using "Find all references" if you ever want to see where a.b.c is used. But, as presented, I see no logical reason to use the method.

                1 Reply Last reply
                0
                • S Super Lloyd

                  C GetBc(A a) => a.b.c;

                  The only "real advantage" (in the day of yore before intellisense) is that it's more like

                  SomeClass GetBc(AnotherClass a) => a.LongPropertyName.OtherLongPropertyName;

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

                  Sander RosselS Offline
                  Sander RosselS Offline
                  Sander Rossel
                  wrote on last edited by
                  #8

                  Super Lloyd wrote:

                  C GetBc(A a) => a.b.c;

                  This is just ridiculous :~ Send that reviewer over to this thread so he can read that I find him ridiculous. Judging from the other replies on this thread I'm not the only one :laugh:

                  Super Lloyd wrote:

                  The only "real advantage" (in the day of yore before intellisense) is that it's more like

                  In those instances I don't make a function, but I simply use a variable.

                  var shortName = a.LongPropertyName.OtherLongPropertyName;
                  // Use shortName here.

                  Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

                  D 1 Reply Last reply
                  0
                  • S Super Lloyd

                    There was some piece of C# code I am refactoring (+ fixing small bug) where, at some stage, an expression like a.b.c is replaced by (private method) GetBc(A a). When I refactored that, I ignored GetBc(a) and wrote a.b.c instead, because I like it better that way. One of the code reviewers complained I was not using GetBc(a). Whatever, I updated my code to use GetBc(a) again. Now I wonder, mm.. how many people would care about that kind of detail and what kind of expression they would prefer?

                    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
                    #9

                    GetBc is a wrapper. As posted, it could be doing something else, or has done something else in the past. Or it was a stub from development. Do you just clean it out or replace it when "done"? (and maybe introduce side effects). Mixing and matching isn't the solution.

                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                    P 1 Reply Last reply
                    0
                    • S Super Lloyd

                      C GetBc(A a) => a.b.c;

                      The only "real advantage" (in the day of yore before intellisense) is that it's more like

                      SomeClass GetBc(AnotherClass a) => a.LongPropertyName.OtherLongPropertyName;

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

                      T Offline
                      T Offline
                      trønderen
                      wrote on last edited by
                      #10

                      I take the liberty to slightly defend that code reviewer. It is a matter of blackboxing: When you reference that bc property of a, you should be unaffected by how the a object structures its attributes, i.e. whether it has a single bc attribute (and maybe bc1, bc2, bc3, ...) or groups all the b<*> attributes into a b object with subfields. C# lets the a object provide a .bc property, so that is can map it to a .bc or a b.c field at its own discretion. Maybe that is nowadays available in C++ as well (it wasn't when I switched from C++ to C#). I have become very fond of blackboxing and need-to-know: You should need to know as little as possible about the inner structure of the objects you interact with. a.b.c does reveal an inner structure that you shouldn't care about. But I most certainly would prefer a .bc property to a GetBc(A a) method!

                      J 1 Reply Last reply
                      0
                      • L Lost User

                        GetBc is a wrapper. As posted, it could be doing something else, or has done something else in the past. Or it was a stub from development. Do you just clean it out or replace it when "done"? (and maybe introduce side effects). Mixing and matching isn't the solution.

                        "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

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

                        Gerry Schmitz wrote:

                        Mixing and matching isn't the solution.

                        True, consistency is desirable, but in this case, having the method means the method may be used in some places and not in others, which is inconsistent. Remove the method and all code will have to use use the a.b.c syntax consistently. Writing a method and then having to root out all of the instances of the old syntax is less than ideal.

                        1 Reply Last reply
                        0
                        • T trønderen

                          I take the liberty to slightly defend that code reviewer. It is a matter of blackboxing: When you reference that bc property of a, you should be unaffected by how the a object structures its attributes, i.e. whether it has a single bc attribute (and maybe bc1, bc2, bc3, ...) or groups all the b<*> attributes into a b object with subfields. C# lets the a object provide a .bc property, so that is can map it to a .bc or a b.c field at its own discretion. Maybe that is nowadays available in C++ as well (it wasn't when I switched from C++ to C#). I have become very fond of blackboxing and need-to-know: You should need to know as little as possible about the inner structure of the objects you interact with. a.b.c does reveal an inner structure that you shouldn't care about. But I most certainly would prefer a .bc property to a GetBc(A a) method!

                          J Offline
                          J Offline
                          jschell
                          wrote on last edited by
                          #12

                          trønderen wrote:

                          When you reference that bc property of a, you should be unaffected by how the a object structures its attributes

                          If you use the data of the object outside the object then you have exposed the internal details of the object. The specifics of how the data is exposed is not relevant. This comes about because people confuse the idealization of 'object' and 'message' and the implementation to 'class' and 'method'. They then think incorrectly that it must mean that it goes the other way so 'method' => 'message'. And certainly ignore that the first is a ideal which can never and should never be rigidly enforced.

                          1 Reply Last reply
                          0
                          • M Marc Clifton

                            I would ask the code reviewer, why not GetC(GetB(a)) as that is really the logical extreme he/she is going to and points out the ludicracy of not doing a.b.c

                            Latest Article:
                            SVG Grids: Squares, Triangles, Hexagons with scrolling, sprites and simple animation examples

                            E Offline
                            E Offline
                            englebart
                            wrote on last edited by
                            #13

                            I was thinking the same thing with Get…

                            1 Reply Last reply
                            0
                            • Sander RosselS Sander Rossel

                              Super Lloyd wrote:

                              C GetBc(A a) => a.b.c;

                              This is just ridiculous :~ Send that reviewer over to this thread so he can read that I find him ridiculous. Judging from the other replies on this thread I'm not the only one :laugh:

                              Super Lloyd wrote:

                              The only "real advantage" (in the day of yore before intellisense) is that it's more like

                              In those instances I don't make a function, but I simply use a variable.

                              var shortName = a.LongPropertyName.OtherLongPropertyName;
                              // Use shortName here.

                              Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript

                              D Offline
                              D Offline
                              DerekT P
                              wrote on last edited by
                              #14

                              In most cases it's ridiculous, yes. It's not a construct I think I've used myself. However... What if b is null? Suppose b is a lazy-loaded property which is only instantiated as/when referenced, but a does not support that functionality? Or - in the circumstances where you use the GetBC function you need a default value returned if b or c are null. I'd agree that if GetBC does nothing more than return b.c then yes, it's pointless; but if there's code in that function (even just exception handling) then maybe... though a more descriptive/specific name than simply GetBC might be appropriate.

                              Telegraph marker posts ... nothing to do with IT Phasmid email discussion group ... also nothing to do with IT Beekeeping and honey site ... still nothing to do with IT

                              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