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. FTW?

FTW?

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharprubycollaborationquestion
10 Posts 9 Posters 3 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.
  • R Offline
    R Offline
    Rotted Frog
    wrote on last edited by
    #1

    This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

    public bool SelectedByDefault
    {
      get { return \_defaultSelected; }
      set
      {
        // no, check isn't pointless, because serialisation can assign a null to a bool
        if (value != null)
        {
          \_defaultSelected = value;
        }
        else
        {
          \_defaultSelected = false;
        }
      }
    }
    
    P G C R C 8 Replies Last reply
    0
    • R Rotted Frog

      This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

      public bool SelectedByDefault
      {
        get { return \_defaultSelected; }
        set
        {
          // no, check isn't pointless, because serialisation can assign a null to a bool
          if (value != null)
          {
            \_defaultSelected = value;
          }
          else
          {
            \_defaultSelected = false;
          }
        }
      }
      
      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      :zzz: Just a different take on a common situation.

      1 Reply Last reply
      0
      • R Rotted Frog

        This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

        public bool SelectedByDefault
        {
          get { return \_defaultSelected; }
          set
          {
            // no, check isn't pointless, because serialisation can assign a null to a bool
            if (value != null)
            {
              \_defaultSelected = value;
            }
            else
            {
              \_defaultSelected = false;
            }
          }
        }
        
        G Offline
        G Offline
        geegeegeegee
        wrote on last edited by
        #3

        lol, arguments in code comments.

        1 Reply Last reply
        0
        • R Rotted Frog

          This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

          public bool SelectedByDefault
          {
            get { return \_defaultSelected; }
            set
            {
              // no, check isn't pointless, because serialisation can assign a null to a bool
              if (value != null)
              {
                \_defaultSelected = value;
              }
              else
              {
                \_defaultSelected = false;
              }
            }
          }
          
          C Offline
          C Offline
          Chris Maunder
          wrote on last edited by
          #4

          Here, here might need this: ?

          cheers, Chris Maunder

          CodeProject.com : C++ MVP

          1 Reply Last reply
          0
          • R Rotted Frog

            This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

            public bool SelectedByDefault
            {
              get { return \_defaultSelected; }
              set
              {
                // no, check isn't pointless, because serialisation can assign a null to a bool
                if (value != null)
                {
                  \_defaultSelected = value;
                }
                else
                {
                  \_defaultSelected = false;
                }
              }
            }
            
            R Offline
            R Offline
            Rotted Frog
            wrote on last edited by
            #5

            Even more surprising is that it appeared convinced this was true even though the compiler gives an unreachable code warning and tell you that the check will always return true. But he probably didn't notice it hidden amongst the other 200 warnings. Sigh.

            1 Reply Last reply
            0
            • R Rotted Frog

              This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

              public bool SelectedByDefault
              {
                get { return \_defaultSelected; }
                set
                {
                  // no, check isn't pointless, because serialisation can assign a null to a bool
                  if (value != null)
                  {
                    \_defaultSelected = value;
                  }
                  else
                  {
                    \_defaultSelected = false;
                  }
                }
              }
              
              C Offline
              C Offline
              cybertone
              wrote on last edited by
              #6

              By the way, C# compiler (with optimization option 'on') generates these IL instructions for set accessor:

              ldarg.0
              ldarg.1
              stfld bool <reference_to_local_field>
              ret

              ; so, at the C# level it whould be:

              this._<reference_to_local_field> = value;

              ; So, this construction is obviously needless :-D

              modified on Monday, January 19, 2009 1:56 AM

              1 Reply Last reply
              0
              • R Rotted Frog

                This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

                public bool SelectedByDefault
                {
                  get { return \_defaultSelected; }
                  set
                  {
                    // no, check isn't pointless, because serialisation can assign a null to a bool
                    if (value != null)
                    {
                      \_defaultSelected = value;
                    }
                    else
                    {
                      \_defaultSelected = false;
                    }
                  }
                }
                
                Brian C HartB Offline
                Brian C HartB Offline
                Brian C Hart
                wrote on last edited by
                #7

                A colleague says perhaps this guy just plain didn't trust that said field would be checked actually *in* the serialization code...not that anyone would want to risk an exception getting thrown for serializing a bool anyway. Since when were bool variables ever null? Besides isn't that equivalent to false, or am I not a "C# Expert?" -Brian

                Sincerely Yours, Brian Hart

                1 Reply Last reply
                0
                • R Rotted Frog

                  This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

                  public bool SelectedByDefault
                  {
                    get { return \_defaultSelected; }
                    set
                    {
                      // no, check isn't pointless, because serialisation can assign a null to a bool
                      if (value != null)
                      {
                        \_defaultSelected = value;
                      }
                      else
                      {
                        \_defaultSelected = false;
                      }
                    }
                  }
                  
                  K Offline
                  K Offline
                  kampr3t
                  wrote on last edited by
                  #8

                  public bool SelectedByDefault{ get; set; } why not like above ? :-O

                  B 1 Reply Last reply
                  0
                  • R Rotted Frog

                    This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.

                    public bool SelectedByDefault
                    {
                      get { return \_defaultSelected; }
                      set
                      {
                        // no, check isn't pointless, because serialisation can assign a null to a bool
                        if (value != null)
                        {
                          \_defaultSelected = value;
                        }
                        else
                        {
                          \_defaultSelected = false;
                        }
                      }
                    }
                    
                    V Offline
                    V Offline
                    vaghelabhavesh
                    wrote on last edited by
                    #9

                    Rotted Frog wrote:

                    because serialisation can assign a null to a bool

                    Isn't the bool variable default initialized to false?

                    1 Reply Last reply
                    0
                    • K kampr3t

                      public bool SelectedByDefault{ get; set; } why not like above ? :-O

                      B Offline
                      B Offline
                      BillW33
                      wrote on last edited by
                      #10

                      Clearly, that would be _way_ too easy! ;)

                      Just because the code works, it doesn't mean that it is good code.

                      modified on Friday, March 20, 2009 4:41 PM

                      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