Click here to Skip to main content
15,895,011 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: Readable code, taken too far (too Swift)? Pin
raddevus7-Jan-19 1:56
mvaraddevus7-Jan-19 1:56 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Ravi Bhavnani21-Jan-19 5:06
professionalRavi Bhavnani21-Jan-19 5:06 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus21-Jan-19 5:12
mvaraddevus21-Jan-19 5:12 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Ravi Bhavnani21-Jan-19 6:26
professionalRavi Bhavnani21-Jan-19 6:26 
GeneralRe: Readable code, taken too far (too Swift)? Pin
raddevus21-Jan-19 7:31
mvaraddevus21-Jan-19 7:31 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Ravi Bhavnani21-Jan-19 9:11
professionalRavi Bhavnani21-Jan-19 9:11 
GeneralRe: Readable code, taken too far (too Swift)? Pin
Dr.Walt Fair, PE7-May-19 5:46
professionalDr.Walt Fair, PE7-May-19 5:46 
Generalpersonal worst... Pin
DerekT-P19-Nov-18 7:07
professionalDerekT-P19-Nov-18 7:07 
Have just been asked to take over support for a live website. It's a mix of Classic ASP and ASP.Net. It runs on Windows Server 2003, .Net Framework 1.1, on a box running in the client's office. The business depends on the application.
Because there's a mix of classic and .Net, and the login authentication is done in Classic with a login token stored in the Classic Session object, login status is inaccessible to the .Net pages. So you can just enter the URL of a .net page and you get full access to everything. Neat!

The .ASPX pages are written exactly as Classic ASP; no code-behind, absolutely no separation of UI and business logic. HTML interspersed with VB.Net. Variables are defined without any type in most cases. There is no concept of objects and absolutely no code re-use (e.g. most pages can send emails, and there's all the code needed to setup an SMTP client on every page). Some pages connect to the database using ODBC and OLEDB concurrently, and the connection strings for each are hard-coded in the pages themselves.

Came across this little snippet just now...
The page has about 20 bound controls, dropdown lists, all setup the same way:
VBScript
mySelect = "select product_id, name from mytable"
If Request.QueryString("cust_id") <> "0" Then
    mySelect = mySelect + "	WHERE cust_id=" & Request.QueryString("cust_id")
End If
mySelect = mySelect + " order by name"
myDBCommand = New OleDbCommand(mySelect, myConnection)
myDBReader = myDBCommand.ExecuteReader()
lstBox1.DataSource = myDBReader
lstBox1.DataTextField = "name"
lstBox1.DataValueField = "product_id"
lstBox1.DataBind()
myDBReader.Close()
myDBReader = myDBCommand.ExecuteReader()
iLoop = 0
Do While myDBReader.Read And iLoop < 10000
    If product_id = myDBReader("product_id") Then '' (product_id is set previously)
	lstBox1.SelectedIndex = iLoop
	iLoop = 10000
    End If
    iLoop = iLoop + 1
Loop
myDBReader.Close()

I don't know what I like least about this. The lack of validation of the querystring parameter; the concatenation of the query string into the SQL statement (ripe for SQL injection); the re-opening (i.e. re-execution) of the data reader; the looping through all the rows to match the existing value; the arbitrary limit of 10000 on the loop; the setting of the loop counter to 10000 rather than 9998 to exit the loop ... almost every line makes my head hurt.

There's hundreds of pages written like this. Of which about 10% are actually used; the remainder are "old" versions of pages, but not named consistently and some referenced from live pages so I can't just go through and delete irrelevant stuff.

I'm advising the client that a total rewrite is very urgently needed, but in the meantime there are functional changes required and this stuff has to be edited!
GeneralRe: personal worst... PinPopular
raddevus19-Nov-18 7:56
mvaraddevus19-Nov-18 7:56 
GeneralRe: personal worst... Pin
RickZeeland19-Nov-18 8:02
mveRickZeeland19-Nov-18 8:02 
GeneralRe: personal worst... Pin
charlieg19-Nov-18 17:06
charlieg19-Nov-18 17:06 
GeneralRe: personal worst... Pin
Daniel Pfeffer19-Nov-18 19:57
professionalDaniel Pfeffer19-Nov-18 19:57 
GeneralRe: personal worst... Pin
RickZeeland19-Nov-18 23:55
mveRickZeeland19-Nov-18 23:55 
GeneralRe: personal worst... Pin
Richard Deeming20-Nov-18 1:34
mveRichard Deeming20-Nov-18 1:34 
GeneralRe: personal worst... Pin
Chris Maunder19-Nov-18 8:08
cofounderChris Maunder19-Nov-18 8:08 
GeneralRe: personal worst... Pin
GenJerDan19-Nov-18 20:34
GenJerDan19-Nov-18 20:34 
GeneralRe: personal worst... Pin
Herman<T>.Instance21-Nov-18 22:23
Herman<T>.Instance21-Nov-18 22:23 
GeneralRe: personal worst... Pin
DerekT-P21-Nov-18 23:09
professionalDerekT-P21-Nov-18 23:09 
GeneralRe: personal worst... Pin
Nelek22-Nov-18 9:48
protectorNelek22-Nov-18 9:48 
GeneralRe: personal worst... Pin
TheGreatAndPowerfulOz14-Jan-19 2:57
TheGreatAndPowerfulOz14-Jan-19 2:57 
GeneralRe: personal worst... Pin
David A. Gray28-Apr-19 15:49
David A. Gray28-Apr-19 15:49 
GeneralMS, you funny! Pin
David O'Neil10-Nov-18 13:18
professionalDavid O'Neil10-Nov-18 13:18 
GeneralRe: MS, you funny! Pin
Marc Clifton10-Nov-18 13:50
mvaMarc Clifton10-Nov-18 13:50 
GeneralRe: MS, you funny! Pin
David O'Neil10-Nov-18 14:37
professionalDavid O'Neil10-Nov-18 14:37 
GeneralRe: MS, you funny! Pin
Jon McKee10-Nov-18 16:02
professionalJon McKee10-Nov-18 16:02 

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.