The worst code collection ever

The worst code collection ever

[[141823]]

In fact, there is no such thing as the "worst code in history". If there is, it is only "worse than ever". I want to talk about this topic casually, which also originated from a discussion on Douban. In fact, it is common to be criticized for bad code when the system is complex. Of course, there are also some short code snippets that are enough to show that the author of the code is not a good person.

The use of Boolean types can easily become the worst code:

  1. if (isTrue())
  2. if (isTrue())
  3. doSomething();
  4.  
  5. if (boolVal == true ) {
  6. .....
  7. }

There are some meaningless comments:

  1. return   1 ; // Return 1  
  2.  
  3. //If the flag is true, return true  
  4. if (flag)
  5. return   true ;

Even more meaningless is variable naming like this:

  1. public   static   final   int ONE = 1 ;
  2. public   static   final   int TWO = 2 ;

Some people also say that the worst code snippet should be like this:

  1. }
  2. }
  3. }
  4. }
  5. }
  6. }
  7. }
  8. }
  9. }

There is also 12306.cn, which was once criticized to the point of pus flowing all over its body. The code excerpt is:

  1. var sig = 0 ;
  2. if (searchwordl.indexOf( "'" ) > - 1 || searchwordl.indexOf( "\"" ) > - 1 || searchwordl.indexOf( "%" ) > - 1 || searchwordl.indexOf( "#" ) > - 1 || searchwordl.indexOf( "&" ) > - 1 || searchwordl.indexOf( "*" ) > - 1 || searchwordl.indexOf( "(" ) > - 1 || searchwordl.indexOf( ")" ) > - 1 || searchwordl.indexOf( "@" ) > - 1 || searchwordl.indexOf( "`" ) > - 1 || searchwordl.indexOf( "/" ) > - 1 || searchwordl.indexOf( "\\") > -1 || searchwordl.indexOf(" , ") > -1 || searchwordl.indexOf(" . ") > -1 || searchwordl.indexOf(" = ") > -1 || searchwordl.indexOf(" < ") > -1 || searchwordl.indexOf(" >") > - 1 )
  3. sig = 1 ;
  4.  
  5. searchwordl=searchwordl.replace( "'" , "" );
  6. //searchwordl=searchwordl.replace(" ","");  
  7. searchwordl=searchwordl.replace( "%" , "" );
  8. searchwordl=searchwordl.replace( "#" , "" );
  9. searchwordl=searchwordl.replace( "&" , "" );
  10. searchwordl=searchwordl.replace( "*" , "" );
  11. searchwordl=searchwordl.replace( "(" , "" );
  12. searchwordl=searchwordl.replace( ")" , "" );
  13. searchwordl=searchwordl.replace( "@" , "" );
  14. searchwordl=searchwordl.replace( "`" , "" );
  15. searchwordl=searchwordl.replace( "/" , "" );
  16. searchwordl=searchwordl.replace( "\\"," ");
  17. searchwordl=searchwordl.replace( "," , "" );
  18. searchwordl=searchwordl.replace( "." , "" );
  19. searchwordl=searchwordl.replace( "=" , "" );
  20. searchwordl=searchwordl.replace( "<" , "" );
  21. searchwordl=searchwordl.replace( ">" , "" );
  22. if (searchwordl == 'Please enter the search criteria' ){
  23. alert( "Please enter search criteria" );
  24. return   false ;
  25. }
  26. if (searchwordl == '' ){
  27. alert( "Please enter the search terms correctly" );
  28. return   false ;
  29. }
  30. if (sig == 1 ){
  31. alert( "Please enter the search terms correctly" );
  32. return   false ;
  33. }
  34. document.getElementById( 'searchword' ).value=searchwordl;

There are also bad JavaScript codes, which are too many to post. The more flexible the language, the more difficult it is to control, and the more likely you will see super bad code.

Tiago Fernandez did a poll to elect the worst Java API:

  1. The formula is: score = (I can live with) + (Painful * 2) + (Crappy * 3) + (Hellish * 4)
  2.  
  3. The result, did you guess it?

