Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
维护
|
257
对此,你能采取的首要措施是
为记录错误提供一个易用的标准化方法
,并形成文档。这个
方法不要设计得太复杂,也不要太难懂。要确保每个接触到你的项目的开发人员都理解。
它可以简单到仅暴露一个
meadowlarkLog
函数(
log
这个名称常常被其他包使用)。至于这
个函数是记录到数据库里、普通文件里、电子邮件里,还是它们的某种组合里都没关系,
重要的是它必须是标准化的。标准化也让你得以提升日志机制(例如,对服务器做横向扩
展时,普通文件就没那么有用了,于是你就可以修改
meadowlarkLog
函数,让它记录到数
据库里)。一旦有了这个日志机制、已经文档化了,而且团队中每个人也都了解它,就可
以把“检查日志”加入
QA
核对清单中,并且针对如何检查日志设置相应的步骤。
22.2
 代码重用与重构
浪费时间一次又一次地做无用功,这是我时常看到的悲剧。通常这些“无用功”都是很小
的东西,比如那些与其从数月前的某个项目中挖出一段还不如重新写来得容易的代码。这
些重写的代码片段会越积越多。更糟糕的是,它破坏了
QA
的原则
,因为你很可能就不打
算去为这些小片段写测试了(本来没有重用已有的代码就已经浪费了时间,如果写了测
试,就相当于浪费双倍时间)。
即使做的事情一样
,每个代码片段也可能有不同的
bug
。
这是一个坏习惯。
在
Node
和
Express
的开发中
,有一些非常好的机制,可以克服浪费时间做无用功这个问
题。
Node
带
来了命名空间(通过模块)和包(通过
npm
)的机制,而
Express
带来了中间
件的概念。运用这些工具,开发可重用的代码就容易多了。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099