Click here to Skip to main content
15,887,350 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
Vozzie25-Jul-09 3:16
Vozzie25-Jul-09 3:16 
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 
GeneralRe: A small Horror Pin
killabyte5-Jul-09 19:07
killabyte5-Jul-09 19:07 
GeneralRe: A small Horror Pin
molesworth1-Jul-09 22:04
molesworth1-Jul-09 22:04 
GeneralRe: A small Horror Pin
Nathan Tuggy2-Jul-09 6:08
Nathan Tuggy2-Jul-09 6:08 
GeneralRe: A small Horror Pin
Pete O'Hanlon2-Jul-09 2:28
mvePete O'Hanlon2-Jul-09 2:28 
GeneralRe: A small Horror Pin
PIEBALDconsult2-Jul-09 5:28
mvePIEBALDconsult2-Jul-09 5:28 
GeneralRefresh a list view... when ever new file comes into folder Pin
Nikkiee25-Jun-09 12:06
Nikkiee25-Jun-09 12:06 
GeneralRe: Refresh a list view... when ever new file comes into folder Pin
Fatbuddha 125-Jun-09 21:56
Fatbuddha 125-Jun-09 21:56 
GeneralRe: Refresh a list view... when ever new file comes into folder Pin
OriginalGriff25-Jun-09 22:04
mveOriginalGriff25-Jun-09 22:04 
GeneralRe: Refresh a list view... when ever new file comes into folder Pin
Fatbuddha 125-Jun-09 23:42
Fatbuddha 125-Jun-09 23:42 
GeneralNot quite sure what "is equal to" actually means... Pin
OriginalGriff25-Jun-09 1:24
mveOriginalGriff25-Jun-09 1:24 
JokeNot quite sure what "==" | "&&" means surely? Pin
Keith Barrow25-Jun-09 3:05
professionalKeith Barrow25-Jun-09 3:05 
GeneralRe: Not quite sure what "is equal to" actually means... Pin
Chris Meech25-Jun-09 3:06
Chris Meech25-Jun-09 3:06 
GeneralMessage Removed Pin
25-Jun-09 3:09
MadProgrammer7625-Jun-09 3: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.