The worst coding practice you have ever seen

Coding horror stories

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

50 Replies - 14992 Views - Last Post: 11 July 2011 - 02:50 PM

#1 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

The worst coding practice you have ever seen

Posted 04 April 2010 - 08:40 AM

I had a sudden thought today; what is / are the worst coding practice's, or experiences, you have ever seen /experienced :P . I don't mean stuff like not commenting code, or adding regions. I mean the real horror stories, like when Noob's, to use the term loosely, make a password application to protect a folder, and write the password in plain text straight into it. Or when other people put way to many files (in size) into their resources and then complain when their application doesn't work to well.

I'm looking for the Ok, Bad, and Ugly :) , as I think a thread on all the things that people do wrong should warn others against doing it. If there is also a sensible solution to the problem, then also post that as it may help people.

For example a solution to the two above problems is to: hash your passwords and store then in a random file name, or maybe an algorithm based on the name of the folder its in; and to have all files external or in one big external file.

Lets see how many people we can make hide under the desk :devil2:

Is This A Good Question/Topic? 0
  • +

Replies To: The worst coding practice you have ever seen

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4999
  • View blog
  • Posts: 13,490
  • Joined: 18-April 07

Re: The worst coding practice you have ever seen

Posted 04 April 2010 - 09:21 AM

I have seen two from the same guy recently...

1) He sets a variable to the value 3 and then on the next line checks if it is null.
2) Checks a variable is an empty string or that the value equals "USA" and if one of the two is correct, he sets that variable to "USA". I mean check if it is empty fine, but why check if it is USA if you are just going to set it to USA?

Sad thing is that he is working on some of my well tested production code and making horrible logic mistakes that is really just ruining it and nothing I can do about it.
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1161
  • View blog
  • Posts: 4,444
  • Joined: 02-July 08

Re: The worst coding practice you have ever seen

Posted 04 April 2010 - 07:43 PM

I just love seeing the keyword END somewhere in code, yes alone - all by itself - not 'End Sub' or 'End If' - just END. Oh don't you worry the END is coming...
Was This Post Helpful? 0
  • +
  • -

#4 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: The worst coding practice you have ever seen

Posted 05 April 2010 - 03:11 AM

If i = 0 Then
i = 0
End If



and of course.

http://thedailywtf.com/

This post has been edited by T3hC13h: 05 April 2010 - 03:11 AM

Was This Post Helpful? 0
  • +
  • -

#5 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: The worst coding practice you have ever seen

Posted 06 April 2010 - 10:11 AM

wow those are bad, here is another one; A recursive loop to edit a file, at an amazing rate of 10 file operations per second. Of course also seizing ram and CPU space...
Was This Post Helpful? 0
  • +
  • -

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,279
  • Joined: 25-March 09

Re: The worst coding practice you have ever seen

Posted 07 April 2010 - 01:17 AM

not putting comments in my code so i have to wonder what was i thinking when writing this. and the use of variables for every operation. if they are global it is even worse. example:
Public Class Form1
    Public x As Integer
    Public y As Integer
    Public s1 As String
    Public s2 As String
....
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        x = TextBox1.Text
        y = TextBox2.Text
        s1 = TextBox3.Text
        s2 = TextBox4.Text
...
    End Sub
End Class



and the names to be clueless as possible so no one ever know what they do ...

This post has been edited by NoBrain: 07 April 2010 - 01:18 AM

Was This Post Helpful? 0
  • +
  • -

#7 danny_kay1710  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 29
  • View blog
  • Posts: 359
  • Joined: 27-April 08

Re: The worst coding practice you have ever seen

Posted 07 April 2010 - 01:48 AM

One of the worst coding practices I have seen is from someone who went to the same college as me and now works as a "programmer". He wanted to show off so he showed me some code...

He declares EVERY variable globally. In fact if I didn't know better I would say he thought they all had to be global.

But the even worse thing is, he wouldn't re-use a variable in more than one sub e.g. he would use i for a for loop in one of his methods and never re-use it but start using other letters.

He had about 12 variables which were just letters for loops and a huge long list of variables most of which got used only once or twice all from the same method.
Was This Post Helpful? 0
  • +
  • -

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,279
  • Joined: 25-March 09

Re: The worst coding practice you have ever seen

