Click here to Skip to main content
15,887,585 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Set selected value... Pin
fjdiewornncalwe26-Jun-12 8:38
professionalfjdiewornncalwe26-Jun-12 8:38 
GeneralRe: Set selected value... Pin
Sandeep Mewara26-Jun-12 8:59
mveSandeep Mewara26-Jun-12 8:59 
GeneralRe: Set selected value... Pin
OriginalGriff26-Jun-12 8:46
mveOriginalGriff26-Jun-12 8:46 
GeneralRe: Set selected value... Pin
Sandeep Mewara26-Jun-12 9:01
mveSandeep Mewara26-Jun-12 9:01 
GeneralRe: Set selected value... Pin
OriginalGriff26-Jun-12 9:12
mveOriginalGriff26-Jun-12 9:12 
GeneralRe: It makes a little sense... Pin
VallarasuS26-Jun-12 22:57
VallarasuS26-Jun-12 22:57 
GeneralRe: It makes a little sense... Pin
Sandeep Mewara26-Jun-12 23:16
mveSandeep Mewara26-Jun-12 23:16 
GeneralI hope this is not contagious... Pin
CDP180225-Jun-12 22:49
CDP180225-Jun-12 22:49 
I'm cleaning up other people's mess again and came across this code to validate a date. The comments are from me, as our friend does not believe in comments or any other kind of documentation.

protected void cvaliDatum_ServerValidate(object source, ServerValidateEventArgs args)
{
    if (tbDatum.Text.Trim() != "") // useless - parsing an empty string would fail anyway 
    {
        DateTime datok;
        if (DateTime.TryParse(tbDatum.Text.Trim(), out datok))
        {
            if (datok > DateTime.Now)  // the date may not be in the future, so this should be <= and not >
            {
                TimeSpan span = DateTime.Now - datok;
                if (span.Days > 14)     // the date may not lie back more than 14 days
                {
                    if ((Konstanten.Status == -1) || (Konstanten.Status == 1))  // who knows what that's supposed to mean
                    {
                        args.IsValid = false;
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }
                else
                {
                    args.IsValid = false;
                }
            }
            else
            {
                args.IsValid = true;  // This is plain wrong - should be false            }
        }
        else
        {
            args.IsValid = false;
        }
    }
    else
    {
        args.IsValid = false;
    }
}


As a bonus, the same thing has been copied and pasted to do the validation for another date on the same page. The whole thing just would not be as much fun without some redundancy. Being constantly exposed to this kind of code, I certainly hope that whatever turned the poor author into a moron does not prove itself to be contagious.
At least artificial intelligence already is superior to natural stupidity



GeneralRe: I hope this is not contagious... Pin
OriginalGriff26-Jun-12 8:48
mveOriginalGriff26-Jun-12 8:48 
GeneralRe: I hope this is not contagious... Pin
CDP180226-Jun-12 10:40
CDP180226-Jun-12 10:40 
GeneralRe: I hope this is not contagious... Pin
Brisingr Aerowing26-Jun-12 11:58
professionalBrisingr Aerowing26-Jun-12 11:58 
GeneralRe: I hope this is not contagious... Pin
Rajesh R Subramanian30-Jun-12 10:04
professionalRajesh R Subramanian30-Jun-12 10:04 
GeneralRe: I hope this is not contagious... Pin
Brisingr Aerowing1-Jul-12 12:15
professionalBrisingr Aerowing1-Jul-12 12:15 
GeneralRe: I hope this is not contagious... Pin
ignrod27-Jun-12 1:33
ignrod27-Jun-12 1:33 
GeneralRe: I hope this is not contagious... Pin
dakovinc27-Jun-12 2:35
dakovinc27-Jun-12 2:35 
GeneralRe: I hope this is not contagious... Pin
CDP180228-Jun-12 22:21
CDP180228-Jun-12 22:21 
GeneralRe: I hope this is not contagious... Pin
Brisingr Aerowing29-Jun-12 7:16
professionalBrisingr Aerowing29-Jun-12 7:16 
GeneralRe: I hope this is not contagious... Pin
CDP180228-Jun-12 22:23
CDP180228-Jun-12 22:23 
GeneralRe: I hope this is not contagious... Pin
Bernhard Hiller28-Jun-12 21:55
Bernhard Hiller28-Jun-12 21:55 
GeneralRe: I hope this is not contagious... Pin
CDP180228-Jun-12 22:17
CDP180228-Jun-12 22:17 
GeneralString Comparison Pin
Rotted Frog25-Jun-12 18:26
Rotted Frog25-Jun-12 18:26 
GeneralRe: String Comparison Pin
Mohibur Rashid25-Jun-12 20:43
professionalMohibur Rashid25-Jun-12 20:43 
GeneralRe: String Comparison Pin
Nagy Vilmos25-Jun-12 21:59
professionalNagy Vilmos25-Jun-12 21:59 
GeneralRe: String Comparison Pin
Rotted Frog25-Jun-12 22:20
Rotted Frog25-Jun-12 22:20 
GeneralRe: String Comparison Pin
VallarasuS25-Jun-12 23:48
VallarasuS25-Jun-12 23:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.