开发人员急忙犯的3个错误

We want to get things done. That’s natural, and that’s what earns us a paycheck. But when switching from one task to another, we sometimes forget about crucial things — the quality of the code and our growth as programmers.

我们想把事情做好。 那是很自然的,这就是我们赚钱的原因。 但是,当从一项任务切换到另一项任务时,我们有时会忘记一些关键的事情-代码的质量以及我们作为程序员的成长。

Amongst the many sins we commit, the ones caused by hurrying are the most understandable. Nevertheless, we have to look for opportunities to take a deep breath and slow things down.

在我们犯下的众多罪恶中,匆忙造成的罪恶是最容易理解的。 然而,我们必须寻找机会深呼吸并放慢脚步。

Here’s my list of the most significant mistakes we make when we feel there’s not enough time to do things the right way.

这是我列出的最重大错误的清单,当我们觉得没有足够的时间来正确地做事情时。

无法读取足够的代码 (Not Reading Enough Code)

Have you ever seen a movie where a programmer stares at a screen for a couple of minutes and does nothing? Me either. Usually, they type something at a breakneck pace and the problem is solved. Unfortunately, our daily job is not so glamorous.

您是否看过电影,程序员在屏幕上凝视了几分钟却什么也没做? 我也是。 通常,他们以惊人的速度键入某些内容,问题就可以解决。 不幸的是,我们的日常工作并不那么光鲜。

We need to read code — lots of it. And besides reading the code, we should understand what it does and why.

我们需要阅读代码-很多。 除了阅读代码,我们还应该了解它的作用和原因。

来自互联网的随机代码 (Random code from the internet)

Not reading enough code comes in many flavors. When was the last time you were looking for some answers online, found a code snippet on Stack Overflow, and pasted it? I probably did it this week.

阅读不够的代码会带来很多麻烦。 您最后一次在网上寻找一些答案时,是在Stack Overflow上找到一个代码段并将其粘贴的吗? 我大概在这个星期做了。

There’s a big chance the code from SO works. But do you understand what it does, why it does it, and what the limitations are? Is it secure? How does it deal with edge cases and your requirements?

SO的代码很有可能起作用。 但是,您了解它的作用,原因以及局限性吗? 安全吗? 如何处理极端情况和您的要求?

Sometimes, you have to paste code and pray it works. Some things are too complicated to fathom in the limited time you have. But usually, you can understand the code in 15-30 minutes. You should be reasonably confident you know the code you put into the project. If you don’t, you may compromise the project’s security and maintainability in the long term.

有时,您必须粘贴代码并祈祷它可以工作。 有些事情太复杂了,以至于在有限的时间内无法理解。 但通常情况下,您可以在15到30分钟内了解代码。 您应该有足够的信心确定您知道放入项目中的代码。 否则,可能会长期损害项目的安全性和可维护性。

项目中的代码 (Code in your project)

How about reading your project’s code? It’s the same old story: You’re called to fix a bug in the code part you’re not familiar with. Fortunately, you have a hunch and try to fix it immediately. It works, so you push the changes and get back to your business.

如何阅读您的项目的代码? 这是同样的古老故事:有人要求您修复不熟悉的代码部分中的错误。 幸运的是,您有一种直觉,可以尝试立即修复它。 它有效,因此您可以推动更改并恢复业务。

That’s a huge mistake. If you’re not familiar with the codebase and don’t have tests, the chances your fix doesn’t break anything and handles all the cases are small.

那是一个巨大的错误。 如果您不熟悉代码库并且没有测试,那么您的修复不会破坏任何东西并处理所有情况的机会很小。

You always need to understand things before you try to fix them. Just poking around with random adjustments won’t cut it. You may be lucky once or twice, but sooner or later, you’ll break something big.

在尝试修复问题之前,您始终需要了解它们。 只是随意调整就不会削减它。 您可能会幸运一到两次,但迟早会破坏一些大事。

库中的代码 (Code in the libraries)

How many libraries do you add by default when starting a project? Are you sure you need them and understand how they are implemented?

启动项目时,默认情况下您添加了多少个库? 您确定需要它们并了解它们的实现方式吗?

I’m not trying to make a case for not using libraries and frameworks. You should use verified and well-tested code wherever possible. Reinventing the wheel is a common problem and can do more harm than good.

我不是在尝试不使用库和框架。 您应该尽可能使用经过验证和测试的代码。 重新发明轮子是一个普遍的问题,弊大于利。

What I want to say is it’s beneficial to understand the tools you’re using. Popular libraries are often excellent pieces of software, and you can learn a lot by studying their codebases. This will let you become a more skilled developer or you may realize you don’t need a certain library. Either way, you win.

