用什么代码可以改变键盘_为什么我改变了对代码质量的看法

用什么代码可以改变键盘

by John Cobb

约翰·科布(John Cobb)

为什么我改变了对代码质量的看法 (Why I changed the way I think about Code Quality)

What do you think about when you think about code quality?

当您考虑代码质量时,您会怎么看?

Is it consistency? Enforcing a set of standards and best practices on your code through linter rules and formatters? How about ensuring your code has tests that run automatically during your build process? What about pull requests and code reviews — protecting your master branch from direct commits and having peers review your code?

是否一致? 通过linter规则和格式化程序对代码执行一套标准和最佳实践? 如何确保您的代码具有在构建过程中自动运行的测试? 拉取请求和代码审查又如何—保护您的master分支免受直接提交并让同级审查您的代码?

They’re some of the things that come to mind for me. Automated processes and manual checks. Smart and efficient. Yet, while they’re all useful, they really only address half of the problem.

这些是我想到的一些东西。 自动化流程和手动检查。 聪明高效。 然而,尽管它们都很有用,但实际上只能解决一半的问题。

我们不能使一切自动化 (We can’t automate everything)

Automation is crucial for maintaining code quality. Static analysis of your syntax with a linter and automated testing should be mandatory. But I can write code that passes all the automated processes without any guarantee to its actual quality.

自动化对于保持代码质量至关重要。 必须使用lint对语法进行静态分析并进行自动测试。 但是我可以编写通过所有自动化过程的代码,而不能保证其实际质量。

Does the code follow established patterns? Does it use existing modules, or does it duplicate code? Is everything named sensibly? Is the code in the right place in the codebase? Will this change have wider, unintended, implications? Does this code actually address/solve what it intends to? Does it even work?

代码是否遵循既定模式? 它使用现有模块还是重复代码? 一切都被合理地命名了吗? 代码是否在代码库中的正确位置? 这种变化会产生更广泛的,意想不到的影响吗? 此代码是否实际解决/解决了预期的问题? 它甚至工作

Automated processes can’t answer those questions for you (yet). If you (or another human being) aren’t asking these questions of your code, then you’re probably not shipping quality code. That’s why we have code reviews.

自动化流程无法为您回答这些问题(至今)。 如果您(或其他人)没有问代码的这些问题,那么您可能没有在交付质量代码。 这就是为什么我们要进行代码审查。

良好的代码审查不仅仅应包含代码 (A good code review should be about more than the code)

Of course a code review should be about the code (it’s right there in the name after all). But it should also be about the broader questions posed above, and also about the end product.

当然,代码审查应该是关于代码的(毕竟它就在名称中)。 但这还应与上面提出的更广泛的问题以及最终产品有关。

I’ve noticed a tendency for developers to treat code reviews as perfunctory. A rudimentary check of the modified code. A comment on any obvious mistakes (or just picking a nit or two to look busy).

我注意到开发人员倾向于将代码审查视作敷衍。 对修改后的代码的初步检查。 对任何明显的错误发表评论(或者只是挑一两个尼特,让他们看起来很忙)。

Five minutes, job done. Looks good to me.

五分钟,工作完成。 对我来说看起来不错

But, code that doesn’t address the requirements of the task is not quality code. Code that produces console errors or visual bugs in the device/browser is not quality code. Neither of those things can be picked up in a perfunctory code review. You can’t adequately review code unless you actually run it.

但是,不能满足任务要求的代码不是质量代码。 在设备/浏览器中产生控制台错误或视觉错误的代码不是质量代码。 这些功能都无法在敷​​衍的代码审查中找到。 除非您实际运行代码,否则您将无法充分审查代码。

I propose that a good code review should involve at minimum:

我建议良好的代码审查至少涉及:

  • Pulling down the branch to a local environment.

    将分支拉到本地环境。
  • Building the project (and checking that the linter and tests all pass).

    构建项目(并检查短毛绒和测试是否全部通过)。
  • Checking that the code runs error free in the target browsers/devices.

    检查代码是否在目标浏览器/设备中无错误运行。
  • Checking that the completed work matches the requirements of the task.

    检查完成的工作是否符合任务要求。

If there are any issues with any of those steps the pull request should be rejected. Do not pass Go. Do not collect $200. Do not merge to master.

如果这些步骤中的任何步骤有任何问题,则应拒绝请求请求。 不要通过围棋。 不要收取200美元。 不要合并到母版。

Reviewers should also use the code review as an opportunity to ask questions. If you don’t understand the code, then you shouldn’t approve the pull request. Don’t assume that the author knows more than you do — if it doesn’t make sense to you, ask for clarification.

