Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成 how-to-write-clean-code.md #1143

Merged
merged 1 commit into from
May 31, 2023
Merged

Conversation

songyp0505
Copy link
Contributor

@songyp0505 songyp0505 commented May 27, 2023

Checklist:

Closes #1141

@songyp0505
Copy link
Contributor Author

@miyaliu666 miya姐这篇完成啦,好久没翻,有点生疏了😬


Clean code is free from complexity, redundancy, and other code smells and anti-patterns that can make it difficult to maintain, debug, and modify.
整洁的代码脱离了复杂性、冗余以及一些“代码味”和反人类模式,因为这些东西会让代码变得难以维护、调试以及修改。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


So in this article we'll talk about what the term "clean code" means, why it's important, how can we assess whether a codebase is clean or not. You'll also learn some best practices and conventions you can follow to make your code cleaner.
所以在这篇文章中,我们将会讨论“代码整洁”指的是什么,它为什么这么重要,我们如何评估一个代码库整洁与否。同时你也会学会一些你能一起做的最佳实践和惯例,从而让你的代码更加整洁。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同时你也会学习一些你能遵循的最佳实践和惯例,让你的代码更加整洁。


Also, when code is easy to maintain, it ensures that the codebase can be improved and updated over time. This is especially important for long-term projects where code must be maintained and updated for years to come.
并且,代码易于维护也就保证了,即使随着时间的推移,代码库也能不断提高和更新。这对于长期项目来说十分重要,尤其是代码在未来几年需要不断更新和维护的时候。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当代码是易于维护的,随着时间的推移,代码库也能不断提高和更新。


## Effectiveness, Efficiency and Simplicity
<h2 id="tips-and-conventions-to-write-cleaner-code">写出cleaner code的一些技巧和惯例</h2>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

让代码更整洁的技巧和惯例


To expand upon efficiency, here are two examples of a function that calculates the sum of all numbers in an array.
为了评估这一点,算法复杂度是一个你应该注意的事情。如果你对这个词不熟悉,你可以去我写的[这一篇文章](https://www.freecodecamp.org/news/introduction-to-algorithms-with-javascript-examples/#algorithmic-complexity)看一下。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这篇文章有中文版


Both work and are just fine, but we should aim to always use the same syntax for similar operations, as it becomes more even and readable along the codebase.
两个都可以顺利的实现功能,但是我们在相似的操作中应该总是使用相似的操作,这样的话可以使得代码库更加的可读,且代码量也更加的均匀。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们应该力求在类似的操作中始终使用相同的语法。


Here are two examples of JavaScript code that perform the same task, one with a clear flow of execution, and the other with spaghetti code:
下面是执行相同任务的两个 JavaScript 代码示例,一个执行流程清晰,另一个代码很杂乱:

```javascript
// Example 1: Clear flow of execution
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

示例 1:清晰的执行流程
(注释也需要翻译哦)

- [简洁VS清晰](###conciseness-versus-clarity)
- [复用性](###re-usability)
- [清晰的执行流程](###clear-flow-of-execution)
- [单一制责原则](###single-responsibility-principle)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

单一职责原则


If you'd like to know how to implement this in JavaScript using modules, [check out this other article of mine](https://www.freecodecamp.org/news/modules-in-javascript/).
如果您想知道如何使用模块在 JavaScript 中实现这一点,[查看我的另一篇文章](https://www.freecodecamp.org/news/modules-in-javascript/)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文章有中文版


If you're interested in learning more about this, [in this article I wrote about software architecture](https://www.freecodecamp.org/news/an-introduction-to-software-architecture-patterns/#different-folder-structures-to-know) I expanded upon the topic of folder structures and well-known patterns you can follow.
如果您有兴趣了解更多相关信息,[在本文中我写了关于软件架构的文章](https://www.freecodecamp.org/news/an-introduction-to-software-architecture-patterns/#different-folder -structures-to-know)我扩展了文件夹结构和您可以遵循的众所周知的模式的主题。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文章有中文版

@miyaliu666
Copy link
Member

译文整体很棒,谢谢 @songyp0505 细心翻译这份手册。我提了些建议,在发布时修改啦:)

@miyaliu666 miyaliu666 merged commit 6636f57 into freeCodeCamp:main May 31, 2023
1 check passed
@miyaliu666 miyaliu666 added Published 已发布 and removed Review-awaiting 待校对 labels May 31, 2023
@songyp0505
Copy link
Contributor Author

译文整体很棒,谢谢 @songyp0505 细心翻译这份手册。我提了些建议,在发布时修改啦:)

看完修改建议啦,下次注意注释的问题,还有一些语序通顺的问题也会注意的😬谢谢miya姐

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Published 已发布
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Auto](如何写出整洁的代码 - 技巧与实践)
2 participants