Click here to Skip to main content
15,887,289 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: return value optimization Pin
BobJanova17-May-12 2:04
BobJanova17-May-12 2:04 
GeneralRe: return value optimization Pin
Vasily Tserekh21-May-12 8:01
Vasily Tserekh21-May-12 8:01 
GeneralRe: return value optimization Pin
BobJanova16-May-12 22:59
BobJanova16-May-12 22:59 
GeneralRe: return value optimization Pin
Mohibur Rashid17-May-12 0:12
professionalMohibur Rashid17-May-12 0:12 
GeneralRe: return value optimization Pin
BobJanova17-May-12 0:55
BobJanova17-May-12 0:55 
GeneralRe: return value optimization Pin
jsc4221-May-12 22:13
professionaljsc4221-May-12 22:13 
GeneralRe: return value optimization Pin
BobJanova21-May-12 23:51
BobJanova21-May-12 23:51 
GeneralRe: return value optimization Pin
jsc4222-May-12 0:11
professionaljsc4222-May-12 0:11 
BobJanova wrote:
Can't you just cast to boolean instead of using !!?

Yes, you could. Casting could be done using
JavaScript
return Boolean(flag);
Note that
JavaScript
return new Boolean(flag); 
would return a Boolean object whereas without the new keyword, you'd be casting to a Boolean primitive. Greater clarity could be effected by using the triadic operator:
JavaScript
return flag ? true : false; 
or you could use short circuiting, viz
JavaScript
return flag && true;
but using ! ! flag is more succinct.

(I noticed yesterday a piece of jQuery that used !1 for false - I wouldn't go that far in obfuscation).
GeneralRe: return value optimization Pin
Rahul Rajat Singh17-May-12 1:03
professionalRahul Rajat Singh17-May-12 1:03 
GeneralRe: return value optimization Pin
Mohibur Rashid17-May-12 1:52
professionalMohibur Rashid17-May-12 1:52 
GeneralRe: return value optimization Pin
Rahul Rajat Singh17-May-12 2:01
professionalRahul Rajat Singh17-May-12 2:01 
GeneralRe: return value optimization Pin
BillW3317-May-12 3:10
professionalBillW3317-May-12 3:10 
Generalcome on give me a break !! PinPopular
Ankush Bansal12-May-12 2:03
Ankush Bansal12-May-12 2:03 
GeneralRe: come on give me a break !! Pin
StM0n13-May-12 23:43
StM0n13-May-12 23:43 
GeneralRe: come on give me a break !! Pin
Ankush Bansal14-May-12 1:49
Ankush Bansal14-May-12 1:49 
GeneralRe: come on give me a break !! Pin
StM0n14-May-12 2:17
StM0n14-May-12 2:17 
GeneralRe: come on give me a break !! Pin
BobJanova14-May-12 0:30
BobJanova14-May-12 0:30 
GeneralRe: come on give me a break !! PinPopular
Rahul Rajat Singh14-May-12 2:25
professionalRahul Rajat Singh14-May-12 2:25 
GeneralRe: come on give me a break !! Pin
Jan Steyn14-May-12 4:11
Jan Steyn14-May-12 4:11 
GeneralRe: come on give me a break !! Pin
BillW3314-May-12 3:00
professionalBillW3314-May-12 3:00 
GeneralRe: come on give me a break !! Pin
OriginalGriff14-May-12 3:39
mveOriginalGriff14-May-12 3:39 
GeneralRe: come on give me a break !! Pin
cptKoala14-May-12 3:55
cptKoala14-May-12 3:55 
AnswerRe: come on give me a break !! Pin
AspDotNetDev15-May-12 22:20
protectorAspDotNetDev15-May-12 22:20 
GeneralRe: come on give me a break !! Pin
BillW3316-May-12 2:47
professionalBillW3316-May-12 2:47 
GeneralRe: come on give me a break !! Pin
Ankush Bansal16-May-12 18:50
Ankush Bansal16-May-12 18: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.