Click here to Skip to main content
15,888,579 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: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 0:59
pasztorpisti7-Sep-13 0:59 
GeneralRe: Most Unhelpful Message Ever Pin
jeron12-Aug-13 5:30
jeron12-Aug-13 5:30 
GeneralRe: Most Unhelpful Message Ever Pin
Chad3F2-Aug-13 13:03
Chad3F2-Aug-13 13:03 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 0:49
pasztorpisti7-Sep-13 0:49 
GeneralRe: Most Unhelpful Message Ever Pin
Chad3F7-Sep-13 12:40
Chad3F7-Sep-13 12:40 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 13:09
pasztorpisti7-Sep-13 13:09 
GeneralRe: Most Unhelpful Message Ever Pin
BillW3330-Aug-13 5:35
professionalBillW3330-Aug-13 5:35 
GeneralRe: Most Unhelpful Message Ever Pin
pasztorpisti7-Sep-13 0:34
pasztorpisti7-Sep-13 0:34 
In my C/C++ code I often write similar things: assert statements. ASSERT -> "It should never happen that the specified expression evaluates to false". Of course ASSERT is usually compiled only into some non-release configurations. I use different kind of assert statements, I call one of these the "This should never happen" assert: This is an assert that always fires unconditionally with a specified message when executed. For example assert_message("Unhandled EMode enum member");
C++
enum EMode
{
    EMode_mode1,
    EMode_mode3,
};

void Func(EMode mode)
{
    switch (mode)
    {
    case EMode_mode1:
        // blah blah
        break;
    case EMode_mode2:
        // blah blah
        break;
    default:
        assert_message("Unhandled EMode enum member!");
        break;
    }
}

If someone extends the enum with a new member (and lets say the functions that use the enum are not next to the enum in your files) and some codepieces are not updated along with the enum then at least you get a runtime error sooner or later in non-release builds. Of course there are a lot of other places where "This should never happen" asserts are useful.
QuestionWhich code you suggest? Pin
Rajesh Anuhya24-Jul-13 20:04
professionalRajesh Anuhya24-Jul-13 20:04 
AnswerRe: Which code you suggest? PinPopular
NeverJustHere24-Jul-13 21:02
NeverJustHere24-Jul-13 21:02 
GeneralRe: Which code you suggest? Pin
Reelix25-Jul-13 21:36
Reelix25-Jul-13 21:36 
GeneralRe: Which code you suggest? Pin
KP Lee26-Jul-13 17:21
KP Lee26-Jul-13 17:21 
AnswerRe: Which code you suggest? Pin
_Damian S_24-Jul-13 21:02
professional_Damian S_24-Jul-13 21:02 
AnswerRe: Which code you suggest? PinPopular
Ingo25-Jul-13 3:42
Ingo25-Jul-13 3:42 
AnswerRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 4:48
professionalZurdoDev25-Jul-13 4:48 
GeneralRe: Which code you suggest? PinPopular
OriginalGriff25-Jul-13 5:04
mveOriginalGriff25-Jul-13 5:04 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 5:11
professionalZurdoDev25-Jul-13 5:11 
GeneralRe: Which code you suggest? Pin
Sentenryu25-Jul-13 7:15
Sentenryu25-Jul-13 7:15 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 7:32
professionalZurdoDev25-Jul-13 7:32 
GeneralRe: Which code you suggest? Pin
OriginalGriff25-Jul-13 8:26
mveOriginalGriff25-Jul-13 8:26 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 8:28
professionalZurdoDev25-Jul-13 8:28 
GeneralRe: Which code you suggest? Pin
OriginalGriff25-Jul-13 8:31
mveOriginalGriff25-Jul-13 8:31 
GeneralRe: Which code you suggest? Pin
ZurdoDev25-Jul-13 8:35
professionalZurdoDev25-Jul-13 8:35 
GeneralRe: Which code you suggest? Pin
Andrew Leeder25-Jul-13 22:34
Andrew Leeder25-Jul-13 22:34 
GeneralRe: Which code you suggest? Pin
OriginalGriff25-Jul-13 22:50
mveOriginalGriff25-Jul-13 22:50 

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.