What does the crappiest code you’ve ever seen look like? (Come for a long experience)

Hello everyone, I’m Xiaobian.

19 rubbish code snippets that people actually write

One of them may have been written by you.

It happens to all of us at some point. You produce code that you are not proud of. This code makes you wonder, *”How could I write something like this?”* It’s nothing to be ashamed of. We are only human. Sometimes we just don’t do our best.

It happened to me, it happened to you, but it also happened to other developers. I took some time and collected the worst code snippets I could find. Today, I will introduce them to you.

However, I only do this under one condition. You have to assure me that you will not treat them badly. Remember, at some point, you may have written something like that. That being the case, let’s put on our open-minded glasses and play. The first one is here!

Rebuilding the wheel went wrong

Regular boolean comparisons don’t return what you’re looking for. What should you do? The answer is simple, you create one yourself.

original data

magic number

Looking at this picture, I can’t help but ask. What happens if we change one of the numbers? Probably nothing good.

Notice

At the end of the article: 7701 pages of interview questions for Internet companies

original data

At least it’s split into several lines

From the sheer look of this code, I’m guessing it’s a school project. Needless to say, my condolences to this teacher.

original data

The devil is also a function

Today, we will see various implementations of the isEven function. This is our first candidate. What I’m trying to say is that we’re off to a good start. what do you think?

original data

Wish there was a function to get the size of a string

This idea crossed the minds of our fellow developers. He didn’t hesitate for a second. and implemented it immediately.

original data

Awaken the inner child

As crazy as it sounds, you can use emoji as variable names. But should you use them this way? See the code below and decide for yourself.

original data

Who the hell is reading commit t info

If you have a colleague who uses the same commit message over and over again. She may have done so.

original data

If any of these changes

The future is unpredictable. It can change overnight. To prevent this from happening, it’s best to be extra careful.

original data

Reasons to buy an ultrawide monitor

There’s nothing wrong with lengthy variable names. As long as they help improve the readability of the code. But sometimes, we have to ask ourselves “How long is long?”

original data

act of genius

Nothing to add here. I think this note is self-explanatory.

original data

Typography is the best

Type safety feels good. So how can you better ensure that you don’t get any type errors? These guys, they figured this out.

original data

If it works, it works

What is really to be said. Just make sure that the sum of the parameters is always 7. And this function doesn’t fail.

original data

Make sure it’s a real Bool

How much pessimism is too pessimistic? I would say this guy is really close.

original data

The best way to test-driven development

We have to applaud the use of unit tests. But I can’t help but ask. What happens if the test is to generate random numbers?

original data

Do you dare to expand?

We’ve all written complex switch statements at some point. However, a thousand lines seems a bit too much. But after all, there are a lot of mouse states that need to be covered.

original data

Try the Switch statement

Do you think the future plan is to expand this Switch? Nothing more, just have to believe it.

original data

math is difficult

Sometimes, there is no shame in using outside help. What actually exists is – even packages. Can you guess how many downloads it gets per week? It surpassed 150,000 times.

original data

When brilliant ideas flow

Sometimes, you just feel like a rebel. You have to do things your own way. But I think we can agree that this type of code shouldn’t go into code review.

original data

When you’re a coder but your passion is calligraphy

I tried different types of fonts. But I have to say, it never got this far. If this makes you wonder “is pirated software written this way?” you’re not alone.

original data

Final Thoughts

I hope you are in a good mood when looking at these examples. Of course so do I. Feel free to let me know which one is your favorite. Or if you have some shameful photo to share, don’t be afraid to share it in the comments.

I’m having fun browsing through these code snippets. It reminds me of my early days. During my career, I’ve written snippets of code that I’m not proud of. But luckily, no one took screenshots of them. Or at least I hope so.

The text and pictures in this article are from the architect’s column

loading.gif

This article is reprinted from https://www.techug.com/post/what-s-the-most-garbage-code-you-ve-ever-seen-to-learn-more/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment

Your email address will not be published.