Let your co-workers can not write maintainable code

Yes, you read that right, this article is to teach you how to write so that colleagues can not maintainable code.

A program named

  1. Enter the name of the variable is easy: for example: Fred, asdf;
  2. Single-letter variable names: for example: a, b, c, x, y, z (if not used, can be considered a1, a2, a3, a4, ....);
  3. Spelling mistakes creatively: for example: SetPintleOpening, etPintalClosing. This can make it difficult to search code;
  4. Abstract: For example: ProcessData, DoIt, GetData ... just like nothing abstract to say the same;
  5. Abbreviations: For example: WTF, RTFSC ...... (pinyin also abbreviated to force, for example: BT, TMD, TJJTDS);
  6. Random capital letters: For example: gEtnuMbER;
  7. Naming reuse: the same variable name in the embedded wonders statement block;
  8. Accented letters use: For example: int ínt (second ínt not int);
  9. Use underscore: for example: _, __, ___;
  10. Different languages: for example mix English, German, or Chinese pinyin;
  11. Using character names: for example: slash, asterix, comma ...;
  12. With irrelevant words: For example: god, superman, iloveu ...;
  13. And confuse l 1: letter l and the number 1 is sometimes not apparent;

Second, camouflage fraud

  1. Note the code and the intertwined: for (j = 0; j <array_len; j + = 8)
  2. {
  3. total += array[j+0 ];
    复制代码
  4. total += array[j+1 ];
    复制代码
  5. total += array[j+2 ]; /* Main body of
    复制代码
  6. total += array[j+3]; * loop is unrolled
    复制代码
  7. total += array[j+4]; * for greater speed.
    复制代码
  8. total += array[j+5]; */
    复制代码
  9. total += array[j+6 ];
    复制代码
  10. total += array[j+7 ];
    复制代码
  11. }
  12. Code and show inconsistencies: for example, your interface display called postalcode, but the code does call zipcode;
  13. Hide global variables: the use of global variables in the manner of arguments passed to the function, which can make people feel that the variables are not global variables;
  14. Using a similar variable names: such as: similar words, swimmer and swimner, letters like: ilI1 | or oO08. parselnt and parseInt, D0Calc and DOCalc. There is this group: xy_Z, xy__z, _xy_z, _xyz, XY_Z, xY_z, Xy_z;
  15. Overloaded functions: use the same function name, but its function and realization has nothing to do;
  16. Operator Overloading: Overloaded operators can make your code becomes tricky, thanks to CCTV, thanks to C ++. This thing is to raise the chaos code into an art form. For example:! Operator overloading a class, but the actual function is not inverted, return an integer. So, if you use the operator, then the interesting thing occurred -!!! First class is called overloaded operators, and then returned to become its integer boolean variable, if it is !!!!? Ha ha;

Third, documents and notes

  1. Lying in a comment: You really do not have to lie, simply do not update the comments in the code to change the time on it;
  2. Notes written inside nonsense: For example: / * add 1 to i * /, just comment what it is, but not why;
  3. Do not comment Secret: If you develop a flight system, you must ensure that every flight is a new join, you have to modify the program more than 25 locations. Please do not write this thing in the document;
  4. Attention to detail: When you design a very complicated algorithm, you must take all the fine details of the design are written down, you can not give up no 100, paragraph 5 to have a level above, paragraph numbers have more than 500, for example: 1.2.4.6.3.13 - Display all impacts for activity where selected mitigations can apply (short pseudocode omitted) so that when you write code, you can make your code and documentation consistent, such as: Act1_2_4_6_3_13 () do not. Notes of the balance units. Such as the time in seconds or milliseconds is used, with the size in pixels or inches, or MB size KB. and many more. Also, in your code, you can mix different degrees of scale units, but do not comment;
  5. Gotchas trap: Do not comments in the code of the trap, to let off steam in the comments and documents;

Fourth, programming

  1. Java Casts. Java type of transformation is a godsend. Every time when you get in from a Collection object, you need to put it back to the original type. Because some of these casts will appear in the N number of places. If you change the type, so you do not have to change all the places. The compiler might be able to check, it may not check.
  2. Using Java redundancy. For example: Bubblegum b = new Bubblegom (); and swimmer = swimner + 1; nuances Note that the variable.
  3. Never verified. Never entered verification data, verification never return value of the function. Doing so can show how much you trust the company's equipment and other programmers to you
  4. Do package. The caller needs to know all the details is called.
  5. Cloning and copying. For efficiency, you have to learn to use copy + paste. You almost do not understand other people's code, you can efficiently programmed.
  6. Great listener. Write a listener, and let all of your button classes use this listener, so you can a whole lot if the listener in the ... else ... statement, quite exciting.
  7. The use of three-dimensional array. If you think three is not enough, you can try the four-dimensional.
  8. Mix. At the same time get to use the class / set methods and direct access to the public variables. The advantage of this is that maintenance personnel can greatly frustrated.
  9. Packaging, packaging, packaging. Put all your API is packaged on 6-8 times the depth of packing up to four or more layers. Then packed a similar function.
  10. There is no secret. All the members of declared public. In this way, you will later be difficult to limit their use of people, and this can cause more coupling and other code can make your code live longer.
  11. Arrangement and obstacles. After the drawRectangle (height, width) into drawRectangle (width, height), and so release several versions, then change it back. Such maintenance programmers who do not understand quickly which one is right.
  12. The change in the variable name. For example, the setAlignment (int alignment) into, setLeftAlignment, setRightAlignment, setCenterAlignment.
  13. Retention and obsolete variables, methods, and code all you do not use.
  14. Final category you all child nodes, so that when you finish this project, no one can extend your class through inheritance. java.lang.String not like this?
  15. Avoid using layout. This allows us to only use absolute coordinates. If your boss force you to use layout, you may consider using GridBagLayout, then the grid coordinates of hard code.
  16. Environment variables. If your code needs to use environment variables. Well, you should initialize the members of your class using environment variables, rather than the constructor.
  17. The use of global variables. 1) to initialize global variables in different functions, even if this function has nothing to do with this variable, so allow us to maintain the same personnel as do the detective work. 2) the use of global variables can make your argument to the function becomes less.
  18. Profile. The main configuration file used to initialize some of the parameters. In programming, we can make the configuration parameters in the file name and the actual program name is different.
  19. Expansion of your class. Let your class with a variety of methods bloated and obscure as possible. For example, your class implements only a possibility, but you have to provide all likelihood method. Do not define other classes, all the functions are placed in a class.
  20. Use subclasses. The object is to write code that can not maintain a godsend oriented. If you have a class to become ten (variables and methods) you can consider writing 10 levels of inheritance, then these ten properties were placed in ten hierarchy. If possible, these ten categories were placed in ten different files.
  21. Confusion your code. The use of XML. The power of XML is unparalleled. You can use the XML code that would have been as long as 10 lines into 100 lines. Moreover, there are also forcing others to XML. (See the letter but have eternal life XML, XML was confident the letter)

Five test

  1. Never test. Do not test any error handling, never detect the return value of the system call. 2. never be a performance test. If not fast enough to tell users for a faster machine. If you do a test, then you might want to change your algorithm, or even re-design and re-architecture. 3. Do not write test cases. Do not do code coverage testing, automated testing.
  2. Testing is a cowardly act. A brave programmers do not need this step. Too many programs are too afraid of their boss, afraid of losing their jobs, fear of users complain or be prosecuted. This fear fear a direct impact on productivity. If you have strong confidence in your code, then also what test? Real programmers do not need to test their code.

Six other

  1. Your boss knows everything. Whether your boss how SB, you have to strictly follow His will work, this way, you'll learn more knowledge and how to write code more can not be maintained.
  2. Subversion Help Desk. You want to make sure that you are full of bug in the program never be maintenance team know. When a user calls and the time to write a message to you, you do not bother even to bother to redo the system allows users to tell the user or their account has a problem, is the standard answer.
  3. To shut up. For some big bug like y2k, you have to learn secretive, do not tell anyone, including your family friends and co-workers and management, so that when that day, you can use this bug to make money.
  4. Fudge. You will learn to flicker, even if your code is poorly, you have to label their GoF Design Patterns hang, even if you do another project rotten, you have to put up its quick tag, the entire team and companies, and even the whole industry began restless, so as to maintain the code is really difficult to pave the way.

In short, our slogan is - Write Everywhere, Read Nowhere

Guess you like

Origin juejin.im/post/5d19d05cf265da1b5f266d34