Click here to Skip to main content
15,904,348 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: Swiss made Pin
ProtoBytes5-Jul-09 11:16
ProtoBytes5-Jul-09 11:16 
JokeMessage Closed Pin
5-Jul-09 10:10
Bernard Laplace5-Jul-09 10:10 
GeneralRe: Swiss made Pin
jan larsen7-Aug-09 2:47
jan larsen7-Aug-09 2:47 
GeneralRe: Swiss made Pin
charlieg30-Aug-23 14:43
charlieg30-Aug-23 14:43 
GeneralRe: Swiss made Pin
PIEBALDconsult2-Jul-09 5:09
mvePIEBALDconsult2-Jul-09 5:09 
GeneralTL,DR Pin
peterchen2-Jul-09 5:11
peterchen2-Jul-09 5:11 
JokeRe: Swiss made Pin
Thomas Weller2-Jul-09 5:15
Thomas Weller2-Jul-09 5:15 
GeneralRe: Swiss made Pin
ed welch2-Jul-09 14:53
ed welch2-Jul-09 14:53 
GeneralRe: Swiss made Pin
NormDroid2-Jul-09 21:26
professionalNormDroid2-Jul-09 21:26 
GeneralRe: Swiss made Pin
DoctorMick3-Jul-09 5:35
DoctorMick3-Jul-09 5:35 
GeneralRe: Swiss made Pin
nullpointer22-Jul-09 17:59
nullpointer22-Jul-09 17:59 
GeneralRe: Swiss made Pin
BillW3313-Aug-09 5:13
professionalBillW3313-Aug-09 5:13 
GeneralRe: Swiss made Pin
Vozzie25-Jul-09 3:16
Vozzie25-Jul-09 3:16 
GeneralMessage Closed Pin
3-Jul-09 4:47
Bernard Laplace3-Jul-09 4:47 
GeneralRe: Swiss made Pin
Dan Neely6-Jul-09 2:43
Dan Neely6-Jul-09 2:43 
GeneralRe: Swiss made Pin
sucram3-Jul-09 4:59
sucram3-Jul-09 4:59 
GeneralRe: Swiss made Pin
Jeroen De Dauw5-Jul-09 8:10
Jeroen De Dauw5-Jul-09 8:10 
GeneralRe: Swiss made Pin
0x3c05-Jul-09 8:27
0x3c05-Jul-09 8:27 
GeneralRe: Swiss made Pin
ProtoBytes5-Jul-09 11:11
ProtoBytes5-Jul-09 11:11 
JokeRe: A real Mess Pin
GKP199220-Jun-23 22:14
professionalGKP199220-Jun-23 22:14 
GeneralA small Horror Pin
Nathan Tuggy1-Jul-09 20:10
Nathan Tuggy1-Jul-09 20:10 
This is some sample code from an SDK, published by a medium-sized company who I will of course not name. (For one thing, my job is somewhat tied to their work... Hmmm | :| .)
It was so bad I rewrote it in place, and I couldn't resist a side-by-side comparison of my code and the original code.

(Side note: this code was apparently auto-translated by a tool from C# to VB.NET at some point during its life... it's possible that some of the horror is auto-generated, but how much of this could be from that source? And anyway, that's pretty bad in itself.)

''' <summary>
''' Parses the Input txt File by Rows and returns a array of string of input rows
''' </summary>
''' <param name="filelocation">System Path of the File </param>
''' <returns></returns>
Private Function ParseTheFileByLine(ByVal filelocation As String) As String()
  ' This is my code; the XMLdoc comments and method signature are unchanged,
  ' except that I fixed capitalization.
  Try
    Using sr As New StreamReader(filelocation)
      Dim ares As New List(Of String)
      Do Until sr.EndOfStream
        ares.Add(sr.ReadLine())
      Loop
      Return ares.ToArray()
    End Using
  Catch ex As IOException
    Dim hh As New System.Collections.ArrayList(1)
    hh.Add("Invalid Input File " & ex.Message)
    ' CompanyNameBrandedCustomValidationException is not, of course, the real
    ' name of the exception in question because, as the name implies, it
    ' contains the company's real name.
    ' And yes, its constructor does require an ArrayList. No, I don't quite
    ' know why. Chalk another one up to general incompetence or just garden-
    ' variety peculiarity.
    Throw New CompanyNameBrandedCustomValidationException(hh)
  End Try

  ' Here is the original miserable code, commented out (the way I left it
  ' there for possible "future use"...).
  '  Dim fs As FileStream = Nothing
  '  Dim fs1 As FileStream = Nothing
  '  Dim sr As StreamReader = Nothing
  '  Dim sr1 As StreamReader = Nothing
  '  Try
  '    fs = File.OpenRead(filelocation)
  '    fs1 = File.OpenRead(filelocation)
  '    sr = New StreamReader(fs)
  '    sr1 = New StreamReader(fs1)
  '  Catch Ex As Exception
  '    Dim hh As New System.Collections.ArrayList(1)
  '    hh.Add("Invalid Input File " & Ex.Message)
  '    Throw New CompanyNameBrandedCustomValidationException(hh)
  '  End Try
  '  Dim input_Array_Lines() As String = Nothing
  '  Dim input_line As String = ""
  '  Dim num_of_Lines As Integer = 0
  '  Try
  '    Do While sr1.Peek() > -1
  '      input_line = sr1.ReadLine()
  '      num_of_Lines += 1
  '    Loop

  '  Catch a As Exception
  '    Dim hh As New System.Collections.ArrayList()
  '    hh.Add("Invalid Input File " & a.Message)
  '    Throw New CompanyNameBrandedCustomValidationException(hh)
  '  End Try
  '  If num_of_Lines > 0 Then
  '    input_Array_Lines = New String(num_of_Lines - 1) {}
  '  End If
  '  num_of_Lines = 0
  '  Try
  '    Do While sr.Peek() > -1
  '      input_line = sr.ReadLine()
  '      input_Array_Lines(num_of_Lines) = input_line
  '      num_of_Lines += 1
  '    Loop
  '    Return input_Array_Lines

  '  Catch a As Exception
  '    Dim hh As New System.Collections.ArrayList()
  '    hh.Add("Invalid Input File " & a.Message)
  '    Throw New CompanyNameBrandedCustomValidationException(hh)
  '  End Try
End Function


I realize this code is not quite down to the ordinary standards of the Coding Horror, but still, it's pretty bad.
The worst? It's a helper function in a form file with over 10000 lines of code. Complete kludge all the way through. Tune in next time for more cleaned-up code samples....
GeneralRe: A small Horror Pin
killabyte1-Jul-09 21:27
killabyte1-Jul-09 21:27 
GeneralRe: A small Horror Pin
Jeroen De Dauw5-Jul-09 8:07
Jeroen De Dauw5-Jul-09 8:07 
GeneralRe: A small Horror Pin
killabyte5-Jul-09 11:35
killabyte5-Jul-09 11:35 
GeneralRe: A small Horror Pin
Jeroen De Dauw5-Jul-09 14:09
Jeroen De Dauw5-Jul-09 14:09 

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.