失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > android 揭示动画_如何使用意图揭示函数名称使代码更好

android 揭示动画_如何使用意图揭示函数名称使代码更好

时间:2023-09-10 17:49:24

相关推荐

android 揭示动画_如何使用意图揭示函数名称使代码更好

android 揭示动画

Discover Functional JavaScriptwas named one of thebest new Functional Programming books by BookAuthority!

“发现功能JavaScript”BookAuthority评为最佳新功能编程书籍之一

Code is a way to communicate with developers reading it. Functions with intention-revealing names are easier to read. We read the function name and can understand its purpose. The function name is our tool for expressing intent on a piece of code.

代码是与阅读代码的开发人员进行交流的一种方式。 具有意图揭示名称的功能更易于阅读。 我们阅读了函数名称,并可以理解其用途。 函数名称是我们表达代码意图的工具。

Let’s look at a list of operations done in a functional style with the use of anonymous functions.

让我们看一下使用匿名函数以功能样式完成的操作的列表 。

function getTodos(users){return todos.filter(todo => !pleted && todo.type === "RE").map(todo => ({title : todo.title,userName : users[todo.userId].name})).sort((todo1, todo2) => todo1.userName.localeCompare(todo2.userName));}

Now check the same functionality refactored using functions with intention-revealing names.

现在,检查使用具有意图公开名称的功能重构的相同功能。

function isTopPriority(todo){return !pleted && todo.type === "RE";}function ascByUserName(todo1, todo2){return todo1.userName.localeCompare(todo2.userName);}function getTodos(users){function toViewModel(todo){return {title : todo.title,userName : users[todo.userId].name}}return todos.filter(isTopPriority).map(toViewModel).sort(ascByUserName);}

Function names give clarity to the code. With a good function name, you just have to read the name — you don’t need to analyze its code to understand what it does.

函数名称使代码更清晰。 有了一个好的函数名,您只需要阅读名称即可—您无需分析其代码即可了解其功能。

It’s widely estimated that developers spend 70% of code maintenance time on reading to understand it.

据广泛估计,开发人员将70%的代码维护时间用于阅读以理解它。

Kyle Simpson in Functional-Light JavaScript

功能轻型JavaScript中的 Kyle Simpson

Discover Functional JavaScriptwas named one of thebest new Functional Programming books by BookAuthority!

发现功能JavaScript被称为BookAuthority最好的新功能编程书籍

For more on applying functional programming techniques in React take a look atFunctional React.

有关在React中应用函数式编程技术的更多信息,请查看Functional React

Learnfunctional React, in a project-based way, withFunctional Architecture with React and Redux.

通过带有React和Redux的功能架构,以基于项目的方式学习功能性React

Follow on Twitter

在Twitter上关注

翻译自: /news/how-to-make-your-code-better-with-intention-revealing-function-names-6c8b5271693e/

android 揭示动画

如果觉得《android 揭示动画_如何使用意图揭示函数名称使代码更好》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。