审阅者还应将代码审阅作为提问的机会。 如果您不理解代码,则不应批准请求请求。 不要以为作者比你了解更多—如果这对你没有意义,请澄清。

The reviewer has equal responsibility with the author for the quality of the code. This is a mindset that is essential for maintaining code quality.

审阅者与作者对代码质量负有同等责任。 这是保持代码质量必不可少的一种心态。

Comprehensive code reviews go a long way to helping ensure code quality. But there are steps you can take before you even open a pull request. Small things you can do that will help enhance the quality of your code, and reduce the effort required to review it.

全面的代码审查对确保代码质量大有帮助。 但是,您甚至可以在打开拉取请求之前执行一些步骤。 您可以做的小事情将有助于提高代码的质量,并减少检查代码所需的工作。

仔细检查您自己的作品是否完整 (Double check your own work for completeness)

I have an annoying habit. When I finish writing the last lines of code for a task, I mentally check the task off as complete.

我有个烦人的习惯。 当我完成任务的最后几行代码编写时,我会在脑海中检查任务是否完成

If I were to listen to that impatient voice in my head, I’d submit my pull request right then. But that code would likely contain many, or all, of the following:

如果我想听听我脑子里那急躁的声音,那我马上就要提交我的请求。 但是该代码可能包含许多或全部以下内容:

  • Missed requirements.

    错过的要求。
  • Missing test cases.

    缺少测试用例。
  • Superfluous, unused or draft code.

    多余的,未使用的或草稿的代码。
  • Not enough code comments.

    代码注释不足。
  • Visual bugs in some browsers/devices.

    某些浏览器/设备中的视觉错误。

If any of those things are true about your code, then your code is not complete. If any of those things end up in the master branch, then you have degraded the quality of the codebase.

如果您的代码中有任何上述情况,则您的代码不完整。 如果这些事情中的任何一个最终出现在master分支中,则说明代码库的质量下降了。

The main point here is this: code quality starts with the code author. You shouldn’t rely on automated tasks, a code review, quality assurance or user acceptance testing to catch your mistakes.

这里的重点是:代码质量始于代码作者。 您不应该依靠自动化任务,代码审查,质量保证或用户验收测试来发现错误。

Double checking work for completeness is an essential first step toward code quality. It’s the easiest step to take, but also the easiest one to ignore.

进行双重检查以确保完整性是迈向代码质量必不可少的第一步。 这是最简单的步骤,也是最容易忽略的步骤。

You should only open up a pull request when you are certain your code is complete.

仅在确定代码完成后才应打开拉取请求。

对分支机构进行自我审查 (Perform a self review of your branch)

I’m always surprised at how many issues — or opportunities to refine a solution — I can find in my own code. Issues and opportunities that only become visible to me when I step back and view my changes in isolation.

我总是在自己的代码中发现有多少问题或改进解决方案的机会,总是感到惊讶。 当我退后一步,孤立地查看我的更改时,问题和机会才对我可见。

You can review your work and apply your own feedback before assigning a team member to review your work. You can also use this opportunity to leave comments on the pull request to clarify anything for the reviewer.

您可以在分配团队成员来审查您的工作之前,先审查您的工作并应用您自己的反馈。 您还可以利用此机会在请求请求中留下评论,以使审阅者澄清任何事情。

Taking time to ensure your work is complete, to correct obvious mistakes, or assess your solution, will enhance the quality of your code. It also reduces the effort required to review it.

花一些时间来确保您的工作完成,纠正明显的错误或评估您的解决方案,将会提高代码的质量。 它还减少了审核所需的工作。

It might also save you some embarrassment. I know it has for me.

这也可能使您免于尴尬。 我知道它适合我。

确保代码质量应该是每个开发任务的内在要求 (Ensuring code quality should be an inherent requirement of every development task)

You may be thinking that this approach adds time to the length of a task. And you’re right, it does. But that isn’t a bad thing.

您可能会认为这种方法会增加任务时间。 你是对的,的确如此。 但这不是一件坏事。

Efficiency is important, but laziness and apathy is harmful. Apathy leads to a bloated, inconsistent code base. Laziness creates a growing backlog of bad technical debt. We can’t be passive and maintain code quality. It requires time and effort.

效率固然重要,但懒惰和冷漠是有害的。 冷漠会导致a肿的,不一致的代码库。 懒惰导致不良技术债务积压的情况越来越多。 我们不能被动地保持代码质量。 这需要时间和精力。

