Naming
Why is Naming important ?
情境A
情境B
Target as a Team!!
To make the code review stuff more efficient
針對其提供之功能或代表的資料做預測的依據
How does Naming affect?
Naming Concepts
Don’t Make Me Think
在避免造成混淆的前提下,依循團隊的習慣,盡可能精簡地命名
混淆 v.s. 精簡-Influence scope
tree
Naming Domain-Just like file path
Problem Domain
Solution Domain
What may bad Naming Domain cause
Container v.s. Component
Rest room
Living room
Bedroom
RelatedRecommandMainBlock
RelatedRecommand - Problem Domain
=> suggestion || Recommandation
Main - Main ? Sub ?
=> Main
Block - Container for multiple different objects
=> Board
SuggestionDraggingCardBoard
Dragging feature?
Monster Names
function SimpleBeanFactoryAwareAspectInstanceFactory()
House Container
Function & Data
Normal sentence:Sub+Verb+Obj
Normal program sentence:
Sub is (Verb+Obj)
Data
:=
Function
Sub is Obj
Data
Data
Data
Function
=
return
=
Declared function
=
return
=
import
const product = getProduct();
// ...
// What is it 'new' for??
const newProduct = getNewProduct();
// ...
// What's the difference with 'newProduct'?
const returnProduct = getReturnProduct();
return returnProduct;
// api fetching by the 'fetch' verb
const initialProduct = fetchInitialProduct();
// ...
const productWithContent = getProductWithContent();
// ...
const validatedProduct = validateProduct();
return validatedProduct;
Some cautions and examples
1. Avoid Confusing Shorthands
// IT IS
function getUserAddress()
// NOT
function getUserAd()
2. Stop abusing Google translation!!
統一發票:taxIdNumber or VATNumber
Some kind of invoice???
3. Check your spelling
4. Name it meaningfully
// What's the difference between them?
const productInfo, productData, productContent
ticketByLanguage
5. Constants
// Not that clear
const profit = Math.round(totalCost * (1 - 0.05));
// Better
const TAX_RATE = 0.05;
const profit = Math.round(totalCost * (1 - TAX_RATE));
6. Avoid small difference alphabet
1l O0
// Use them with pronounceable names
programO, program0
7. 主動、被動、未來式、過去式
References
deck
By ian Lai
deck
- 321