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. Clever Code
  4. Overflowded!

Overflowded!

Scheduled Pinned Locked Moved Clever Code
visual-studiodata-structuresdebugging
12 Posts 6 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 joon vh
    public class foo
    {
        int mBar;
    
        public int Bar
        {
            get { return Bar; }
            set { mBar = value; }
        }
    }
    

    This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p

    P Offline
    P Offline
    Prakash Nadar
    wrote on last edited by
    #2

    joon vh. wrote:

    get { return Bar; }

    Took me 3 seconds, actually less than that.


    -Prakash

    J 1 Reply Last reply
    0
    • P Prakash Nadar

      joon vh. wrote:

      get { return Bar; }

      Took me 3 seconds, actually less than that.


      -Prakash

      J Offline
      J Offline
      joon vh
      wrote on last edited by
      #3

      of course, I loosened it up for you.


      Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

      P 1 Reply Last reply
      0
      • J joon vh
        public class foo
        {
            int mBar;
        
            public int Bar
            {
                get { return Bar; }
                set { mBar = value; }
            }
        }
        

        This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p

        S Offline
        S Offline
        Steve Hansen
        wrote on last edited by
        #4

        Oh I love my ReSharper, it would have taken me one second in any case to notice that :) ReSharper 2.5 shows in the side when some method is recursivly calling. Preview[^]

        J 1 Reply Last reply
        0
        • S Steve Hansen

          Oh I love my ReSharper, it would have taken me one second in any case to notice that :) ReSharper 2.5 shows in the side when some method is recursivly calling. Preview[^]

          J Offline
          J Offline
          joon vh
          wrote on last edited by
          #5

          I use it too, and it's awesome :) Too bad I didn't have it back then ;) a tat heavy, but saves so much time.


          Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

          1 Reply Last reply
          0
          • J joon vh
            public class foo
            {
                int mBar;
            
                public int Bar
                {
                    get { return Bar; }
                    set { mBar = value; }
                }
            }
            

            This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p

            N Offline
            N Offline
            NormDroid
            wrote on last edited by
            #6

            Must admit I've been bitten a couple of times with that one, although it only takes less than a second to discover and fix.

            .net is a box of never ending treasures, every day I get find another gem.

            J 1 Reply Last reply
            0
            • N NormDroid

              Must admit I've been bitten a couple of times with that one, although it only takes less than a second to discover and fix.

              .net is a box of never ending treasures, every day I get find another gem.

              J Offline
              J Offline
              joon vh
              wrote on last edited by
              #7

              not if it's a first time encounter, and you're me, and convinced, due to lack of confidence, that you must've severely broken something because you get an Error without a stacktrace.


              Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

              1 Reply Last reply
              0
              • J joon vh

                of course, I loosened it up for you.


                Visual Studio can't evaluate this, can you? public object moo { __get { return moo; } __set { moo = value; } }

                P Offline
                P Offline
                Prakash Nadar
                wrote on last edited by
                #8

                yeah, I figured that now :) Thanks.


                -Prakash

                1 Reply Last reply
                0
                • J joon vh
                  public class foo
                  {
                      int mBar;
                  
                      public int Bar
                      {
                          get { return Bar; }
                          set { mBar = value; }
                      }
                  }
                  

                  This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p

                  N Offline
                  N Offline
                  Nemanja Trifunovic
                  wrote on last edited by
                  #9

                  As I said on multiple occasions: properties are a bad idea - methods with a syntax of data members X|


                  Programming Blog utf8-cpp

                  S 1 Reply Last reply
                  0
                  • N Nemanja Trifunovic

                    As I said on multiple occasions: properties are a bad idea - methods with a syntax of data members X|


                    Programming Blog utf8-cpp

                    S Offline
                    S Offline
                    Steve Hansen
                    wrote on last edited by
                    #10

                    In Java you have something like:

                    private String name;
                    public String get_Name()
                    {
                    return name;
                    }
                    public void set_Name(String name)
                    {
                    this.name = name;
                    }

                    Why is it so bad to use this instead:

                    public String Name
                    {
                    get { return name; }
                    set { name = value; }
                    }

                    Which is internally used as get_Name and set_Name, you can check this by trying to add a method with signature public string get_Name() and it will complain. The biggest advantage you get is more readable code.

                    person.Name += " Something";

                    instead of

                    person.set_Name(person.get_Name() + " Something");

                    N 1 Reply Last reply
                    0
                    • S Steve Hansen

                      In Java you have something like:

                      private String name;
                      public String get_Name()
                      {
                      return name;
                      }
                      public void set_Name(String name)
                      {
                      this.name = name;
                      }

                      Why is it so bad to use this instead:

                      public String Name
                      {
                      get { return name; }
                      set { name = value; }
                      }

                      Which is internally used as get_Name and set_Name, you can check this by trying to add a method with signature public string get_Name() and it will complain. The biggest advantage you get is more readable code.

                      person.Name += " Something";

                      instead of

                      person.set_Name(person.get_Name() + " Something");

                      N Offline
                      N Offline
                      Nemanja Trifunovic
                      wrote on last edited by
                      #11

                      Steve Hansen wrote:

                      Why is it so bad to use this instead: public String Name{get { return name; }set { name = value; }}

                      I am not talking about implementing properties, but the way they are used. They look like data members, but are functions and that not only leads to bugs like the one described in this topic, but also reduces readability of the code.

                      Steve Hansen wrote:

                      The biggest advantage you get is more readable code. person.Name += " Something"; instead of person.set_Name(person.get_Name() + " Something");

                      Both are bad.


                      Programming Blog utf8-cpp

                      1 Reply Last reply
                      0
                      • J joon vh
                        public class foo
                        {
                            int mBar;
                        
                            public int Bar
                            {
                                get { return Bar; }
                                set { mBar = value; }
                            }
                        }
                        

                        This one took me an hour to figure out, due to lack of confidence. I was so sure that I had done something terribly wrong, while the answer was just right in front of me. VS StackOverFlowed without a (stack)trace, but the pointer stopped at the 'public int Bar', But strangely this happened right at startup (not during build), looong before the property was ever used. So I thought something was horribly wrong, instead of just looking where the pointer stopped. I hope you see it quicker than me :p

                        X Offline
                        X Offline
                        xibeifeijian
                        wrote on last edited by
                        #12

                        Just replace "get { return Bar; }" to "get { return this.mBar; }. I suggest you remove m from "mBar" and replace it with a "_":rolleyes:

                        █▒▒▒▒▒██▒█▒██ █▒█████▒▒▒▒▒█ █▒██████▒█▒██ █▒█████▒▒▒▒▒█ █▒▒▒▒▒██▒█▒██

                        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