Skip to content

Instantly share code, notes, and snippets.

@hiepdqflame
Last active May 4, 2023 05:12
Show Gist options
  • Save hiepdqflame/6fe4d62f9cc4a54a3ae5109fa28fd822 to your computer and use it in GitHub Desktop.
Save hiepdqflame/6fe4d62f9cc4a54a3ae5109fa28fd822 to your computer and use it in GitHub Desktop.
Đặt tên biến

Đối với biến là số nguyên

Đặt ở dạng: numberOf hoặc Count. Ví dụ: numberOfTickets, ticketCount

Đối với số dấu phẩy động

Đặt ở dạng: Amount. ví dụ: rainfallAmount, moneyAmount.

Nếu đơn vị không rõ ràng thì thêm đơn vị ở cuối tên biết: withInCentimet, rainFallAmountInInchesPerHourse, angleInDegrees, failPercent, failRatio.

Đối với biến boolean

Boolen sẽ có hai giá trị là true và false. Sẽ đặt theo các mẫu sau: isSomething, hasSomething, doesSomething, didSomething, shouldDoSomething hoặc willDoSomething, isDisabled, hasErrors, allowsWhitespace, didUpdate, shouldUpdate, willUpdate

Đối với string

Đặt ở dạng String hoặc AsString

Đối với list

Đặt ở dạng s hoặc List. Một số ví dụ: customers, errors, tasks, queueOfTask, stackOfCards, orderedSetOfTimestamps

Đối với object

Chú ý đặt danh từ, ví dụ: person, account, task

Đặt tên hàm

Đặt ở dạng handle, ví dụ: handleClickLogin, ...

Tham số truyền vào thêm tiền tố new để tránh shadow. Ví dụ:

person(newName,newAddress) {}

Đặt hằng số

Chữ hoa và cách nhau bởi _. Ví dụ: TOOLTIP_SHOW_DELAY_IN_MILLISECS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment