تکنیک های نامگذاری متغیر

Summarize this content to 400 words in Persian Lang در توسعه نرم افزار، قراردادهای نامگذاری متغیرها برای خوانایی، قابلیت نگهداری و سازگاری کد بسیار مهم هستند. بسته به زبان، شیوههای توسعه یا قراردادهای تیم، رویکردهای متفاوتی وجود دارد. در اینجا رایج ترین انواع قراردادهای نامگذاری متغیرها آورده شده است:
کیف شتر (CamelCase)
Common in: JavaScript, Java, Swift, TypeScript
Format: First word in lowercase, subsequent words are capitalized.
Example: orderStatus, customerName, totalPrice
جلد پاسکال (PascalCase)
Common in: C#, .NET, TypeScript (for classes, enums)
Format: Each word starts with an uppercase letter, including the first word.
Example: OrderStatus, CustomerName, TotalPrice
کیف مار (snake_case)
Common in: Python, Ruby, PHP, C
Format: Words are lowercase and separated by underscores.
Example: order_status, customer_name, total_price
کیسه کباب (کباب کیس)
Common in: URLs, some configurations, CSS class names
Format: Words are lowercase and separated by hyphens.
Example: order-status, customer-name, total-price
قاب مار بالایی (UPPER_SNAKE_CASE)
Common in: Constants, environment variables (in many languages like Python, C, Go)
Format: All uppercase letters with words separated by underscores.
Example: ORDER_STATUS, CUSTOMER_NAME, TOTAL_PRICE
نماد مجارستانی
Common in: Older C++, legacy systems (less common now)
Format: Variable names are prefixed with letters representing the variable type.
Example: strCustomerName (string), iTotalPrice (integer)
کیس جیغ مار
Common in: Environment variables, constants
Similar to snake case but all characters are uppercase, often used for constants or global variables.
Example: MAX_USER_COUNT, ENVIRONMENT_MODE
نامگذاری مبتنی بر اختصار
Common in: Small variable names or indexing operations
Format: Abbreviated form of the variable’s purpose.
Example: idx for index, cnt for count, msg for message
نامگذاری اختصاصی دامنه
Based on: Domain-driven design or business logic
Example: invoiceData, productCategory, shippingStatus
بهترین روش ها برای نام گذاری متغیرها:
Descriptive & Meaningful: Variables should represent their purpose. For example, instead of using x, use productPrice or orderCount.
Avoid Single Letters: Except for loop counters (e.g., i, j), avoid single-letter variable names.
Use Consistent Conventions: Choose one naming convention (like camelCase or snake_case) and use it consistently across the codebase.
Avoid Abbreviations: Unless they’re well-known, avoid abbreviations that can confuse others reading the code.
در توسعه نرم افزار، قراردادهای نامگذاری متغیرها برای خوانایی، قابلیت نگهداری و سازگاری کد بسیار مهم هستند. بسته به زبان، شیوههای توسعه یا قراردادهای تیم، رویکردهای متفاوتی وجود دارد. در اینجا رایج ترین انواع قراردادهای نامگذاری متغیرها آورده شده است:
کیف شتر (CamelCase)
Common in: JavaScript, Java, Swift, TypeScript
Format: First word in lowercase, subsequent words are capitalized.
Example: orderStatus, customerName, totalPrice
جلد پاسکال (PascalCase)
Common in: C#, .NET, TypeScript (for classes, enums)
Format: Each word starts with an uppercase letter, including the first word.
Example: OrderStatus, CustomerName, TotalPrice
کیف مار (snake_case)
Common in: Python, Ruby, PHP, C
Format: Words are lowercase and separated by underscores.
Example: order_status, customer_name, total_price
کیسه کباب (کباب کیس)
Common in: URLs, some configurations, CSS class names
Format: Words are lowercase and separated by hyphens.
Example: order-status, customer-name, total-price
قاب مار بالایی (UPPER_SNAKE_CASE)
Common in: Constants, environment variables (in many languages like Python, C, Go)
Format: All uppercase letters with words separated by underscores.
Example: ORDER_STATUS, CUSTOMER_NAME, TOTAL_PRICE
نماد مجارستانی
Common in: Older C++, legacy systems (less common now)
Format: Variable names are prefixed with letters representing the variable type.
Example: strCustomerName (string), iTotalPrice (integer)
کیس جیغ مار
Common in: Environment variables, constants
Similar to snake case but all characters are uppercase, often used for constants or global variables.
Example: MAX_USER_COUNT, ENVIRONMENT_MODE
نامگذاری مبتنی بر اختصار
Common in: Small variable names or indexing operations
Format: Abbreviated form of the variable’s purpose.
Example: idx for index, cnt for count, msg for message
نامگذاری اختصاصی دامنه
Based on: Domain-driven design or business logic
Example: invoiceData, productCategory, shippingStatus
بهترین روش ها برای نام گذاری متغیرها:
Descriptive & Meaningful: Variables should represent their purpose. For example, instead of using x, use productPrice or orderCount.
Avoid Single Letters: Except for loop counters (e.g., i, j), avoid single-letter variable names.
Use Consistent Conventions: Choose one naming convention (like camelCase or snake_case) and use it consistently across the codebase.
Avoid Abbreviations: Unless they're well-known, avoid abbreviations that can confuse others reading the code.