Changing the culture around code quality can be hard. Project managers and product owners generally aren’t concerned about code quality — they have their own concerns. Requesting extra time for code quality processes can sometime fall on deaf ears. However, maintaining code quality shouldn’t be thought of as something extra — it should be an inherent requirement of every task.

改变围绕代码质量的文化可能很难。 项目经理和产品所有者通常不关心代码质量-他们有自己的问题。 为代码质量过程请求额外的时间有时会置若de闻。 但是,不应将保持代码质量视为额外的工作—它应该是每个任务的固有要求。

As developers, if we don’t change the way we think about code quality, we can’t expect anyone else to.

作为开发人员,如果我们不改变我们对代码质量的方式,我们不能指望别人。

Nothing I’ve talked about here is particularly groundbreaking, nor is it prescriptive. Not every team, workplace, or project is the same, and some of the above may not be applicable to you.

我在这里谈论的没有什么特别开创性的,也不是规定性的。 并非每个团队,工作场所或项目都是相同的,并且上述某些内容可能不适用于您。

I do believe there is often a gap between the way developers think about code quality, and the actual actions taken to address it. If you’ve found that too, then hopefully there is something you can take away from this article — or perhaps you’ve already taken a different approach to addressing it. I’d love to hear your suggestions in the comments.

我确实相信开发人员对代码质量的思考方式与为解决该问题而采取的实际措施之间通常存在差距。 如果您也发现了这一点,那么希望本文可以对您有所帮助–也许您已经采用了另一种方法来解决它。 我很想听听您在评论中的建议。

Thanks for reading!

谢谢阅读!

翻译自: https://www.freecodecamp.org/news/why-i-changed-the-way-i-think-about-code-quality-88c5d8d57e68/

用什么代码可以改变键盘

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/394870.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

建模:建模清单

ylbtech-建模:建模清单1.返回顶部 2.返回顶部3.返回顶部4.返回顶部5.返回顶部 6.返回顶部作者:ylbtech出处:http://ylbtech.cnblogs.com/本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明&#xf…

获得picker选项的当前年月值_如果你用OPPO手机!千万记得开启开发者选项,手机性能大幅度提升...

如果你用OPPO手机!千万记得开启开发者选项,手机性能大幅度提升用过OPPO手机的用户都知道,手机使用1-2年都会出现卡顿的情况。这也是安卓手机的通病,但也有很多朋友手机使用3年也不会出现卡顿的现象,都是因为打开了手机…

imageset matlab,如何以imageSet或imageDataStore的形式向MATLAB中的BagOfFeatures()函數提供輸入?...

我想使用MATLAB的bagOfFeatures()函數。但它需要以imageSet或imageDataStore的形式輸入。我想運行的代碼如下:如何以imageSet或imageDataStore的形式向MATLAB中的BagOfFeatures()函數提供輸入?Dataset D:\dsktop\kinect_leap_dataset\acquisitions;thre…

Django运维后台的搭建之四:用bootstrap模板让运维前台变得更漂亮

我对于PHP和ajax是属于二把刀的水平,所以做网页前端肯定是比上天还难,但是我又想把网页做的漂亮可爱,怎么办呢?我就只好去download别人的模板,在这里我使用了bootstrap框架做的模板。各位可以去https://wrapbootstrap.…

codeigniter_如何在浏览器中查看CodeIgniter日志文件

codeigniterby Seun Matt通过Seun Matt 如何在浏览器中查看CodeIgniter日志文件 (How to View CodeIgniter Log Files in the Browser) Just like any other page, it is now possible to read CodeIgniter log files in the browser. My Sweet Goodness!与其他页面一样&#…

小程序强制自动更新

(3)强制更新官方版 微信团队2018-03-2315987浏览背景 此前有开发者反馈小程序发布新版本后,新版本覆盖率比较慢,因为小程序的更新机制是异步的,部分用户不会马上应用上新版本。 小程序启动会有两种情况,一种是「冷启动」&#xff…

联想m7400pro更换墨粉盒怎么清零_佳能打印机怎么换墨水 佳能打印机换墨水注意事项【详解】...

佳能打印机是我们办公室用品中比较常见的一个品牌,作为国际知名品牌,其质量也是非常有保障的。在使用的时候打印机没有墨是经常会遇见的。这时候我们就需要更换墨水盒了。但很多不知道具体步骤,或者没有注意相关细节,导致换墨水盒…

oracle数据库连接数超了,oracle数据库当前和最大连接数

