What's the worst coding practices you have seen(or done!)?

No Offence, each one of us must have either seen or (mostly) done/followed some Coding Practices that we are not so proud of ๐Ÿ˜†.

Let's be honest here and post what are those. It would be great to see those with some examples, if possible!

To start with me, so far most horrible coding practice I had in two places:

  • Loops : I have written for loops that are nested to 4 levels with iterate variable named as, i, j, k, l etc.. When I look back, damm ๐Ÿ˜ฌ!
  • Logical Conditions: &&, ||, ! with if-else. I have really done blunders in past where I wrote some if-else along with && and || that finally sounded very illogical and had to re-factor.

As Programmers, everyday is a new day with a new learning. I have learned too from my horrible programming practice mistakes. Still learning!

Let us know yours. ๐Ÿ˜„

Sandeep Panda's photo

Good question and several useful answers so far! Here are some of the bad practices I have encountered:

  • Mixing early return with if-else
if (x) {
  return 1;
else {
  // Do something else
  • Inconsistent naming e.g. variable name looks like a boolean, but you store something else
var isPublication = "publicationId";
  • Making code harder to read and complicating it unnecessarily
return (x === 1 ? true : false);
  • Lover of callbacks e.g. nesting too many callbacks when you can easily avoid them using something like async/await
dosomething(10, 12, (data) => {
  doSomethingElse(data, (something) => {
    doAnotherThing(something, () => {
      // More callbacks
  • Making typos and copying the typos everywhere because you couldn't notice. Sometimes you misspell a variable name and copy-paste it to different places -- it works -- However, when other collaborators glance over the variable name and try to use it in some section, the code simply doesn't work. It wastes a lot of time because we are not able to figure out that the original variable name is incorrect.

  • Failing to return early by mistake. Some developers accidentally skip return keyword while returning early in case of error.

if (err) {
  res.status(400).end(); // This doesn't halt the execution of code

// rest of the code

There are many more, but these are the ones I've come across most frequently. I have always highlighted them in the code reviews so far. :D

Show +2 replies
Paul's photo

Web Developer

If you're retrieving from a database, you might leave the connection open.

Levi A Kirkland's photo

Any time I see code similar to below. The code author wraps a try/catch around a bit of code that should be written to ensure no failure, and the doesn't even write anything in the catch to overcome the issue. I feel this is the equivalent to On Error Resume Next . try { int i = (convert a string) } catch (Exception ex){}

//keep going....

Emil Moe's photo

My teacher! Not only was it in Danish, it was also ridiculous. Here is the (english) translated version:

 * Determine kids gender.
public isBoy() {
  if (this.isBoy) {
    return true;
  else {
    return false;

I also had another teacher who started out, when he for the first time showed us his code, by saying "this is a little messed and now how you should do it" โ€“ he had put all 5-10 classes of the application in the same single file.

Ehsan Fazeli's photo

I wrote a module couple of months ago that was the literal meaning of overhead.

We have a support center and it's running by a handful of trusted, experienced supporters that work with our platform and resolve the issues created by customers. The task was pretty straightforward, disable the skip button for one hour when an operator skips more than three issues.

What I did was to create an entity to store logs of when an operator has exceeded their skip threshold, cache the prohibition timestamp, create a job on queue and set its delay to one hour, create a worker to listen to the queue, create an endpoint to respond to the client current timestamp of the server, a boolean containing that he/she is prohibited or not, the future timestamp that their penalty would be dismissed and an interval that evaluates every single second to increment the time retrieved from server and compare it to the threshold to inform the user whenever they can skip the issues again.

All of which could be done with a simple local storage variable containing these simple info to handle it completely on client-side. I'm wondering why the hell I chose the first approach. Maybe I was bored at work at the moment. :D

Caleb H.'s photo

Mine was a security issue.

When I first got into backend programming, one of the first things I did was build my own authentication system (sign up, sign in, etc.)

And...I stored those passwords in plaintext. Yep.

But I learned from it later on, and now all my apps use hashes with salt to store the passwords.

It turns out Facebook had the same problem when it was first created...

...and they had one password that could be used by Facebook employees to sign in to any account. Yikes.

Quick tip: If you ever go to a website's "forgot password" page, and they email you your password, that website has terrible security.

Show +1 replies
Emil Moe's photo

Software Engineer & Consultant

If we talk about stupid things we did in the past, then first time I ever installed Linux I executed sudo rm -r / it was just on desktop, but it wasted me a lot of time.

Caleb H.'s photo

Co-founder of High/Low

๐Ÿ˜ฌ I feel your pain. Although at least it wasn't -rf?

Mohd Shad Mirza's photo

I'm a React Native Developer so my answer will be in that context.

  1. Global Variables: I used to define at the very start of my career.
  2. Arrow functions inside render method: For the first 4 months, I think. Then I had to implement a FlatList and optimizing it taught me a lot about rerendering.
  3. Inline CSS: It's a good practice to define a StyleSheet outside the render method because it keeps taking memory on every rerender.
  4. I used to write code with proper indentation and format then I enabled format code each save setting in VS Code and it's so much productive now.
  5. Using for loops: Can't say it's a bad practice but using Array Higher-Order Functions like map and reduce is so much efficient and code is more readable too.
  6. Using recursive functions everywhere: When I first learned Recursive, I started using it everywhere which is bad. If the stack is going to be large then it will take a huge amount of memory and you might run into stack overflow. It's important to know when to iterate and when to use recursion. Yup, that's pretty much it.
Tapas Adhikary's photo

โ˜ UI/UX Enthusiast | ๐Ÿ’ป Work @MicroFocus | โœ๏ธ Blogger | ๐Ÿ‘จโ€๐Ÿซ Mentor | ๐ŸŽค Speaker | ๐ŸŸ Foodie

With given use cases, moving to map, reduce, filter etc from for-loops are so much fun to write and relaxing to read! Fully agree with you..

John Eric's photo

A function that loops all of the array of objects, then inside of it has also a check if the current iteration of that loop is an array or object, if it's an array it will recursively run itself again, and returns nothing. Imagine you have hundred thousands of data / object that is being passed from that function and it returns nothing, no mutation at all.

Tapas Adhikary's photo

โ˜ UI/UX Enthusiast | ๐Ÿ’ป Work @MicroFocus | โœ๏ธ Blogger | ๐Ÿ‘จโ€๐Ÿซ Mentor | ๐ŸŽค Speaker | ๐ŸŸ Foodie


Yashu Mittal's photo

I want to pinpoint one project, where I would say that I have never seen the worst coding practices anywhere else.

  1. Using scoped styles in every component
  2. Using a JS framework along with defining custom components (like: buttons and labels)
  3. Not using ESLint or any other linting tool
  4. Spacing and tabs mixed together
  5. Not removing old/unused code
Tapas Adhikary's photo

โ˜ UI/UX Enthusiast | ๐Ÿ’ป Work @MicroFocus | โœ๏ธ Blogger | ๐Ÿ‘จโ€๐Ÿซ Mentor | ๐ŸŽค Speaker | ๐ŸŸ Foodie

Not using linter is bad...However using the linter and disabling the rules in code lines is kinda crime!

Hipkiss's photo

More of a deployment/version control thing but I've seen people version control the code and then just copy the files to test + staging servers LOL. I've done a couple of bad things in the past but nothing quite like that.

That's probably the worst I've come across.

Maneesh Kumar's photo

I also experienced some bad coding standard ..

a. Very convenient way to declare global variable into program -- Memory leak issue . b. Use ForEach loop like a bread & Jam -- Performance issue c. Always ready to implement everything in UI layer rather then think twice and move to right place . d. Use proper design for implementation , It can avoid lot of bad practice .

Still Counting :)

Lazar's photo

Boy... I don't know where to begin. I've broken just about every rule in the book. My main problem i think is I find I use if statements without the else a lot. Like I will do this:

foo = 300

if foo == 200:
    print("foo is equal to 200")
if foo is != 200:
    print("foo is not 200")

I could of easily used an else there, it also looks extremely messy.

I name my variables ridiculous names.

I just give them names off the top of my head.... I'm trying to break that habit but I will literally use "foo" as a variable name if I can't think of anything.

If I listed everything else, I would go on all day. ;D

Tapas Adhikary's photo

โ˜ UI/UX Enthusiast | ๐Ÿ’ป Work @MicroFocus | โœ๏ธ Blogger | ๐Ÿ‘จโ€๐Ÿซ Mentor | ๐ŸŽค Speaker | ๐ŸŸ Foodie

Often I find myself naming variables too long...Then when try to short them, the meaning will be lost and back to square one!

j's photo

Hmmm it was with PHP 4. This is just an example how it looks it has been quite a while

function myMethod() {
  $var1 = 12;

  $var3 = $var2->doSomething();

and the fun part was the reference was sometimes passed through 4 - 5 layers.

This was quite a confusing way to do things.

It's not that I am innocent of doing horrible things with code but this example actually kinda scared me ;D ....