Java has many frameworks and strict syntax, which is helpful in limiting programmers who want to cause damage. But if they really want to cause damage, it is impossible to limit them. I once worked on a portlet extension class with several thousand lines in total. At that time, I thought the code was bad enough. But later, I saw a stored procedure with more than 5,000 lines and a jsp page with more than 7,000 lines. I used to think that Java programmers were much less destructive than C/C++ programmers. It seems that this is not entirely true.

The most common types of bad code I have encountered include the following:

Some naming habits, such as the abbreviation "cptct" for method names that are almost cipher-like, are probably due to the poison of Basic. Even early versions of Visual Basic enforced some constraints on the code (such as the length of variable names, the number of variables allowed in a module, and the size of the module).
Web projects in the early years (even some of the web projects done by small companies now) did not understand decoupling and layering, and all the logic was mixed together, like a pile of shit. Page templates directly accessed the database, style codes were scattered all over the world, and HTML was hard-coded in various logics.
In the eyes of some programmers, "reuse" == "inheritance". As long as there are reusable properties and public methods, they will try to use the invincible thunderbolt inheritance method to solve it, regardless of whether it is suitable or not, level by level, in the end it must be a majestic and boundless inheritance tree.
Endless tool classes. This type of code is not much better than the inheritance code. Static classes like XXHelper and XXTools are everywhere, but the reuse vision is more than just inheritance...
I have seen several programmers like this who have almost no idea about the definitions and methods of numerical object types such as Integer, Long, and Double, but are very familiar with String. They convert and verify data into String and then convert it back after completion.
God class. The essence is a misunderstanding of the single responsibility of a class. It's fine for Java and C++ programmers to write God classes, but this year I heard from a friend that a Ruby programmer with considerable work experience wrote a huge God class...
Design patterns are everywhere. The essence is over-design. A good "new Template()" must introduce a factory, and then a strategy pattern and template pattern. It's not enough, so finally add annotations to achieve it...
Most of the JavaScript and CSS. Not explained.

Today, a colleague said that the reason why code becomes bad code is that the person who wrote the code will encounter many more problems than the person who reads the code later. Although the person who wrote the code solved most of the problems, the remaining problems are enough to make the code infamous. But I don't think so. I have seen VB code and Delphi code from a relatively old year. Although they are all used for interface development and many of the concepts are far less than today, the code is still clear and easy to understand.

Some programmers say that the deadline is tight, the project is heavy, and the leader is pushing me to the point of vomiting blood every day, so I have no choice but to write bad code. There are thousands of objective reasons, and I really have nothing to say. After all, when material civilization is still very weak, it is better not to talk about spiritual civilization. However, excellent programmers have pursuits, but people are numb and always talk about project pressure. Giving a loose deadline may not make a difference.

Some programmers also said that dialectical materialism tells us that everything has two sides, so we should learn the good design from bad code and take the bad design as a warning... I said, come on. Bad is bad, even shit in an ice cream cone is still shit, so why be so pretentious?

Many programmers always have the urge to start over, especially when they see bad code. I used to do that too. In fact, this is dangerous. Moreover, in many cases, your rewrite may not be better than the original bad code. Maybe you can solve 30 problems, but introduce 50 new problems. Refactoring should start with small changes and modules when the business model and process are clear. It is always dangerous to make big changes.

I don't admire programmers who always say they suffered so much fifteen years ago. I admire excellent programmers who can still write code that makes people feel comfortable now under the conditions and concepts fifteen years ago. Not writing bad code is to cherish life, save resources, and protect the earth. Writing good code is the quality of a programmer. There are no so many reasons to explain.

<<:  Things about the bad code you wrote

>>:  Code practice of background positioning upload

Recommend

The world's most famous mother bear died on the road

Grizzly 399 passed away. She was the legendary gr...

Brand Marketing Project Index

China's marketing agencies have yet to reach ...

Mobileye drives innovation in the autonomous driving industry with open RSS

When people talk about autonomous driving, they u...

The Nine Swords of User Growth Strategy

Product " user growth " is the most tro...

There are so many types of mobile phone fast charging, which one is the safest?

A few days ago, Meizu released the third-generatio...

The core of brand planning and promotion!

The names, logos, standard colors and standard ch...

How to restore TikTok to normal with 0 views? What are the main reasons?

Douyin is a very popular self-media video APP now...

Xiaomi Air Purifier 2 unboxing photos: 699 yuan, smaller in size

When you are all paying attention to the Redmi No...