我想说的是,了解正在使用的工具是有益的。 流行的库通常是出色的软件,您可以通过研究它们的代码库来学到很多东西。 这将使您成为更熟练的开发人员,或者您可能会意识到不需要特定的库。 无论哪种方式,您都赢了。

You don’t have to analyze every library you use, but when you use something time and time again, it’s worth taking a look at how it works.

您不必分析所使用的每个库,但是当您一次又一次地使用某些库时,值得一看。

Reading good code makes you a better developer and helps you understand your products. You may believe you don’t have time to read code, but that’s not true. Familiarity with your product’s code will speed up your coding, and reading other code will let you grow as a developer. So, in the long run, reading code will save you time — not waste it.

阅读好的代码可以使您成为一名更好的开发人员,并帮助您了解产品。 您可能会认为您没有时间阅读代码,但这不是事实。 熟悉产品代码将加快您的编码速度,阅读其他代码将使您成长为开发人员。 因此,从长远来看,阅读代码可以节省您的时间-不会浪费时间。

不重构 (Not Refactoring)

You need to implement a feature, and you’re in a hurry. Fortunately, you have an idea of how to build the feature quickly. So you jump in, type somewhat cryptic code, and everything seems to work. Problem solved. Time to move on.

您需要实施一项功能,所以很着急。 幸运的是,您对如何快速构建功能有所了解。 因此,您跳了进来,键入了一些含糊的代码,一切似乎都正常了。 问题解决了。 分手后要往前看了。

Wrong.

错误。

When you start coding without considering different options and stick to the first solution, your code is flawed. It may be inefficient, unreadable, or unmaintainable. In the worst case, it is all three at once and doesn’t solve the problem.

在不考虑其他选项而开始编码并坚持第一个解决方案时,您的代码就有缺陷。 它可能效率低下,无法读取或无法维护。 在最坏的情况下,这三个问题同时存在,无法解决问题。

Finishing your tickets rapidly is tempting. It may even make you proud. But a hallmark of a great developer is creating high-quality code and improving the surrounding codebase.

快速完成您的门票很诱人。 它甚至可能使您感到骄傲。 但是,出色的开发人员的特点是创建高质量的代码并改善周围的代码库。

A project where everyone is focused on shipping new features as fast as possible is doomed to create huge technical debt. Over time, it becomes less and less maintainable, and the developers’ productivity stalls. It’s the responsibility of every developer on the team to enhance the code.

每个人都致力于尽快交付新功能的项目注定会造成巨大的技术负担。 随着时间的流逝,它变得越来越难以维护,并且开发人员的生产力停滞了。 团队中每个开发人员都有责任增强代码。

So make sure you take your time implementing new features. Consider your work’s side effects and how it fits in the general application architecture. You should always leave the codebase in better shape than you found it in. Not only will it speed up development in the long term, but it will also make you a more skilled programmer.

因此,请确保您花时间实施新功能。 考虑您的工作的副作用以及它如何适合一般的应用程序体系结构。 您应该始终将代码库的状态保持在比您发现的状态更好的状态。它不仅可以长期提高开发速度,而且还可以使您成为一名更有技能的程序员。

不测试 (Not Testing)

How often do you create a feature without preparing a test to make sure it works? Unfortunately, it’s a common practice — especially in projects that need to move fast. Everyone feels tests waste the precious developers’ time, so they’re rescheduled — often forever.

您多久创建一次功能而没有准备测试以确保其正常工作? 不幸的是,这是一种普遍做法,尤其是在需要快速发展的项目中。 每个人都觉得测试浪费了宝贵的开发人员时间,所以他们被重新安排了时间-常常是永远的。

In reality, testing is crucial for any project with a long lifespan or that is likely to grow. It doesn’t matter how good your code is. Someone will have to change it. And when they do, they need a certainty that the code still works.

实际上,对于任何使用寿命长或可能会增长的项目,测试都是至关重要的。 您的代码有多好无关紧要。 有人将不得不更改它。 并且当他们这样做时,他们需要确定代码仍然有效。

What’s even worse, someone can change different code parts, which will break your feature. Without a test, you won’t know it. Correct tests provide security. They allow you to make changes in the code with confidence.

更糟糕的是,有人可以更改不同的代码部分,这将破坏您的功能。 没有测试,您将不会知道。 正确的测试可提供安全性。 它们使您可以放心地对代码进行更改。

So you may feel testing is a waste of time and money, but it’s the opposite. Your future self, or other developers, will thank you for writing useful tests.

因此,您可能会觉得测试浪费时间和金钱,但事实恰恰相反。 您将来的自己或其他开发人员将感谢您编写有用的测试。

翻译自: https://medium.com/better-programming/3-mistakes-developers-make-when-theyre-in-a-hurry-29a8a46109dd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值