Click here to Skip to main content
15,887,214 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.

 
GeneralSo to really make you weep Pin
Jörgen Andersson1-Nov-12 21:28
professionalJörgen Andersson1-Nov-12 21:28 
GeneralRe: So to really make you weep Pin
_Maxxx_4-Nov-12 11:54
professional_Maxxx_4-Nov-12 11:54 
GeneralRe: So to really make you weep Pin
Jörgen Andersson4-Nov-12 22:54
professionalJörgen Andersson4-Nov-12 22:54 
GeneralRe: So to really make you weep Pin
Stefan_Lang5-Nov-12 1:33
Stefan_Lang5-Nov-12 1:33 
GeneralRe: So to really make you weep Pin
Jörgen Andersson5-Nov-12 1:38
professionalJörgen Andersson5-Nov-12 1:38 
GeneralRe: So to really make you weep Pin
Stefan_Lang5-Nov-12 2:03
Stefan_Lang5-Nov-12 2:03 
GeneralRe: So to really make you weep Pin
Jörgen Andersson5-Nov-12 2:10
professionalJörgen Andersson5-Nov-12 2:10 
GeneralRe: Trick for young players. Pin
BobJanova2-Nov-12 0:47
BobJanova2-Nov-12 0:47 
_Maxxx_ wrote:
If each object had two booleans, would it act the same?

Depends if it's a value type, and whether Equals is overridden.

_Maxxx_ wrote:
The fact that the Contains method works inconsistently depending on the contents of objects is the problem.

It does not behave differently depending on the contents. It depends differently depending on the type. You can think of it like string interning: there is only one false so when you have two of them, they are always equal, both in value terms and in reference terms. I think this is true for all value types; it's certainly true for all basic types.

_Maxxx_ wrote:
And I expect the answer to be yes or no - and not 'well, if it's an object containing only a value type, then the collection contains at least one similar Object where the value type has the same value, but if it's a reference type then that instance exists I the collection'

The answer is yes if there is an object in the collection for which Equals with the one you've passed returns true. That's what equality means, and it's usually much more useful than checking for reference equality. You can override == on custom types to make that check whatever you want. By default the behaviour is to check references for reference types and to check values for value types (or at least base types).

Choosing which constructor to use based on the values of parameters, instead of the types of parameters, is a WTF all to itself.

Edit: Equals, not ==. I always override both of these, and also !=, if I do either, so I get them mixed up sometimes.
GeneralRe: Trick for young players. Pin
_Maxxx_2-Nov-12 1:15
professional_Maxxx_2-Nov-12 1:15 
GeneralRe: Trick for young players. Pin
BobJanova2-Nov-12 1:46
BobJanova2-Nov-12 1:46 
GeneralRe: Trick for young players. Pin
_Maxxx_2-Nov-12 2:01
professional_Maxxx_2-Nov-12 2:01 
GeneralRe: Trick for young players. Pin
Harley L. Pebley2-Nov-12 6:18
Harley L. Pebley2-Nov-12 6:18 
GeneralRe: Trick for young players. Pin
_Maxxx_4-Nov-12 11:56
professional_Maxxx_4-Nov-12 11:56 
GeneralRe: Trick for young players. Pin
Sentenryu1-Nov-12 5:47
Sentenryu1-Nov-12 5:47 
GeneralRe: Trick for young players. Pin
twizzle8011-Nov-12 19:32
twizzle8011-Nov-12 19:32 
GeneralRe: Trick for young players. Pin
_Maxxx_2-Nov-12 0:07
professional_Maxxx_2-Nov-12 0:07 
GeneralRe: Trick for young players. Pin
BobJanova2-Nov-12 0:50
BobJanova2-Nov-12 0:50 
GeneralRe: Trick for young players. Pin
harold aptroot2-Nov-12 0:25
harold aptroot2-Nov-12 0:25 
GeneralRe: Trick for young players. Pin
englebart2-Nov-12 2:54
professionalenglebart2-Nov-12 2:54 
GeneralRe: Trick for young players. Pin
_Maxxx_4-Nov-12 11:49
professional_Maxxx_4-Nov-12 11:49 
GeneralRe: Trick for young players. Pin
CafedeJamaica2-Nov-12 10:54
professionalCafedeJamaica2-Nov-12 10:54 
GeneralRe: Trick for young players. Pin
AspDotNetDev2-Nov-12 11:28
protectorAspDotNetDev2-Nov-12 11:28 
GeneralRe: Trick for young players. Pin
BotReject4-Nov-12 10:54
BotReject4-Nov-12 10:54 
GeneralRe: Trick for young players. Pin
TheCoolCoder5-Nov-12 1:13
TheCoolCoder5-Nov-12 1:13 
GeneralRe: Trick for young players. Pin
_Maxxx_5-Nov-12 1:40
professional_Maxxx_5-Nov-12 1:40 

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.