1、查询oracle的连接数select count(*) from v$session;2、查询oracle的并发连接数select count(*) from v$session where statusACTIVE;3、查看不同用户的连接数select username,count(username) from v$session where username is not null group by username;4、查看所有用户…

MySQL Workbench导出数据库

步骤: 1. 打开mysql workbench,进入需要导出的数据库,点击左侧栏的【Management】tab键。 2. 点选要输出的数据库 点击【Data Export】选在要输出的数据库选择是否输出存储过程和函数,事件,触发器 点击Start Export3. …

django 传递中文_如何在Django中建立消息传递状态

django 传递中文by Ogundipe Samuel由Ogundipe Samuel 如何在Django中建立消息传递状态 (How to Build a Message Delivery Status in Django) Today, we will make a real-time message delivery status framework with Django and Pusher.今天,我们将使用Django和…

软链接与硬链接

文件引用模型 在linux中,一切皆文件,而文件包含元数据(metedata)和用户数据(user data)。元数据中的inode号是系统标识和获取用户数据的唯一凭证,而文件名仅是为了方便用户记忆和使用。为了管理…

c++ 数组的输入遇到特定字符停止输入_C语言 第4章-字符串和格式化输入/输出

#include 用数组name储存字符串,name数组有40个字节,每个字节储存一个字符值。在scanf()函数中,输入字符串name没有&前缀。C预处理器把字符常量DENSITY定义为62.4。strlen()获取字符串长度。1. 字符串1.1. char类型数组双引号标记字符串&…

vue3+typescript引入外部文件

vue3typescript中引入外部文件有几种方法 &#xff08;eg:引入echarts&#xff09; 第一种方法&#xff1a; 1 indext.html中用script引入 <div id"app"></div><script src"https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts-en.common.min.js…

在哪能找到陌生人聊骚_如何说服陌生人帮助您找到工作

在哪能找到陌生人聊骚by Alex Lacey通过亚历克斯莱西 找工作吗&#xff1f; 这是说服陌生人帮助您找到一个人的方法 (Looking for a job? Here’s how to convince strangers to help you find one) 我过去获得40个推荐的7个步骤 (The 7-step process that I used to get 40 …

Python基础 day2

Python基础 一、Python的数据类型 1、int(整型) 在32位机器上&#xff0c;整数的位数为32位&#xff0c;取值范围为-2**31&#xff5e;2**31-1&#xff0c;即-2147483648&#xff5e;2147483647&#xff0c;而.在64位系统上&#xff0c;整数的位数为64位&#xff0c;取值范围为…

matlab 文件指针回到开头,[c/c++] 文件指针位置回到文件开头(rewind)及行开头(ftell+fseek)...

待读入文件1.greenteemo2.csdn3.blog代码&#xff0c;详细说明见注释#include #define LENGTH_OF_LINE 1024int main(){FILE *fp fopen("file.txt", "r"); // 打开文件char line[LENGTH_OF_LINE];while( fgets(line, LENGTH_OF_LINE, fp) ){printf("…

python全栈开发优势_Python全栈开发多少钱?学Python价格贵吗?

Python全栈开发培训多少钱?学习Python是大家进入编程世界的理想之选&#xff0c;而且Python也是一门非常受欢迎的编程&#xff0c;可以从事的领域有很多。 从目前市场上的行情来说&#xff0c;一般情况下Python培训的费用在一万五到两万元之间的&#xff0c;以后可能会更高&am…

gym101808 E

提问&#xff1a;我是什么品种的傻逼&#xff1f; 哇看到积水兴高采烈啊。然后就走上了一条不归路。 为什么不归呢&#xff0c;因为我这个法子就是不对的&#xff0c;我总是在想很多很多点围成的一块区域&#xff0c;然后求这一块区域的面积。 然后尝试了各种扫描方法&#xff…

WordPress中缠结的自定义数据世界

by Kamil Grzegorczyk通过卡米尔(Kamil Grzegorczyk) WordPress中缠结的自定义数据世界 (The Tangled World of Custom Data in WordPress) 降低风险并管理您的自定义字段 (Reducing Risk and Managing Your Custom Fields) Have you ever wondered how to properly name keys…

【站点部署】解析二级域名并部署站点

开设原因 : 近期在学健身, 上一份工作辞掉后, 在北京找了家私人教练培训学校, 进行为期四个月的健身培训, 这个比在健身房找私教专业多了, 被健身房私人教练坑慘了, 说多了都是泪, 已经培训了将近一个半月, 学习了基础私教, 普拉提, 这在学习康复课程, 之后还有功能性 和 综合格…