当前位置:网站首页>Teach you to write non maintainable PHP code step by step
Teach you to write non maintainable PHP code step by step
2022-06-25 04:49:00 【Oglie's magic slippers~】
With the unemployment rate getting higher , Many people realize how important it is to keep their jobs . that , What is keeping your job , And a good way to make yourself irreplaceable ? A simple fact is that as long as no one can maintain your code , Then you will succeed in keeping your job . Writing non maintainable code is a special skill , But it's strange , It seems natural for some developers . But for the rest of the developers , Here are some tips and tricks to get you started writing non maintainable code .
The first thing to do
First step , Start looking for a job . You should look for the right company , Where you can unleash and realize your unmaintainable potential . You don't have to be part of the company PHP Daniel, it would be better . When looking for a job , If the job description mentions the need to migrate from other to PHP ( So you know you're in charge ), Or you can search for that need 10 year PHP5 Misleading work experience , Coupled with skilled use FrontPage and Netscape Composer .
Once you get this once-in-a-lifetime opportunity , Take steps from day one . Speaking at the meeting , Let your opinions be heard . Talk about object-oriented architecture , Enterprises , the reform program , How to make good enough better , Of course, you have to make corresponding commitments . Make sure everyone consults with you on important coding issues .
Non maintainable core
Inspired by excellent articles “Writing unmaintainable code” ( People who want to keep their jobs will see ), Here are two important concepts you need to master and master :
You should make it impossible for others to modify anything easily , Unless he destroys something else .
Maintainers don't have time to understand your code . Maintainable code means being able to quickly locate specific parts of a mountain of code , Be able to quickly understand how it works and modify it without breaking something . You can't do this . Don't let others easily search for something or find it where they expect it to be .
Your code cannot “ look ” It's not maintainable ( Because others will doubt ), It has to “ yes ” It's not maintainable .
The code should look normal to the maintainer , But give them a surprise when they least expect it .
Best practices
Prohibit code conventions . There is no end to the abuse of coding and naming conventions . Such a situation must not occur in your excellent organization . You have some awesome projects to do , You can't spend countless hours discussing tab Or space . Besides , An agreement is a restriction . If a new employee is hired , And he is not used to your agreement , He'll be in pain . Unhappy programmers are inefficient programmers . Anyone who asks you will explain to them . Let everyone write code in their own style . As for your own code - Change your agreement . On Monday camelCase Naming of small hump , On Tuesday all_lowercase All lowercase names , Mix it on Friday , At every 2 month 29 Japan Use Hungarian nomenclature .
Don't write notes . Your code is beautiful , It does not require comments . If someone doesn't understand your code , Then it is very likely that they are not such good programmers . If , If this is possible , You are forced to write notes , So direct and exaggerated . Describe in detail the most obvious and least important code , Skip other .
Use Notepad encoding . Or use another editor that doesn't show code indentation . Make others suffer and eventually leave the team . So you don't have to listen to their complaints all the time . If someone asks you why you use Notepad , Be prepared to explain : Because it comes from Windows ( The only one today , An operating system for creative programmers ), No necessary training is required , And at no cost . I believe you can find references on the Internet that you can use any program , even Word, To write your web code , But only Notepad is the real authority , After all , Only you are the authority of the people employed by your company .
Reject unit tests . Explain to anyone who questions you , You are hired to write high-quality, bug free code ( therefore , There is no need to test ). Why would a sane person take the time to write unimportant tests to verify that the code works properly ? Some things in life are like - The sky is blue , The sun rises in the East , Your code is working properly , So thank you very much . continue ( Like a comment , If forced to take the test , So be prepared to test the obvious and skip the rest )
Do not use a template engine . The template engine can help you distinguish between the business logic layer and the presentation layer . It can guarantee the maintainability of the code, so you can't follow this rule .PHP The father of Rasmus Lerdorf Said :“PHP Template engine ”. Even if you have to use a template engine , Also find a way to abuse it , For example, put some business codes in the template , Or be careful to HTML( and CSS and JavaScript) The code is mixed in the database access layer .
Generally speaking , Try to put your... In the same line of code PHP,HTML,CSS and JavaScript The code is rightfully mixed together . stay PHP Create... In code JavaScript And with inline styles HTML Code . If someone asks , Tell them this pattern is called “ encapsulation ”, You will take full responsibility for your code .
version control . Although this is hard to avoid , But getting rid of any form or version control is worth trying . You can prove to everyone during the discussion that this improves the communication between team members , Instead of relying on cold-blooded version control software . If you don't convince anyone , Please don't despair . You can submit without commit all . Keep some of your own code locally . So if someone other than you tries to build and deploy , These small and deadly code snippets will destroy the project . If caught , Just argue that the code is not suitable for display , After all , You have submitted high-quality code and excellent solutions that can educate the junior team . These little boys and girls will look up to you and look forward to it !
Build a framework . Then you inevitably become an architect , Your authority is beyond doubt . So you can add some secret conventions ( Of course, most of them are sometimes contradictory ), Even the most experienced maintenance personnel are not aware of . Your framework will be responsible for everything , No one needs to bother to understand it , Everyone will be very happy because you make development easier and improve the productivity of the whole company . Don't publish your framework as open source , because a) This framework is the company's asset and the company has invested a lot of money , b) The open source community will laugh at you , And this will be the end of your bluff .
Naming is related to
Your variable name should be a little mysterious , It is better to have only one letter . In this way, no one can find the required content through simple search .
Class names and methods are best defined with a single letter . If you really want to define a normal name , Use it all the time —— remember , The best way to hide information is to use it frequently . When the same name is used repeatedly ( be called “ Object oriented programming ”) when , If you put parentheses and curly braces on a new line , This will help improve the readability of the code , And let teammates look for anything in your code , You have to go over regular expressions . Think about it :
$noodles = 1;
class
noodles
{
var $noodles = 2;
function
noodles ()
{
$noodles['noodles'] = 'noodles';
}
}
function
noodles() {
return new noodles;
}
$noodles = noodles();
var_dump($noodles);
You can also use fancy character sets to name variables . Cyrillic alphabet is very suitable , Because some letters look like Roman letters , But it's not ( All of these :xopekacMEBCTAKXOPH). So the following output is :
$alert = 1;
$аlert = 2;
echo $alert;
If the second one alert In Cyrillic letters “a” start , Do not place !
Quote relevant
Even if you define something very normally , But that doesn't mean you can't use it in interesting ways . The main weapons are :
eval()
Volatile variables
Mutable class , such as $strudels = "noodles"; $noo = new $strudels
;
call_user_func()
Basically any language structure that treats code as a string is your good friend .
// calling abc();
$z = 'A';
call_user_func($z .'bC');
Capitalization
Letter example , Function method names are not case sensitive , Abuse this feature .
function abc(){
echo "abc";}AbC();
On the other hand , The key of the array (key) Case sensitive , Also abuse this feature .
$a['UseConvetionsOnlyTobreakThem'] = 1;if (isset($a['UseConvetionsOnlyToBreakThem'])) {
// ?? Capitalization B !!1!}
rewrite
Override global variables in unexpected situations , Especially super global variables . Rewrite as early as possible G E T Count Group in Of Belong to sex , many Time heavy Write , _GET Properties in the array , Rewrite... Many times , GET Count Group in Of Belong to sex , many Time heavy Write ,_POST The same is true . stay $_REQUEST Do some obscure rewriting on as embellishment . If it's in WTF-ed On , You can explain that you are preventing users from entering XSS attack 、 Injection attacks and other virus attacks .
Control structure
Use 、 blend 、 Match all alternative if,while,for,foreach,switch grammar . If asked , All of these , Please explain that you are training new employees to learn the real language .
if ($a > 5):
if ($a > 4) {
while ($a > 0):
echo --$a;
endwhile;
}endif;
Nested ternary operators , There's nothing better than this 、 More concise code .
// Guess what the output here is echo true ? 'true' : false ? 't' : 'f';
stay for In the circulatory system , Add again $i To keep everyone's attention . perhaps , By not using $i To realize the surprise of cyclic increment . never .
Nested loop 、 thorough , Then suddenly jump out of them ( loop ). image break 2 and break 3 Such code is stored for entertainment , Especially when mixed with strange indentation code .
This is the beginning !
That's all for today . I hope you believe you can do it yourself , You can also write non maintainable code . Now your future is in your hands ! Of course , You can also write readable code , But at the risk of being replaced .
Practice makes perfect.
Original address :http://www.phpied.com/how-to-write-unmaintainable-php-code-2009/
come from php Chinese net
边栏推荐
- Simple text analysis of malicious samples - Introduction
- EL & JSTL (XIII)
- [image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]
- Response (XI)
- 固態硬盤開盤數據恢複的方法
- Which programming language is the most cumbersome to implement Hello world?
- Join() in JSZ
- Wechat likes to pay attention to the solution of invalid automatic reply
- Cascading deletion of gbase 8s
- STM32的DMA双缓冲模式详解
猜你喜欢
Why is the TCP handshake just 3 times?
[esp32 learning path 6 - Flash encryption]
WPF 使用 MAUI 的自绘制逻辑
Mongodb cluster
【无标题】
Part I Verilog quick start
[image fusion] image fusion based on MATLAB directional discrete cosine transform and principal component analysis [including Matlab source code 1907]
为什么SQL语句命中索引比不命中索引要快?
win11蓝牙无法连接怎么办?win11蓝牙无法连接的解决方法
Paper notes: multi label learning ESMC (I don't understand it, but I haven't written it yet, so I'll put it here for a place temporarily)
随机推荐
《牛客刷verilog》Part I Verilog快速入门
Construction scheme of distributed websocket
JS arguments
Immutable学习之路----告别传统拷贝
机器学习深度学习——向量化
第九章 APP项目测试(2) 测试工具
2.0SpingMVC使用RESTful
Gbase 8s index b+ tree
以太网是什么要怎么连接电脑
Deep learning - several types of learning
基于Cortex-M3、M4的精准延时(系统定时器SysTick延时,可用于STM32、ADuCM4050等)
【图像融合】基于matlab方向离散余弦变换和主成分分析图像融合【含Matlab源码 1907期】
515. find the maximum value / Sword finger offer II 095 in each tree row Longest common subsequence
OpenSea PHP开发包
The solution of wechat applet switchtab unable to take parameters
Gbase 8s overall architecture
What if the desktop computer is not connected to WiFi
Calculate student grade (virtual function and polymorphism)
ASEMI三相整流桥的工作原理
JS' sort() function