Click here to Skip to main content
15,900,254 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: Update 12.03B: There are no longer 16 ounces in a Pound Pin
Netblue25-Aug-08 3:25
Netblue25-Aug-08 3:25 
GeneralRe: Update 12.03B: There are no longer 16 ounces in a Pound Pin
PIEBALDconsult26-Aug-08 3:30
mvePIEBALDconsult26-Aug-08 3:30 
GeneralRe: Update 12.03B: There are no longer 16 ounces in a Pound Pin
Paul Conrad22-Aug-08 18:06
professionalPaul Conrad22-Aug-08 18:06 
GeneralRe: Update 12.03B: There are no longer 16 ounces in a Pound Pin
Netblue23-Aug-08 3:31
Netblue23-Aug-08 3:31 
GeneralRe: Update 12.03B: There are no longer 16 ounces in a Pound Pin
Paul Conrad23-Aug-08 7:37
professionalPaul Conrad23-Aug-08 7:37 
GeneralRe: Update 12.03B: There are no longer 16 ounces in a Pound Pin
Chris Maunder25-Aug-08 5:22
cofounderChris Maunder25-Aug-08 5:22 
GeneralRe: Update 12.03B: There are no longer 16 ounces in a Pound Pin
CDP180228-Aug-08 4:22
CDP180228-Aug-08 4:22 
GeneralFinding a record by its primary key Pin
Chris Quinn21-Aug-08 5:47
Chris Quinn21-Aug-08 5:47 
When I joined my current company about three years ago, I was given the task of maintaining the company's business critical order processing system. This is written as an Access front end to a SQL Server back end, and was written by a contractor who had left at the end of his contract with a large amount of the company's money in his bank account!

Some investigation after my first week or two lead me to discover the following horrors:

There was not a single error trapping routine in the whole front end - if something fell over, the standard error message was "an error occurred in the click event of btn....."

Each routine that inserted a record was written as a Sub, rather than a function that returned a success/failure value.

Every user on the database was assigned DBO permissions!

There was absolutely no referential integrity defined in the database.

There was no transaction processing in the system - if someting fell over part way through (as it often did), updates/inserts/deletes had to be rolled back manually using Enterprise manager.

An example of his coding style is shown here - it shows how he retrieved a single record using its primary key:

Set rstMain = New ADODB.Recordset
Set cmd = New ADODB.Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "spSELocationForSageImport"
Set prm = cmd.CreateParameter("@LocationCode", adVarChar, adParamInput, 20, "Sage")
cmd.Parameters.Append prm
cmd.CommandType = adCmdStoredProc
rstMain.Open cmd, , adOpenDynamic, adLockOptimistic, adCmdStoredProc

With rstMain
    Do While Not .EOF
        strLocation = ![Location]
        .MoveNext
    Loop
End With
Set rstMain = Nothing


Maybe I'm missing something, but do you need to loop though a dataset that can only contain one record?

His date handling was also a bit esoteric:

txtDateCreated = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())


I recently had occasion to rewrite some of his code that applied changes from an external system to the database. His code took two or more hours to run and slowed the system so much it was unusable (meaning I usually had to do unpaid overtime to apply the data out of hours). One of the lovely bits of code he wrote looped through a data set of 7000+ records, taking a value from each record and using this as a parameter in a stored procedure that retrieved a related value from a lookup table. Changing the source query of the main dataset to join it to the lookup table and return the value directly removed 7000+ executions of the stored procedure.

Tweaking the query, adding an index and cleaning up his code reduced the run time to approximately 3 minutes!


====================================
Transvestites - Roberts in Disguise!
====================================

GeneralRe: Finding a record by its primary key Pin
MidwestLimey21-Aug-08 7:58
professionalMidwestLimey21-Aug-08 7:58 
GeneralRe: Finding a record by its primary key Pin
leppie21-Aug-08 8:01
leppie21-Aug-08 8:01 
GeneralRe: Finding a record by its primary key Pin
leppie21-Aug-08 8:00
leppie21-Aug-08 8:00 
GeneralRe: Finding a record by its primary key Pin
Paul Conrad21-Aug-08 16:48
professionalPaul Conrad21-Aug-08 16:48 
GeneralRe: Finding a record by its primary key Pin
Chris Quinn21-Aug-08 22:02
Chris Quinn21-Aug-08 22:02 
GeneralRe: Finding a record by its primary key Pin
Paul Conrad22-Aug-08 6:25
professionalPaul Conrad22-Aug-08 6:25 
GeneralRe: Finding a record by its primary key Pin
Pete O'Hanlon22-Aug-08 9:18
mvePete O'Hanlon22-Aug-08 9:18 
GeneralRe: Finding a record by its primary key Pin
Dan Neely22-Aug-08 9:32
Dan Neely22-Aug-08 9:32 
GeneralRe: Finding a record by its primary key Pin
Paul Conrad22-Aug-08 9:40
professionalPaul Conrad22-Aug-08 9:40 
QuestionRe: Finding a record by its primary key Pin
developer626-Aug-08 1:49
developer626-Aug-08 1:49 
AnswerRe: Finding a record by its primary key Pin
Pete O'Hanlon26-Aug-08 1:58
mvePete O'Hanlon26-Aug-08 1:58 
QuestionRe: Finding a record by its primary key Pin
developer626-Aug-08 2:07
developer626-Aug-08 2:07 
AnswerRe: Finding a record by its primary key Pin
Dan Neely26-Aug-08 2:19
Dan Neely26-Aug-08 2:19 
GeneralRe: Finding a record by its primary key Pin
Paul Conrad22-Aug-08 9:36
professionalPaul Conrad22-Aug-08 9:36 
GeneralRe: Finding a record by its primary key Pin
SilimSayo25-Aug-08 3:52
SilimSayo25-Aug-08 3:52 
GeneralRe: Finding a record by its primary key Pin
Nathan Tuggy25-Aug-08 8:45
Nathan Tuggy25-Aug-08 8:45 
GeneralRe: Finding a record by its primary key Pin
Nathan Tuggy25-Aug-08 8:46
Nathan Tuggy25-Aug-08 8:46 

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.