Posted 07 April 2010 - 02:57 AM

exactly the only thing your missing is the names of the variables. they have to be with the most non related to what they do as they can. like Public Jhon As Integer is used for counter. :)
Was This Post Helpful? 0
  • +
  • -

#9 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1726
  • View blog
  • Posts: 5,704
  • Joined: 25-September 09

Re: The worst coding practice you have ever seen

Posted 08 April 2010 - 01:35 PM

Well, here's one I came across the other day
dim i as integer = 1
For x = 1 to 10
Listbox1.Items.Add("Item #" & i)
i = i + 1
Next


Another one is

Dim UserName as string
UserName = txtUser.Text
If txtUser.Text = UserName then
    txtUser.Text = UserName
    If UserName = "Admin" then
     'lot's of code to make various controls visible\hidden
    end if
    If UserName = "Foreman" then
     'lot's of code to make various controls visible\hidden
    end if
    If UserName = txtUser.Text then
     'yep, you guessed it, more controls made visible\hidden
    End If
End If


With the question, "Why no matter what user I enter I get the same controls showing"

This post has been edited by CharlieMay: 08 April 2010 - 01:35 PM

Was This Post Helpful? 0
  • +
  • -

#10 ZRonZ  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 206
  • Joined: 09-January 09

Re: The worst coding practice you have ever seen

Posted 08 April 2010 - 06:58 PM

I'm pretty new at VB and I still write some ugly stuff but I even find some humor out there.

I am totally amazed at the guy that must have flunked first grade math but still tries to code complex calculations like a running total (rngttl = lastnumber) or an average (running total divided by last value).

How about that one guy that figured out how to calculate an average while using only one variable and then he declared "coding is my new passion". Boy am I jealous of him. He's going to be rich and famous.

On the other hand, maybe I should just shut-up and count my blessings that there are those people out there to make me look better than I am.

It's not what you know, it's what you know minus what they know that matters.

you.looksgood.value = (know.you.quantity - know.them.quantity).toegopoints()

I keep getting a sintext error on that one. Can anyone out there help me? Please? Bump!

This post has been edited by ZRonZ: 08 April 2010 - 07:01 PM

Was This Post Helpful? 0
  • +
  • -

#11 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: The worst coding practice you have ever seen

Posted 09 April 2010 - 07:36 AM

I have another wonderfully hideous excuse for code. This person was using the Process.GetProcess method to check if their application was still running. It was a single instance application...

This post has been edited by Asscotte: 09 April 2010 - 07:37 AM

Was This Post Helpful? 0
  • +
  • -

#12 ZRonZ  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 206
  • Joined: 09-January 09

Re: The worst coding practice you have ever seen

Posted 09 April 2010 - 09:43 AM

How did you know I did that?

View Posthawkvalley1, on 04 April 2010 - 06:43 PM, said:

I just love seeing the keyword END somewhere in code, yes alone - all by itself - not 'End Sub' or 'End If' - just END. Oh don't you worry the END is coming...


I was in the middle of some code and had to put it aside to take care of an "emergency". The next day when I got back to the code (after just reading your post) the first thing I saw was a Sub with nothing in it except "End".

It gave me a good, timely laugh. Thanks
Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: The worst coding practice you have ever seen

Posted 09 April 2010 - 09:58 AM

The class empty true.
If some_condition = True Then
' Empty '
Else
' Code '
EndIf


Instead of
If Not some_condition Then
' Code '
EndIf

Was This Post Helpful? 0
  • +
  • -

#14 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 469
  • View blog
  • Posts: 4,279
  • Joined: 25-March 09

Re: The worst coding practice you have ever seen

Posted 16 April 2010 - 09:59 AM

using this
MyString1 + " And " + MyString2



not

MyString1 & " And " & MyString2



ffs it is no C

This post has been edited by NoBrain: 16 April 2010 - 10:00 AM

Was This Post Helpful? 0
  • +
  • -

#15 weirddemon  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 190
  • Joined: 05-January 09

Re: The worst coding practice you have ever seen

Posted 17 April 2010 - 06:51 PM

Though not as bad as the examples as some have posted, but I hate when a variable has been declared and then it's value set on another line -_-

ie:

Dim i As Integer
i = 1

Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »