Click here to Skip to main content
15,912,072 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: Try Catch Pin
cpkilekofp7-Nov-08 5:44
cpkilekofp7-Nov-08 5:44 
GeneralRe: Try Catch Pin
Kevin McFarlane5-Nov-08 23:42
Kevin McFarlane5-Nov-08 23:42 
GeneralRe: Try Catch Pin
supercat96-Nov-08 6:07
supercat96-Nov-08 6:07 
GeneralRe: Try Catch Pin
DrWheetos7-Nov-08 22:04
DrWheetos7-Nov-08 22:04 
GeneralRe: Try Catch Pin
supercat98-Nov-08 10:05
supercat98-Nov-08 10:05 
GeneralA big if Pin
ClementsDan1-Nov-08 18:42
ClementsDan1-Nov-08 18:42 
GeneralRe: A big if Pin
PIEBALDconsult2-Nov-08 3:04
mvePIEBALDconsult2-Nov-08 3:04 
AnswerRe: C/C++ or C#? [modified] Pin
Thomas Weller2-Nov-08 20:13
Thomas Weller2-Nov-08 20:13 
Let's assume it's C++.

I consider sth. like the code above generally bad coding style. There is far to much nesting here. Supposed that most of the programmers (at least the ones I know, including myself) make an indentation of four spaces (not only two as in the 'sample'), you would quickly run out of monitor space...

I would suggest a kind of 'waterfall style' coding here:

if ((nErrorCode = cFtpConn.SetHost(HOST)) != 0)
{
    Log(...);
    return;
}
  
if ((nErrorCode = ...
{
    Log(...);
    return;
}

...


This is also not perfect since it introduces many returns, but it improves the readability of the code and the return conditions are trivial and repetitive.

PIEBALDconsult wrote:
If it's C#, the methods should probably throw Exceptions.

Agreed. In a perfect world, C# - Methods would always throw exceptions and never signal an error by means of a return value. (As long as this is affordable in terms of performance).

Regards
Thomas

modified on Monday, November 3, 2008 4:55 AM

GeneralRe: C/C++ or C#? Pin
Nagy Vilmos2-Nov-08 22:28
professionalNagy Vilmos2-Nov-08 22:28 
GeneralRe: C/C++ or C#? Pin
PIEBALDconsult3-Nov-08 4:03
mvePIEBALDconsult3-Nov-08 4:03 
GeneralRe: C/C++ or C#? Pin
Nemanja Trifunovic3-Nov-08 8:24
Nemanja Trifunovic3-Nov-08 8:24 
GeneralRe: C/C++ or C#? Pin
Thomas Weller3-Nov-08 8:48
Thomas Weller3-Nov-08 8:48 
GeneralRe: C/C++ or C#? Pin
Nemanja Trifunovic3-Nov-08 9:11
Nemanja Trifunovic3-Nov-08 9:11 
GeneralRe: C/C++ or C#? Pin
Thomas Weller3-Nov-08 9:35
Thomas Weller3-Nov-08 9:35 
GeneralRe: C/C++ or C#? Pin
Nemanja Trifunovic3-Nov-08 9:58
Nemanja Trifunovic3-Nov-08 9:58 
GeneralRe: C/C++ or C#? Pin
Thomas Weller3-Nov-08 10:08
Thomas Weller3-Nov-08 10:08 
GeneralRe: C/C++ or C#? Pin
Nemanja Trifunovic3-Nov-08 10:28
Nemanja Trifunovic3-Nov-08 10:28 
GeneralRe: C/C++ or C#? Pin
Thomas Weller4-Nov-08 3:19
Thomas Weller4-Nov-08 3:19 
GeneralRe: C/C++ or C#? Pin
Dan Neely3-Nov-08 10:13
Dan Neely3-Nov-08 10:13 
GeneralRe: C/C++ or C#? Pin
Thomas Weller3-Nov-08 10:17
Thomas Weller3-Nov-08 10:17 
GeneralRe: C/C++ or C#? Pin
Nemanja Trifunovic3-Nov-08 10:35
Nemanja Trifunovic3-Nov-08 10:35 
GeneralRe: C/C++ or C#? Pin
Dan Neely4-Nov-08 2:16
Dan Neely4-Nov-08 2:16 
GeneralRe: C/C++ or C#? Pin
Nemanja Trifunovic4-Nov-08 4:29
Nemanja Trifunovic4-Nov-08 4:29 
GeneralRe: C/C++ or C#? Pin
supercat95-Nov-08 6:18
supercat95-Nov-08 6:18 
GeneralRe: C/C++ or C#? Pin
Thomas Weller5-Nov-08 6:48
Thomas Weller5-Nov-08 6:48 

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.