android 揭示动画
Discover Functional JavaScript was named one of the best 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 => !todo.completed && 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 !todo.completed && 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 JavaScript was named one of the best new Functional Programming books by BookAuthority!
发现功能JavaScript被称为 BookAuthority最好的新功能编程书籍 !
For more on applying functional programming techniques in React take a look at Functional React.
有关在React中应用函数式编程技术的更多信息,请查看 Functional React 。
Learn functional React, in a project-based way, with Functional Architecture with React and Redux.
通过带有React和Redux的功能架构 ,以基于项目的方式学习功能性React 。
Follow on Twitter
在Twitter上关注
翻译自: https://www.freecodecamp.org/news/how-to-make-your-code-better-with-intention-revealing-function-names-6c8b5271693e/
android 揭示动画