Click here to Skip to main content
15,887,328 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: Logic PinPopular
_Erik_18-May-11 3:45
_Erik_18-May-11 3:45 
GeneralRe: Logic Pin
Fabio V Silva18-May-11 4:09
Fabio V Silva18-May-11 4:09 
GeneralRe: Logic Pin
_Erik_18-May-11 4:29
_Erik_18-May-11 4:29 
GeneralRe: Logic Pin
Keith Barrow18-May-11 5:03
professionalKeith Barrow18-May-11 5:03 
GeneralRe: Logic Pin
Shameel18-May-11 23:55
professionalShameel18-May-11 23:55 
GeneralRe: Logic Pin
Nagy Vilmos19-May-11 0:04
professionalNagy Vilmos19-May-11 0:04 
GeneralRe: Logic Pin
gumi_r@msn.com20-May-11 0:02
gumi_r@msn.com20-May-11 0:02 
GeneralRe: Logic PinPopular
_Erik_20-May-11 4:09
_Erik_20-May-11 4:09 
Come on, guys. Stop this mess, ok? I don't pretend to know the absolute truth about this but, man, you are wrong or, at least, you might be confusing beginners.

The fact that, as you say, "both terms are evaluated no matter what the first expression evaluates to" with the & operator is the key, and it is not a trivial difference. See this example:

C#
string s = null;
bool b1 = s != null && s.Length == 0;
bool b2 = s != null & s.Length == 0;


You see the operands here are boolean expressions. However, while b1 would be assigned false without any problem, a runtime NullReferenceException would be thrown when trying to assing the value to b2. This is a really important difference. Both operands are not the same and can never be considered as if they were the same. Under some circumstances they can return the same result, yes, but that does not mean that they are exactly the same or that you can use any of them when you use boolean expressions.

Can we, please, go on with our lifes now?
GeneralRe: Logic Pin
OriginalGriff20-May-11 4:22
mveOriginalGriff20-May-11 4:22 
GeneralRe: Logic Pin
Nathan D Cook20-May-11 4:10
Nathan D Cook20-May-11 4:10 
GeneralRe: Logic Pin
OriginalGriff20-May-11 4:21
mveOriginalGriff20-May-11 4:21 
GeneralRe: Logic Pin
Manfred Rudolf Bihy20-May-11 4:38
professionalManfred Rudolf Bihy20-May-11 4:38 
GeneralRe: Logic Pin
OriginalGriff20-May-11 4:43
mveOriginalGriff20-May-11 4:43 
GeneralRe: Logic Pin
BobJanova20-May-11 4:46
BobJanova20-May-11 4:46 
GeneralRe: Logic Pin
Shameel25-May-11 8:31
professionalShameel25-May-11 8:31 
GeneralRe: Logic Pin
Nagy Vilmos20-May-11 5:13
professionalNagy Vilmos20-May-11 5:13 
GeneralRe: Logic Pin
sucram23-May-11 2:51
sucram23-May-11 2:51 
GeneralRe: Logic Pin
Timothy Byrd23-May-11 16:25
Timothy Byrd23-May-11 16:25 
GeneralRe: Logic Pin
Rob Grainger23-May-11 23:56
Rob Grainger23-May-11 23:56 
GeneralRe: Logic Pin
Timothy Byrd24-May-11 9:09
Timothy Byrd24-May-11 9:09 
JokeRe: Logic Pin
Firo Atrum Ventus24-May-11 21:36
Firo Atrum Ventus24-May-11 21:36 
GeneralRe: Logic Pin
James Lonero25-May-11 11:24
James Lonero25-May-11 11:24 
JokeGlitch PinPopular
Viktor Signaievskyi13-May-11 22:01
Viktor Signaievskyi13-May-11 22:01 
GeneralRe: Glitch Pin
walterhevedeich15-May-11 14:35
professionalwalterhevedeich15-May-11 14:35 
GeneralRe: Glitch Pin
Viktor Signaievskyi17-May-11 8:42
Viktor Signaievskyi17-May-11 8:42 

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.