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

 
JokeRe: Code which caused my PC hang Pin
Yusuf8-Aug-08 11:06
Yusuf8-Aug-08 11:06 
GeneralAttack of the notepads Pin
Llasus8-Aug-08 22:08
Llasus8-Aug-08 22:08 
GeneralRe: Attack of the notepads Pin
Jonathan C Dickinson9-Aug-08 2:41
Jonathan C Dickinson9-Aug-08 2:41 
GeneralRe: Code which caused my PC hang Pin
Jamie Nordmeyer11-Aug-08 11:03
Jamie Nordmeyer11-Aug-08 11:03 
JokeRe: Code which caused my PC hang Pin
Anand Desai12-Aug-08 23:26
Anand Desai12-Aug-08 23:26 
GeneralRe: Code which caused my PC hang Pin
Jamie Nordmeyer13-Aug-08 3:52
Jamie Nordmeyer13-Aug-08 3:52 
GeneralRe: Code which caused my PC hang Pin
neilmajithia14-Aug-08 2:33
neilmajithia14-Aug-08 2:33 
RantWe need more ITT Tech programmers PinPopular
gongchengshi5-Aug-08 11:27
gongchengshi5-Aug-08 11:27 
I inherited a Borland Win32 application that has over 60 global variables interspersed throughout it. Many of the globals are multilevel struct instantiations.

Nearly every class definition has a line similar to this after it: "extern PACKAGE TTree *Tree;" The actual declarations of these variables are either in the code for the "about page", above the program's "main" function, or in "globals.cpp"

There is a file called "structs.h" which contains the definitions for every struct used in the application. structs that have to do with the database, visual controls, file contents, etc are all in the same file. The file is 6,000 lines long.

There is a file called "globals.h" that is 3,000 lines long that is nothing but #defines. The #defines are related to, you guessed it: database, individual visual controls, different file formats, and other processing specific code. The file is included in every .cpp file. Very few of the #defines have meaning in more two .cpp files.

8 of the 28 .cpp files in the project are over 10,000 lines long. The longest is 14,433 lines. Most of the code in these mammoths has nothing to do with what the file name would have you think they are doing.

Instead of using one of the hundred different XML processing libraries out there, this guy decides to write his own in order to make a way of saving data. The produced files aren't even valid XML so I can't replace it with a more efficient XML processor. I have to maintain his version of XML syntax for backward compatibility.

There isn't a single pass by reference in the entire application. It is all pointers.

There is no function polymorphism being performed. There are a ton of functions with parameters that specify the kind of data being handled with switch-cases that handle different kinds of data.

Every struct declaration looks like this: "struct CALIB_STRUCT Calib;" Always all caps, always has the "struct" keyword, and always ends with "_STRUCT".

There is no real naming scheme. Sometimes constants are all caps, sometimes they aren't, sometimes they are structs.

He declares every variable that could possibly be used by the function at the top of the function. This includes those huge structs that never get used. Get this guy a copy of the C++ standard please! Many functions are over 500 lines long. Thank goodness for split-screened editors.

The only container that is used are statically defined arrays (usually of structs) even when there is no way to know how many elements will be in it. He just makes it big and forgets about it.

There is no class inheritance, encapsulation, polymorphism, or specialization for different kinds of data. Just dozens of functions with huge multilevel switch-case statements to handle the "special" cases of each type of data.

Every function, I mean every single function, has something similar to this as its first line:
AnsiString errorHeader = "Showing Probe Calibration Error: ";
errorHeader += "Function Where Error Occurred: ";
errorHeader += "TfrmConfig::SaveCalData(); Type of error: ";

Every function, I mean every single function, has this exact code at the end (misc is a global of type TMisc):

} // end catch
catch(Exception &e)
{
errorMsg = errorHeader;
errorMsg += e.ClassName();
errorMsg += " Exception; Error message: " + e.Message;
if (Misc)
Misc->LogSystemError(errorMsg);
error = EI_KNOWN_EXCEPTION;
}
catch(...)
{
errorMsg = errorHeader + "Unknown Error";
if (Misc)
{
Misc->LogSystemError(errorMsg);
}
error = EI_UNKNOWN_EXCEPTION;
}
return error;

There is no other exception handling being performed.

The list goes on. These are just the things I can easily describe here. Overall, this guy just loves to copy and paste code. Apparently making a robust function or class specialization is just too much work.

In debugging and running the code, I find that along a single execution path functions may be needlessly called multiple times to fill visual controls with statically defined data. I am seriously terrified to run a code profiler on it. This guy wrote another similar size app here that has also landed in my lap.

Did I mention that this guy teaches at ITT Tech? He no longer works here (I replaced him). Oddly enough, he wasn't let go for incompetence.
GeneralRe: We need more ITT Tech programmers Pin
PIEBALDconsult5-Aug-08 15:12
mvePIEBALDconsult5-Aug-08 15:12 
GeneralRe: We need more ITT Tech programmers Pin
BillW333-Sep-08 4:19
professionalBillW333-Sep-08 4:19 
GeneralRe: We need more ITT Tech programmers Pin
Paul Conrad5-Aug-08 18:32
professionalPaul Conrad5-Aug-08 18:32 
GeneralRe: We need more ITT Tech programmers Pin
J4amieC5-Aug-08 22:48
J4amieC5-Aug-08 22:48 
GeneralRe: We need more ITT Tech programmers Pin
Dan Neely6-Aug-08 2:17
Dan Neely6-Aug-08 2:17 
GeneralRe: We need more ITT Tech programmers Pin
J4amieC6-Aug-08 2:25
J4amieC6-Aug-08 2:25 
GeneralRe: We need more ITT Tech programmers Pin
PIEBALDconsult6-Aug-08 5:06
mvePIEBALDconsult6-Aug-08 5:06 
GeneralRe: We need more ITT Tech programmers Pin
gongchengshi6-Aug-08 6:03
gongchengshi6-Aug-08 6:03 
GeneralRe: We need more ITT Tech programmers Pin
Dan Neely6-Aug-08 6:44
Dan Neely6-Aug-08 6:44 
JokeRe: We need more ITT Tech programmers Pin
Robert Royall6-Aug-08 9:43
Robert Royall6-Aug-08 9:43 
GeneralRe: We need more ITT Tech programmers Pin
Jörgen Sigvardsson7-Aug-08 3:20
Jörgen Sigvardsson7-Aug-08 3:20 
GeneralRe: We need more ITT Tech programmers Pin
AeonBlue7-Aug-08 4:39
AeonBlue7-Aug-08 4:39 
GeneralRe: We need more ITT Tech programmers Pin
MidwestLimey7-Aug-08 5:13
professionalMidwestLimey7-Aug-08 5:13 
GeneralRe: We need more ITT Tech programmers Pin
StevenWalsh7-Aug-08 16:40
StevenWalsh7-Aug-08 16:40 
GeneralRe: We need more ITT Tech programmers Pin
gongchengshi7-Aug-08 17:05
gongchengshi7-Aug-08 17:05 
GeneralRe: We need more ITT Tech programmers Pin
Dan Neely8-Aug-08 2:06
Dan Neely8-Aug-08 2:06 
GeneralRe: We need more ITT Tech programmers Pin
Jonathan C Dickinson9-Aug-08 2:53
Jonathan C Dickinson9-Aug-08 2:53 

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.