Abuse of properties



  • Just saw this submitted into source control,

    
            public string Height
            {
                set
                {
                    ucClassCodeMapping.Height = value;
                    ucConditionMapping.Height = value;
                    ucFramingMapping.Height = value;
                    ucImprovementSizeMapping.Height = value;
                    ucQualityMapping.Height = value;
                    ucStructuralElementsMapping.Height = value;
                    ucStylesMapping.Height = value;
                    ucUnitCountsMapping.Height = value;
                    ucUsesMapping.Height = value;
                    double _height = (new Unit(value)).Value;
                    _height -= lblCloneFrom.Height.Value;
                    ucImprClone.Height = _height.ToString() + "px";
                    _height -= lblImprType.Height.Value;
                    _height -= cbImprovemntType.Height.Value;
                    _height -= lblImprStyle.Height.Value;
                    _height -= 50;
                    dtgImprClone.Height = new Unit(_height);
                    dtgImprClone.ClientSettings.Scrolling.ScrollHeight = new Unit(_height);
                }
            }
    


  • That one's easy: The author is a DBA-turned-developer. This is not actually a property, it's a writeable view.



  • Now *thats* how you do encapsulation, or something...

    I like the hardcoded -= 50, and that he declared a new instance of Unit 3 times...  Man, this is painful to look at.

    Wait, this is telerik, isn't it?  HA!  Now you have two problems...



  • I don't particular care about the declaration of Unit 3 times, if it's lightweight.  On the other hand...

    (new Unit(value)).Value;

    >.>



  • @Sutherlands said:

    I don't particular care about the declaration of Unit 3 times, if it's lightweight.  On the other hand...

    (new Unit(value)).Value;

    >.>

    That actually does make sense. value is a String, while (new Unit(value)).Value is a double. Presumably the Unit constructor does some parsing of the string to store it as a double. Would have made more sense to have it as a static function though.



  •  There are already a couple of static functions in the standard libraries to parse the string as a double. double.Parse and Convert.ToDouble.



  • @C-Octothorpe said:

    Now thats how you do encapsulation, or something...

    I like the hardcoded -= 50, and that he declared a new instance of Unit 3 times...  Man, this is painful to look at.

    Wait, this is telerik, isn't it?  HA!  Now you have two problems...

    Yep, good guess on it using Telerik :)



  • @Mo6eB said:

    @Sutherlands said:

    I don't particular care about the declaration of Unit 3 times, if it's lightweight.  On the other hand...

    (new Unit(value)).Value;

    >.>

    That actually does make sense. value is a String, while (new Unit(value)).Value is a double. Presumably the Unit constructor does some parsing of the string to store it as a double. Would have made more sense to have it as a static function though.

    value can't be a string, otherwise the subtractions would fail since the properties on the right side of the -= have the same value as value.

    Making us talk about values called value just adds do the WTF. This is sure to lead to some communication problems among the devs.



  • Actually, Unit.Value is double as can been seen by the way it assigns it's value to the variable (double) _height.  But here's the kicker: Unit.Value specifies the *lenght* of a webcontrol (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.unit.value.aspx) but is being used as height.  At the very least, this is misleading for any unfortunate future developer maintaining this pile of garbage.



  • @C-Octothorpe said:

    Actually, Unit.Value is double as can been seen by the way it assigns it's value to the variable (double) _height.  But here's the kicker: Unit.Value specifies the *lenght* of a webcontrol (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.unit.value.aspx) but is being used as height.  At the very least, this is misleading for any unfortunate future developer maintaining this pile of garbage.

     

    What? Your link says that Unit.Value specifies the length of the Unit. Both the Width and the Height of a WebControl are of type Unit.



  • Sorry, didn't proof read before posting...  Either way, this is still a confusing bunch of code that was probably born from multiple devs adding to this control without wanting to understand or touch too much.



  • [quote user="Renan "C#" Sousa"]@Mo6eB said:

    @Sutherlands said:

    I don't particular care about the declaration of Unit 3 times, if it's lightweight.  On the other hand...

    (new Unit(value)).Value;

    >.>

    That actually does make sense. value is a String, while (new Unit(value)).Value is a double. Presumably the Unit constructor does some parsing of the string to store it as a double. Would have made more sense to have it as a static function though.

    value can't be a string, otherwise the subtractions would fail since the properties on the right side of the -= have the same value as value.

    Making us talk about values called value just adds do the WTF. This is sure to lead to some communication problems among the devs.

    [/quote] 

    You are wrong, two times.

    First, "value" is not a variable. It is part of property setter, implicit variable like "this". It is value assigned to "Height" property.

    Second, because "Height" is string, then "value" is also string.

     

     



  • @spamcourt said:

    [quote user="Renan "C#" Sousa"]@Mo6eB said:

    @Sutherlands said:

    I don't particular care about the declaration of Unit 3 times, if it's lightweight.  On the other hand...

    (new Unit(value)).Value;

    >.>

    That actually does make sense. value is a String, while (new Unit(value)).Value is a double. Presumably the Unit constructor does some parsing of the string to store it as a double. Would have made more sense to have it as a static function though.

    value can't be a string, otherwise the subtractions would fail since the properties on the right side of the -= have the same value as value.

    Making us talk about values called value just adds do the WTF. This is sure to lead to some communication problems among the devs.

     

    You are wrong, two times.

    First, "value" is not a variable. It is part of property setter, implicit variable like "this". It is value assigned to "Height" property.

    Second, because "Height" is string, then "value" is also string.[/quote]

    I could be wrong, but I think he was referring to this: new Unit(value).Value which is a double.



  • @spamcourt said:

    [quote user="Renan "C#" Sousa"]@Mo6eB said:

    @Sutherlands said:

    I don't particular care about the declaration of Unit 3 times, if it's lightweight.  On the other hand...

    (new Unit(value)).Value;

    >.>

    That actually does make sense. value is a String, while (new Unit(value)).Value is a double. Presumably the Unit constructor does some parsing of the string to store it as a double. Would have made more sense to have it as a static function though.

    value can't be a string, otherwise the subtractions would fail since the properties on the right side of the -= have the same value as value.

    Making us talk about values called value just adds do the WTF. This is sure to lead to some communication problems among the devs.

     

    You are wrong, two times.

    First, "value" is not a variable. It is part of property setter, implicit variable like "this". It is value assigned to "Height" property.

    Second, because "Height" is string, then "value" is also string.

     

     

    [/quote]

    Unless they've overloaded the -= operator, you can't subtract a string. I'm inferring it's a double from the operations done to it. Hence I say it .NET wouldn't let you get away with that should value be a string.



  • Where is he actually subtracting "value"? The only subtractions I see are from other variables, he's only assigning height to (assumed) strings.



  • @Valarnin said:

    Where is he actually subtracting "value"? The only subtractions I see are from other variables, he's only assigning height to (assumed) strings.

    ...

    I think I got some attention-deficit-disorder or something. Read the thing again, and you guys are right.



  • [quote user="Renan "C#" Sousa"]@Valarnin said:

    Where is he actually subtracting "value"? The only subtractions I see are from other variables, he's only assigning height to (assumed) strings.

    ...

    I think I got some attention-deficit-disorder or something. Read the thing again, and you guys are right.

    [/quote]

    I think you got the Overcorrecting Dickweed Disorder (ODD)

    Don't worry, you are not alone



  • @serguey123 said:

    [quote user="Renan "C#" Sousa"]@Valarnin said:

    Where is he actually subtracting "value"? The only subtractions I see are from other variables, he's only assigning height to (assumed) strings.

    ...

    I think I got some attention-deficit-disorder or something. Read the thing again, and you guys are right.

    I think you got the Overcorrecting Pedantic Dickweed Disorder (OPDD)

    Don't worry, you are not alone

    [/quote] 

    FTFY.



  • @Someone You Know said:

    @serguey123 said:

    [quote user="Renan "C#" Sousa"]@Valarnin said:

    Where is he actually subtracting "value"? The only subtractions I see are from other variables, he's only assigning height to (assumed) strings.

    ...

    I think I got some attention-deficit-disorder or something. Read the thing again, and you guys are right.

    I think you got the Overcorrecting Pedantic Dickweed Disorder (OPDD)

    Don't worry, you are not alone

     

    FTFY.

    [/quote]

    See Renan, found one already



  • Although not necessarily elegant, I realy do not see a significan WTF.

     The string is very important, and to the best of my knowlege there are no "standard libraries" that will take a string of '200cm" and return 200 as the Value (double) and set the unites as enumeration (chart below). Plus Unit can do mixed mode (add inchest pixels and get a result in pica).

    The only thing a bit troubling is the magic "50", which is resumable for some type of border...

    PixelMeasurement is in pixels.
    PointMeasurement is in points. A point represents 1/72 of an inch.
    PicaMeasurement is in picas. A pica represents 12 points.
    InchMeasurement is in inches.
    MmMeasurement is in millimeters.
    CmMeasurement is in centimeters.
    PercentageMeasurement is a percentage relative to the parent element.
    EmMeasurement is relative to the height of the parent element's font.
    ExMeasurement is relative to the height of the lowercase letter x of the parent element's font.

Log in to reply