Click here to Skip to main content
15,902,762 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: Magic of if...else...programming Pin
PIEBALDconsult8-Jan-09 8:25
mvePIEBALDconsult8-Jan-09 8:25 
GeneralRe: Magic of if...else...programming Pin
Luc Pattyn8-Jan-09 7:57
sitebuilderLuc Pattyn8-Jan-09 7:57 
GeneralRe: Magic of if...else...programming Pin
Stephen Hewitt11-Jan-09 1:17
Stephen Hewitt11-Jan-09 1:17 
GeneralRe: Magic of if...else...programming Pin
PIEBALDconsult8-Jan-09 3:52
mvePIEBALDconsult8-Jan-09 3:52 
GeneralRe: Magic of if...else...programming Pin
BadKarma8-Jan-09 21:11
BadKarma8-Jan-09 21:11 
GeneralRe: Magic of if...else...programming Pin
Robert Rohde9-Jan-09 2:39
Robert Rohde9-Jan-09 2:39 
GeneralRe: Magic of if...else...programming Pin
che33589-Jan-09 3:53
che33589-Jan-09 3:53 
GeneralRe: Magic of if...else...programming [modified] Pin
qualitychecker9-Jan-09 22:48
qualitychecker9-Jan-09 22:48 
Nice (and compact) solution !!
Still depends on the precedence priorities of the language / the optimization of the underlaying compiler ..
More safe and maintainable code:
------------------------------------
bool res = false;
if (null == dt)
else if (null == dt.Rows)
else if (dt.Rows.Count < 0)
else res = (1 == (int)dt.Rows[0]["Number"]);
return res;
------------------------------------

Rules to be applied :
(1) : prevent against '=' instead of '==' : always put constants first
(2) : always control potential nulls even if seems useless versus construction rules (ex null == dt.Rows)
(3) : provide debugging / tracing points in case of future problems
(4) : write readable code
(5) : single return output point

Shears and happy new year.

modified on Saturday, January 10, 2009 5:03 AM

GeneralRe: Magic of if...else...programming Pin
PIEBALDconsult10-Jan-09 4:16
mvePIEBALDconsult10-Jan-09 4:16 
GeneralRe: Magic of if...else...programming Pin
Luc Pattyn10-Jan-09 5:20
sitebuilderLuc Pattyn10-Jan-09 5:20 
GeneralRe: Magic of if...else...programming Pin
Deflinek11-Jan-09 21:48
Deflinek11-Jan-09 21:48 
GeneralRe: Magic of if...else...programming [modified] Pin
Member 448708312-Jan-09 3:11
Member 448708312-Jan-09 3:11 
GeneralRe: Magic of if...else...programming Pin
PIEBALDconsult12-Jan-09 4:12
mvePIEBALDconsult12-Jan-09 4:12 
GeneralRe: Magic of if...else...programming Pin
Timothy Byrd13-Jan-09 13:01
Timothy Byrd13-Jan-09 13:01 
GeneralRe: Magic of if...else...programming Pin
Aerman456728-Jan-09 4:15
Aerman456728-Jan-09 4:15 
GeneralRe: Magic of if...else...programming Pin
KarstenK9-Jan-09 0:54
mveKarstenK9-Jan-09 0:54 
GeneralRe: Magic of if...else...programming Pin
vaghelabhavesh7-Jan-09 13:22
vaghelabhavesh7-Jan-09 13:22 
GeneralRe: Magic of if...else...programming Pin
GibbleCH8-Jan-09 3:57
GibbleCH8-Jan-09 3:57 
GeneralRe: Magic of if...else...programming Pin
vaghelabhavesh8-Jan-09 4:52
vaghelabhavesh8-Jan-09 4:52 
GeneralRe: Magic of if...else...programming Pin
GibbleCH8-Jan-09 12:35
GibbleCH8-Jan-09 12:35 
GeneralRe: Magic of if...else...programming Pin
vaghelabhavesh8-Jan-09 16:42
vaghelabhavesh8-Jan-09 16:42 
GeneralRe: Magic of if...else...programming Pin
kenrentz13-Jan-09 6:19
kenrentz13-Jan-09 6:19 
GeneralRe: Magic of if...else...programming Pin
GibbleCH14-Jan-09 6:37
GibbleCH14-Jan-09 6:37 
GeneralRe: Magic of if...else...programming Pin
KarstenK9-Jan-09 0:55
mveKarstenK9-Jan-09 0:55 
GeneralRe: Magic of if...else...programming PinPopular
Tony Pottier10-Jan-09 8:52
Tony Pottier10-Jan-09 8:52 

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.