Any comments on this little gem of .net code?



  • I found an entire file full of them in a .net application I'm working on. I'm trying to understand what this person was thinking.

    public static string DecimalToGUI(decimal val) { if (val != Constants.DECIMAL_NULL) { return decimal.ToInt64(val).ToString(); } else { return Constants.STRING_NULL; } }


  • I think it demonstrates your naïveté to assume that they were thinking at all.



  • here is another

    public static System.DateTime GUIToDate(string stringDate) { if (stringDate.Length > 0) { return System.Convert.ToDateTime(stringDate.Trim().Replace(".", "-")); } else { return Constants.DATE_NULL; } }


  •  If written by a contractor, they were thinking of their pension.

    Or maybe wondering if it was time for their meds yet.



  •  What constants/values are there in Constants?



  •  @rohypnol said:

     What constants/values are there in Constants?

    Pffft - All of them of course!



  • Dude, i think your functions are gorgeous.

    Instead of altering its purity, why not to add something coherent to this masterpiece? Here's my little grain of sand.


    /// <summary>
    /// Brilliant function. Returns a valid sting value as string from a sting.
    /// </summary>
    /// <param name="Sting">a Sting string</param>
    /// <returns>A valid sting value in string format</returns>
    public static string StingToString (string Sting){
        if (Sting != Constants.STING){
            return Constants.STING;
        }else{
            return Sting;
        }
    }




  • Yo dawg, I herd you like code, so I put a sting in your string so you can return while you return.

    Yeah, I probably didn't do it right.



  • All of the constants in the application are in Constants including

    <script> public static string STRING_NULL = ""; public static string STRING_NEW = "NEW"; public static int INTEGER_NULL = int.MinValue; public static byte BYTE_NULL = byte.MinValue; public static long LONG_NULL = long.MinValue; public static System.DateTime DATE_NULL = new System.DateTime(1900, 1, 1); public static double DOUBLE_NULL = double.MinValue; public static decimal DECIMAL_NULL = decimal.MinValue; </script>

    I guess they don't know anything about string.Empty



  • @Kev777 said:

    I found an entire file full of them in a .net application I'm working on. I'm trying to understand what this person was thinking.

    public static string DecimalToGUI(decimal val) { if (val != Constants.DECIMAL_NULL) { return decimal.ToInt64(val).ToString(); } else { return Constants.STRING_NULL; } }
    You'll be grateful for his conscientiousness when the C# group realise that the Excel people were right all along, and make decimal.ToInt64(null) return 0 in the next version.


  • Let me make that more clear so the WTF is emphasized:@Kev777 said:

    /* All of the constants in the application are in Constants including /
    public static string STRING_NULL = "";
    public static string STRING_NEW = "NEW";
    public static int INTEGER_NULL = int.MinValue;
    public static byte BYTE_NULL = byte.MinValue;
    public static long LONG_NULL = long.MinValue;
    public static System.DateTime DATE_NULL = new System.DateTime(1900, 1, 1);
    public static double DOUBLE_NULL = double.MinValue;
    public static decimal DECIMAL_NULL = decimal.MinValue;
    /
    I guess they don't know anything about string.Empty */
    They're using C# so they get nullable types for free, but instead of an actual null they reuse a value which "shouldn't happen" to mean null, and as a result have to write their own toString() and parse() functions to account for the discrepancy.


Log in to reply
 

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