🌎
Go! Raymond
LinkedinGithub
  • 🤚Welcome!
  • 👨‍💻About Me
  • 🗒️Blog
    • Not just a technical blog
    • First Working Day After Leaving Trading Floor
  • 🇻🇳Work/Life in Saigon
    • Life in Saigon
      • 🪙胡志明市最佳換匯場所
      • 🥜五郡安東市場 | 伴手禮堅果類
      • 💸越南什麼東西便宜?
      • ☕胡志明工作咖啡廳
    • VN Market
      • 📒Vietnam Stock Market 101
      • 📈Major Equity Index
      • Market Research
        • 越南盾VND長期貶勢
  • 💻Technology
    • Data
      • Business Intelligence Platform
        • 📈Streamlit
          • Install and Create a Streamlit Project
      • 💾Storage | Database
        • How to install MySQL on your computer with Docker?
    • Docker
      • Docker Basic
    • Python
      • Speed up Python
        • Asynchronous
      • Clean Code in Python
        • 命名(Naming)
        • 寫法
    • Web Development
      • FastAPI
        • 建立API
        • 回傳HTML
      • RESTful API是什麼?
    • Office Automation
      • Word Template with Python
    • Task Automation
      • Rocketry
        • Example of historical stock price update (Rocketry)
      • Prefect
    • 💻How to build your own VPN server?
  • 🚀Startup
    • Y Combinator - Startup School
      • Should You Start A Startup?
  • 🌎Travel
    • 🏔️Himalaya, Nepal
      • 🗒️How to apply Nepal travel visa as Taiwanese?
      • 🏔️Annapurna Circuit Trek (ACT)
        • 🎒Equipments checklist
Powered by GitBook
On this page
  • 變數與函數(Variables and Functions)
  • 物件(Class)
  • 固定常數(Constants)
  1. Technology
  2. Python
  3. Clean Code in Python

命名(Naming)

變數與函數(Variables and Functions)

在做變數名稱命名時,應使用「小寫」且使用下底線分隔。

name = "Python"
job_title = "Software Engineer"
populated_countries_list = []
def get_data():
    pass

def calculate_tax_data():
    pass
# Wrong Way: id可能代表任何資料欄位的id,無法讓使用者快速了解
def get_user_info(id):
    db = get_db_connection()
    user = execute_query_for_user(id)
    return user
    
# Right Way: 直接告訴使用者這邊使用的是使用者id
def get_user_by(user_id):
    db = get_db_connection()
    user = execute_user_query(user_id)
    return user

物件(Class)

一般來說常用的模式會將個別單字的首字大寫(駝峰式大小寫Camel-Case)

class UserInformation:
    def __init__(self):
        pass

固定常數(Constants)

固定常數為專案中不大會去更新調整的變數,例如求解精確度,或是小數位數等,但仍保持調整空間。

TOTAL = 56
TIMEOUT = 6
MAX_OVERFLOW = 7

PreviousClean Code in PythonNext寫法

Last updated 1 year ago

💻