Click here to Skip to main content
15,911,132 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: Switch boolean.... (reinventing if, unnecessarily) Pin
chaosworrier_oz29-Jun-15 17:55
chaosworrier_oz29-Jun-15 17:55 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
TheGreatAndPowerfulOz30-Jun-15 9:13
TheGreatAndPowerfulOz30-Jun-15 9:13 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Jörgen Sigvardsson1-Jul-15 3:44
Jörgen Sigvardsson1-Jul-15 3:44 
GeneralRe: Switch boolean.... (reinventing if, unnecessarily) Pin
Bernhard Hiller1-Jul-15 8:06
Bernhard Hiller1-Jul-15 8:06 
JokeFun with Generic Enum Constraint PinPopular
Bernhard Hiller9-Jun-15 22:11
Bernhard Hiller9-Jun-15 22:11 
GeneralRe: Fun with Generic Enum Constraint Pin
Daniel Pfeffer9-Jun-15 22:29
professionalDaniel Pfeffer9-Jun-15 22:29 
GeneralRe: Fun with Generic Enum Constraint Pin
Agent__0079-Jun-15 22:31
professionalAgent__0079-Jun-15 22:31 
GeneralRe: Fun with Generic Enum Constraint Pin
Brisingr Aerowing10-Jun-15 8:50
professionalBrisingr Aerowing10-Jun-15 8:50 
GeneralRe: Fun with Generic Enum Constraint Pin
Bernhard Hiller12-Jun-15 4:35
Bernhard Hiller12-Jun-15 4:35 
GeneralRe: Fun with Generic Enum Constraint Pin
Brisingr Aerowing12-Jun-15 11:31
professionalBrisingr Aerowing12-Jun-15 11:31 
GeneralRe: Fun with Generic Enum Constraint Pin
PIEBALDconsult17-Jun-15 5:00
mvePIEBALDconsult17-Jun-15 5:00 
GeneralRe: Fun with Generic Enum Constraint Pin
Richard Deeming17-Jun-15 5:45
mveRichard Deeming17-Jun-15 5:45 
GeneralRe: Fun with Generic Enum Constraint Pin
PIEBALDconsult17-Jun-15 5:56
mvePIEBALDconsult17-Jun-15 5:56 
GeneralRe: Fun with Generic Enum Constraint Pin
greldak25-Jun-15 21:58
greldak25-Jun-15 21:58 
GeneralRe: Fun with Generic Enum Constraint Pin
James Curran1-Jul-15 5:19
James Curran1-Jul-15 5:19 
GeneralWPF ValidationErrors Pin
Bernhard Hiller29-May-15 4:28
Bernhard Hiller29-May-15 4:28 
GeneralRe: WPF ValidationErrors Pin
Brisingr Aerowing29-May-15 5:11
professionalBrisingr Aerowing29-May-15 5:11 
JokeMessage Closed Pin
29-May-15 5:14
User 113800029-May-15 5:14 
GeneralRe: WPF ValidationErrors Pin
Bernhard Hiller29-May-15 5:35
Bernhard Hiller29-May-15 5:35 
GeneralRe: WPF ValidationErrors Pin
Eddy Vluggen29-May-15 5:46
professionalEddy Vluggen29-May-15 5:46 
GeneralRe: WPF ValidationErrors Pin
Brisingr Aerowing29-May-15 6:00
professionalBrisingr Aerowing29-May-15 6:00 
GeneralRe: WPF ValidationErrors Pin
Eddy Vluggen29-May-15 5:43
professionalEddy Vluggen29-May-15 5:43 
GeneralRe: WPF ValidationErrors Pin
Richard Deeming29-May-15 6:08
mveRichard Deeming29-May-15 6:08 
GeneralRe: WPF ValidationErrors Pin
Bernhard Hiller31-May-15 23:49
Bernhard Hiller31-May-15 23:49 
That's a good point. Their reason is totally valid. But their solution is NOT.
When an error has to be replaced by a different error, the system is in an invalid state when only one of the two steps of adding the new error and removing the old error has been completed. Two errors on the field are as wrong as no error on it. It's similar to transferring money from one bank account to another bank account: do not create or loose money by omitting one step. A solution could be a transaction.
But I think the simplest solution here is similar to a PropertyChanged event. Get rid of the Added/Removed enum, and take two error properties: OldError and NewError.
When you leave the valid state, NewError contains the error which is now communicated with Added, and OldError is null.
When an error gets replaced by a different error, NewError contains the freshly incurred error (now with Added), and OldError the previously encountered error (now with Removed).
When you return to a valid state, NewError is null, and OldError the previously encountered error (now with Removed).
That's a better solution, isn't it?
GeneralRe: WPF ValidationErrors Pin
Richard Deeming1-Jun-15 1:50
mveRichard Deeming1-Jun-15 1: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.