小米5s服务器代码
Sometimes code turns ugly. We add quick fixes or enhancements and our code starts to become a big tangle of functions that aren’t laid out in any sort of organized fashion. Over time, our code becomes bloated, difficult to maintain and what should be simple little fixes can quickly turn into long walks through messy syntax. One way of combating this is by implementing the 5S System.
有时代码变得丑陋。 我们添加了快速修复或增强功能,并且我们的代码开始变得杂乱无章,无法以任何有组织的方式进行布局。 随着时间的流逝,我们的代码变得肿,难以维护,而简单的小错误修复很快就会变成凌乱的语法。 解决此问题的一种方法是实施5S系统。
The 5S System is actually a Japanese improvement process originally developed for the manufacturing industry. Each of the five words when translated to English began with ’S’ hence we call it the 5S System. Like many good philosophies however, the 5S System can apply to a variety of topics. For example, the 5S System has been applied by the Hewlett-Packard Support Center in a business context and has resulted in improvements like reduced training time for employees and reduced call-times for customers. By using the system applied to coding, we can make our code more efficient and much easier to maintain.
5S系统实际上是最初为制造业开发的日本改进程序。 五个单词中的每个单词翻译成英语后都以“ S”开头,因此我们将其称为5S系统。 像许多优秀的哲学一样,5S系统可以适用于各种主题。 例如,惠普(HP)支持中心在商业环境中应用了5S系统,并带来了改进,例如减少了对员工的培训时间和减少了对客户的呼叫时间。 通过使用用于编码的系统,我们可以使我们的代码更高效且更易于维护。
The first ’S’ is Seiri which roughly translates to ‘Sort’. Applied to the manufacturing industry, the goal of sorting was to eliminate unnecessary clutter in the workspace. The idea here is that in a workspace, you need to sort out what is needed and what is not. If you eliminate all of the items that are not necessary, you immediately have a workspace that is cleaner and thereby more efficient
第一个“ S”是Seiri,它大致翻译为“排序”。 在制造业中,分类的目的是消除工作空间中不必要的混乱。 这里的想法是,在工作空间中,您需要梳理需要的和不需要的。 如果您消除了所有不必要的项目,那么您将立即拥有一个更干净,更高效的工作空间。
Applied to coding, this can mean going through our code and determining if we have any lines of code that are really just taking up space. This can be things like error checking that has already been done at a previous step, or if working in the DOM, retrieving the same element in more than one function, instead of simply passing a reference to the element. This definitely applies to CSS code as well. There are very few stylesheets in use that don’t have a line or two that are really just unnecessary because they either accomplish nothing different than the user agent’s default behavior, or are being overridden elsewhere.
应用于编码时,这可能意味着要遍历我们的代码并确定我们是否有任何实际上仅占用空间的代码行。 这可以是上一步已经完成的错误检查之类的事情,或者是在DOM中工作时,可以在多个函数中检索同一元素,而不是简单地将引用传递给该元素。 这当然也适用于CSS代码。 很少使用没有一行或两行的样式表,这些样式表实际上只是不必要的,因为它们要么完成与用户代理的默认行为相同的功能,要么被其他地方覆盖。
The next ’S’ means to straighten or ‘sort in order.’ This step involves arranging resources in the most efficient way possible so that those resources are easy to access.
下一个“ S”表示拉直或“按顺序排序”。 此步骤涉及以最有效的方式安排资源,以便易于访问这些资源。
For coders, this means going through and making sure that functions and code snippets that are related are grouped together in some way. This can be done by a variety of ways. If you are working with server-side scripting, consider placing related code together in an include. In CSS, use either comments or imported stylesheets to separate style declarations based on either the section of page they refer to or the design function that they carry out. (Typographic styles in one place, layout styles in another). In object-oriented programming, organize your code into logical classes and subclasses to show relationships.
对于编码人员来说,这意味着要仔细检查并确保以某种方式将相关的功能和代码段组合在一起。 这可以通过多种方式来完成。 如果使用服务器端脚本,请考虑将相关代码放到包含中。 在CSS中,根据注释所引用的页面部分或所执行的设计功能,使用注释或导入的样式表来分隔样式声明。 (印刷样式在一个地方,布局样式在另一个地方)。 在面向对象的编程中,将代码组织为逻辑类和子类以显示关系。
The third step laid down in the 5S system is the Shine phase. This involves getting and keeping the workplace clean. This is an on-going phase that should be done frequently to polish up anything that is starting to lose its luster.
5S系统中的第三步是Shine阶段。 这涉及到保持工作场所的清洁。 这是一个正在进行的阶段,应该经常进行以完善任何开始失去光泽的东西。
As we go back and work on code, we can often start to get lazy and just throw things wherever and use messy coding techniques because it’s quick and dirty. The long term result of that though is unorganized code that is difficult to maintain. The phase requires a bit of discipline, we have to be willing to keep an eye out for portions of our code that are becoming a bit unwieldy and take the time to clean it up so 6 months down the road we aren’t pulling out hair trying to remember what the heck we were thinking there.
当我们回过头来处理代码时,我们经常会变得懒惰,随便扔东西,然后使用凌乱的编码技术,因为它既快速又肮脏。 但这的长期结果是难以维护的无组织代码。 这个阶段需要一些纪律,我们必须愿意留意我们的部分代码变得有些笨拙,并花时间清理它,所以在接下来的6个月中我们不会拔头发试图记住我们在想什么。
The Standardize phase involves setting down standards to ensure consistency. We can apply this to our coding and make it much easier both for us in the future, and for new employees who may have to try and work with some of the code we have developed.
标准化阶段涉及制定标准以确保一致性。 我们可以将其应用到我们的编码中,这对于我们将来以及对于可能不得不尝试使用我们开发的某些代码的新员工来说,都将变得更加容易。
Standardization in code can come in a variety of forms. We’ve seen some standardization in coding for-loops for example. In a for-loop it is very typical for people to use the variable i as the counter variable throughout the loop. Coders of various levels of expertise recognize the variable i in those situations very quickly and easily, because it is used so frequently.
代码的标准化可以有多种形式。 例如,我们已经在for循环的编码中看到了一些标准化。 在for循环中,人们通常在整个循环中都将变量i用作计数器变量。 各种专业水平的编码人员在这种情况下都可以非常快速,轻松地识别变量i,因为它是如此频繁地使用。
You can also standardize the way you format your code. Some people prefer to indent code inside of loops or functions for readability, others don’t. Whatever the case may be, be consistent with it. Having a consistent coding style makes it a lot easier to come back to that code later and be able to quickly locate where that new feature needs to be dropped in.
您也可以标准化格式化代码的方式。 有些人喜欢在循环或函数内缩进代码以提高可读性,而另一些人则不喜欢。 无论是哪种情况,都应与之保持一致。 拥有一致的编码风格可以使以后更轻松地返回到该代码并能够快速找到需要插入新功能的位置变得容易得多。
Finally, our last step is to sustain the work we set down in each of the previous phases. This is perhaps the most difficult phase of all because it is never ending. There is a definite level of commitment to the process that has to be displayed here in order for us to continue using and utilizing this process when we code. We can’t be satisfied with doing this once or twice and then letting it go. If we work to continually implement this process, we help ourselves to create more manageable and efficient code from the start of the development process to the conclusion.
最后,我们的最后一步是维持我们在之前每个阶段中确定的工作。 这可能是所有阶段中最困难的阶段,因为它永远不会结束。 必须在此处显示对流程的明确承诺,以便我们在编码时继续使用和利用此流程。 我们对执行一次或两次然后放手不满意。 如果我们致力于持续实施此过程,那么我们将帮助自己创建从开发过程开始到结论的更易管理和高效的代码。
翻译自: https://timkadlec.com/2008/04/more-manageable-efficient-code-through-5s/
小米5s服务器代码