DEV Community

Diner Das
Diner Das

Posted on

What's the worst code you've ever written?

Smash that "subscribe" button if you don't want to miss anything. πŸ‘‡

Latest comments (29)

Collapse
 
aptivi profile image
Aptivi

In the very early days of my program on GitHub (I was still a beginner to Visual Basic at the time), there are countless horrible code blocks that still embarrasses me to this day. The most remarkable one is this (from Kernel Simulator v0.0.2):

    Sub ShowTimeQuiet()

        If (Quiet = True) Then
            'Do nothing
        Else
            ShowTime()
        End If

    End Sub
Enter fullscreen mode Exit fullscreen mode

When it should have been this:

    Sub ShowTimeQuiet()

        If Not Quiet Then
            ShowTime()
        End If

    End Sub
Enter fullscreen mode Exit fullscreen mode

That "wrapper" function has been removed ever since. I'm embarrassed as to how I did manage to write such code in an abrasive manner.

Other interesting bits:

The variables were used to list users and passwords:

Login.vb:

    'TODO: Re-write login system, removing unnecessary variables
    'Variables
    Public usernamelist As New List(Of String)                  'Temporary
    Public passwordlist As New List(Of String)                  'Temporary
    Public userword As New Dictionary(Of String, String)()      'List of usernames and passwords
Enter fullscreen mode Exit fullscreen mode

Kernel.vb:

        My.Settings.Usernames = New System.Collections.Specialized.StringCollection     'Temporary
        My.Settings.Passwords = New System.Collections.Specialized.StringCollection     'Temporary
Enter fullscreen mode Exit fullscreen mode

Three completely identical variables related to usernames and passwords in different places to INITIALIZE a SINGLE user! Try to figure out their roles in Login.vb.

Since then, the source code got much better throughout the four years to the point that it even complies with OOP!

Collapse
 
mephi profile image
mephi

I don't remember why I exactly did this and it was years ago, but I had a bunch of similar named variables and/or methods and was to lazy to even copy and paste the code and do some alternations so I used some loops, concat and exec to generate and execute everything. Even though this was before I started to actually study computer science, I had the clear feeling this was wrong, but all that typing seemed unbearable.

I would really like to get that code and to look at this again as I can't imagine by know that this could have been without a less questionable solution and I would like to fix it.

Collapse
 
tandrieu profile image
Thibaut Andrieu

I once implement a sorting algorithm with a complexity of O(n^3)...

It was friday evening. On next monday morning, I just removed all the code and call std::sort() instead.

Collapse
 
jrothlander profile image
jrothlander

Probably the funniest and scarest thing I ever did was write a 1 line C app in my freshmen C class. We were learning how to submit keyboard events. So I thought it would be funny to write an app that captured ctrl-alt-delete and call it from autoexe and see how long it would take someone to figure it out... and hit ctrl-c to stop it. Well, they freaked out and thought it was a virus and the prof formatted every computer in the lab and reinstalled everything from scratch. Then the univerisity put up notices in every computer lab and they created some new article in the student handbook about putting viruses on univerisity computers. Needless to say... I never mentioned it again.

Collapse
 
neoprint3d profile image
Drew Ronsman

Me too

Collapse
 
onlyphantom profile image
Samuel Chan

Heh great catch! that’s probably why it didn’t make it into production.

There should have been 1/17 chance!

Collapse
 
onlyphantom profile image
Samuel Chan

Boss: Try to track page views on our website, but also try to avoid making a database trip on every single page load.

Me: Say no more.

from random import randint
if randint(0,16) == 16:
  model.view_count += 16
  model.save()
Enter fullscreen mode Exit fullscreen mode
Collapse
 
kevincp17 profile image
kevincp17

I was a college student in my first year and I used phyton in basic programming class. It was an exam day and one of the task given was to make a triangle with "*". I didn't even know how to use a loop concept, so I used print() and spacebar a few times to make a triangle. I could say that the task was succesfully failed.

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡

When all you have is a hammer, everything is a nail innit

Collapse
 
lexlohr profile image
Alex Lohr

I once wrote a primitive ES3 lexical parser in PHP meant to filter out comments and bundle JS files (a few years before node.js was released).

It resulted in errors because it had concatenated jQuery, which used an IEFE, with another IEFE without a semicolon in between, an edge case that I had overseen during development. It took me almost 1Β½ days to find and fix that error.

Collapse
 
onlyphantom profile image
Samuel Chan

Didn’t know React but was called in to do some last minute changes which needs to be committed under a deadline.

Using location.reload() to refresh the browser after a react state change that wasn’t rendering the intended component.

Got so sick in the stomach writing it. Had to purge it from git history so it never exist. Spend the weekend learning React proper.

It felt dirty. I never fully recovered.

Collapse
 
joelbonetr profile image
JoelBonetR πŸ₯‡

C'mon that's not that bad πŸ˜‚πŸ˜‚πŸ˜‚