cleancode.in

Naming conventions by language

How 9 languages write the names of types, functions, variables and constants, each from its own guide. Then how to choose the words themselves.

What does my name look like in each case?

  • camelCaseshoppingCartTotal
  • PascalCaseShoppingCartTotal
  • snake_caseshopping_cart_total
  • SCREAMING_SNAKE_CASESHOPPING_CART_TOTAL
  • kebab-caseshopping-cart-total

How does each language write its names?

LanguageTypesFunctionsVariablesConstants
Python sourceShoppingCartadd_itemitem_countMAX_ITEMS
Java sourceShoppingCartaddItemitemCountMAX_ITEMS
JavaScript sourceShoppingCartaddItemitemCountnot set
C# sourceShoppingCartAddItemitemCountMaxItems
Go sourceShoppingCartaddItemitemCountmaxItems
Rust sourceShoppingCartadd_itemitem_countMAX_ITEMS
Kotlin sourceShoppingCartaddItemitemCountMAX_ITEMS
Dart sourceShoppingCartaddItemitemCountmaxItems
SAP ABAP sourceshopping_cartadd_itemitem_countmax_items

What does the table leave out?

  • C# fields: private ones start with an underscore, _itemCount source.
  • Go: case is visibility. ShoppingCart is seen outside its package, addItem is not source.

How do I choose a good name?

  • Say what it holds: elapsed_days, not d; one letter only for a throwaway counter source.
  • Say what it does: a function is a verb, send_invoice source.
  • Ask yes or no: is_paid, has_stock.

What should a name leave out?

  • Empty words: Manager, Data, Info say nothing source.
  • No type tags: customers, not lt_customers source.
  • Spell it out: abbreviations only when everyone knows them source.

Which case is which?

  • camelCase: first word lowercase: itemCount.
  • PascalCase: every word capitalised; PEP 8 says CapWords source, Rust UpperCamelCase source.
  • snake_case: lowercase, joined by underscores: item_count.
  • SCREAMING_SNAKE_CASE: the same in capitals, for constants.