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 揭示動畫