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. Other Discussions
  3. The Weird and The Wonderful
  4. But...wait, what?

But...wait, what?

Scheduled Pinned Locked Moved The Weird and The Wonderful
question
11 Posts 9 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.
  • J Offline
    J Offline
    JHizzle
    wrote on last edited by
    #1

    Nice one today:

            'Not as strange as it looks, the property set adds the object to session
            MemberData = MemberData
    

    you know what? It really works.

    P C L H 4 Replies Last reply
    0
    • J JHizzle

      Nice one today:

              'Not as strange as it looks, the property set adds the object to session
              MemberData = MemberData
      

      you know what? It really works.

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

      Maybe that should be in the constructor?

      S 1 Reply Last reply
      0
      • P PIEBALDconsult

        Maybe that should be in the constructor?

        S Offline
        S Offline
        scotchfaster
        wrote on last edited by
        #3

        I don't know what language that's in, but I'm wondering if relying on the side-effects of assigning a member to itself is a good idea. A compiler (assuming this is compiled code) might reasonably optimize that away. However, you have to like the comment!

        R 1 Reply Last reply
        0
        • S scotchfaster

          I don't know what language that's in, but I'm wondering if relying on the side-effects of assigning a member to itself is a good idea. A compiler (assuming this is compiled code) might reasonably optimize that away. However, you have to like the comment!

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          I assume its C# and a property. Then its a normal method call for the compiler.

          T 1 Reply Last reply
          0
          • R Robert Rohde

            I assume its C# and a property. Then its a normal method call for the compiler.

            T Offline
            T Offline
            Thomas Krojer
            wrote on last edited by
            #5

            comments with ' ... looks like VB or so ...

            J R 2 Replies Last reply
            0
            • T Thomas Krojer

              comments with ' ... looks like VB or so ...

              J Offline
              J Offline
              JHizzle
              wrote on last edited by
              #6

              Yep, VB.NET

              1 Reply Last reply
              0
              • J JHizzle

                Nice one today:

                        'Not as strange as it looks, the property set adds the object to session
                        MemberData = MemberData
                

                you know what? It really works.

                C Offline
                C Offline
                Chris Meech
                wrote on last edited by
                #7

                Now if that were C++ and I had also written a copy constructor for the class, I'd be able to introduce some side effects that would be truly humourous. Assign NULL to some pointers, initialize some other variables. Probably make it to Coding Horrors. :cool:

                Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]

                1 Reply Last reply
                0
                • T Thomas Krojer

                  comments with ' ... looks like VB or so ...

                  R Offline
                  R Offline
                  Robert Rohde
                  wrote on last edited by
                  #8

                  Well ok. But even if its VB.Net its still the same. On the other hand its total crap to abuse a property in this manner.

                  S 1 Reply Last reply
                  0
                  • R Robert Rohde

                    Well ok. But even if its VB.Net its still the same. On the other hand its total crap to abuse a property in this manner.

                    S Offline
                    S Offline
                    supercat9
                    wrote on last edited by
                    #9

                    Robert Rohde wrote:

                    On the other hand its total crap to abuse a property in this manner.

                    Although such code should never be used outside a class, since it relies upon the class not to implement caching behavior (or else relies upon some class-specific means of overriding such behavior), setting a property to itself may be a reasonable way of forcing a refresh of a corruptible copy of a property from a stable one. For example, one might have an object which manages a USB-connected lighting controller. Setting the "Brightness" property of the object will send a command to the controller to change the brightness. If external factors might disrupt the brightness setting of the external controller, it may be desirable to periodically set the brightness to the value the computer expects. If the property-set routine simply wraps a SetHardwareBrightness method, it would probably be better to call that method than set the property to its present value. If the property-set routine does the actual work itself, however, it's probably better to use the property-set routine for the refresh than to split out a new SetHardwareBrightness method.

                    1 Reply Last reply
                    0
                    • J JHizzle

                      Nice one today:

                              'Not as strange as it looks, the property set adds the object to session
                              MemberData = MemberData
                      

                      you know what? It really works.

                      L Offline
                      L Offline
                      leppie
                      wrote on last edited by
                      #10

                      MMKAY

                      xacc.ide
                      IronScheme - 1.0 RC 1 - out now!
                      ((λ (x) `(,x ',x)) '(λ (x) `(,x ',x))) The Scheme Programming Language – Fourth Edition

                      1 Reply Last reply
                      0
                      • J JHizzle

                        Nice one today:

                                'Not as strange as it looks, the property set adds the object to session
                                MemberData = MemberData
                        

                        you know what? It really works.

                        H Offline
                        H Offline
                        Hired Mind
                        wrote on last edited by
                        #11

                        I try to remember to do a Find All Usages in Resharper (now in VS2010) to make sure that code inside the class doesn't use the property, only the backing field. Keeps me from writing code like that. It goes without saying that any code outside the class shouldn't even have any idea what side-effects might be happening in a public setter.

                        Before .NET 4.0, object Universe = NULL;

                        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