Dynamic Hardcoding.



  •  This is one of the gems I encountered today written by a guy thats no longer here.

     Requirement: To show a list of "contact types" retrieved from the DB into a Cached DataSet in a drop down list.e.g. Phone, Email, Postal Address, Fax, Mobile etc..

    This values must not be hardcoded since we might add new contact types like facebook,twitter etc..

    This is what i found... note that for each item, the methods to get the info - name, id, are fired multiple times.

     -----------------------------------------WTF CODE---------------------------------------------------

             /// <summary>
            /// Loads the data into the dropdownlist [cmbLocatorType]
            /// </summary>
            private void LoadData()
            {            
                cmbLocatorType.Items.Add(new RadListDataItem(
                        LocatorType.Get().GetName(LocatorType.Get().GetId(LocatorTypeCodes.AfterHoursPhone)),
                        LocatorType.Get().GetId(LocatorTypeCodes.AfterHoursPhone)));
                cmbLocatorType.Items.Add(new RadListDataItem(
                    LocatorType.Get().GetName(LocatorType.Get().GetId(LocatorTypeCodes.DaytimePhone)),
                    LocatorType.Get().GetId(LocatorTypeCodes.DaytimePhone)));
                cmbLocatorType.Items.Add(new RadListDataItem(
                    LocatorType.Get().GetName(LocatorType.Get().GetId(LocatorTypeCodes.Email)),
                    LocatorType.Get().GetId(LocatorTypeCodes.Email)));
                cmbLocatorType.Items.Add(new RadListDataItem(
                    LocatorType.Get().GetName(LocatorType.Get().GetId(LocatorTypeCodes.Fax)),
                    LocatorType.Get().GetId(LocatorTypeCodes.Fax)));
                cmbLocatorType.Items.Add(new RadListDataItem(
                    LocatorType.Get().GetName(LocatorType.Get().GetId(LocatorTypeCodes.SMS)),
                    LocatorType.Get().GetId(LocatorTypeCodes.SMS)));
                cmbLocatorType.SelectedIndex = 0;
                dateTimeSelector1.Value = DateTime.Now;
            }

     

    -----------------------------------------------------------------------------

     ---------------------------Patched---------------------------------------

     /// <summary>
            /// Loads the data into the dropdownlist [cmbLocatorType]
            /// </summary>
            private void LoadData()
            {           
                LocatorType type = LocatorType.Get();
                foreach (LocatorTypeBe.LocatorTypeRow row in type.BusinessEntity.LocatorType)
                {
                    cmbLocatorType.Items.Add(new RadListDataItem(row.Name,row.Id));
                }
                dateTimeSelector1.Value = DateTime.Now;
            }

     ---------------------------Patched---------------------------------------



  •  One can never forget that strangely warm feeling inside when refactoring wtf code.



  • Truly, refactoring bad code into good code is one of life's greatest pleasures.



  •  I code hard all the time



  • @EJ_ said:

     I code hard all the time

     

    You should pop the stack and flush the queue every now and then-- helps you focus.



  •  TRWTF is Telerik.



  •  @toshir0 said:

     One can never forget that strangely warm feeling inside when refactoring wtf code.

    Refactoring is second only to sex.

     



  •  Whats so bad about telerik? 



  • @hoodaticus said:

     TRWTF is Telerik.

     

    TRWTF is OP for using Telerik.

     



  • @hoodaticus said:

     @toshir0 said:

     One can never forget that strangely warm feeling inside when refactoring wtf code.

    Refactoring is second only to sex.
    Let's combine the concepts. Tonight, I won't just fuck with my wife, I'll try to refactor her instead.



  • @toshir0 said:

    Refactoring is second only to sex.
    Let's combine the concepts. Tonight, I won't just fuck with my wife, I'll try to refactor her instead.

    [Michael Caine]Met this stunnin' bird last night. Factor, still wasn't satisfied, so then I refactor.[/Michael Caine]


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.