Programming Naming Conventions — camelCase, PascalCase, snake_case by Language
Different programming languages have different naming convention standards. Here's the official naming convention for variables, functions, classes, and files in JavaScript,...
Naming conventions make code readable and predictable. Each language has an official or community-standard style guide. Mixing conventions in a single codebase creates friction — here’s what each language expects.
Use the Case Converter to instantly convert identifiers between any naming convention.
Quick reference by language
| Language | Variables | Functions | Classes | Constants | Files |
|---|---|---|---|---|---|
| JavaScript | camelCase | camelCase | PascalCase | UPPER_SNAKE | kebab-case |
| TypeScript | camelCase | camelCase | PascalCase | UPPER_SNAKE | kebab-case |
| Python | snake_case | snake_case | PascalCase | UPPER_SNAKE | snake_case |
| Java | camelCase | camelCase | PascalCase | UPPER_SNAKE | PascalCase |
| C# | camelCase | PascalCase | PascalCase | PascalCase | PascalCase |
| Go | camelCase | camelCase | PascalCase | PascalCase | snake_case |
| Rust | snake_case | snake_case | PascalCase | UPPER_SNAKE | snake_case |
| Ruby | snake_case | snake_case | PascalCase | UPPER_SNAKE | snake_case |
| PHP | camelCase | camelCase | PascalCase | UPPER_SNAKE | PascalCase |
JavaScript / TypeScript
Based on the official ECMAScript style guide and the Google JavaScript Style Guide:
// Variables and functions: camelCase
const userName = 'Alice';
let isLoggedIn = false;
function getUserProfile(userId) { ... }
const calculateTotal = (items) => { ... };
// Classes: PascalCase
class UserAuthService {
constructor(private db: Database) {}
async authenticate(email: string, password: string) { ... }
}
// Constants: UPPER_SNAKE_CASE (or camelCase for const variables)
const MAX_RETRY_COUNT = 3;
const API_BASE_URL = 'https://api.example.com';
// TypeScript types/interfaces/enums: PascalCase
interface UserProfile { ... }
type ApiResponse<T> = { data: T; error: string | null };
enum UserRole { Admin, Editor, Viewer }
// Files: kebab-case
// user-profile.ts, auth-service.ts, api-client.ts
Python (PEP 8)
# Variables and functions: snake_case
user_name = 'Alice'
is_logged_in = False
def get_user_profile(user_id):
pass
def calculate_total(items, tax_rate=0.0):
pass
# Classes: PascalCase
class UserAuthService:
def __init__(self, db):
self.db = db
def authenticate(self, email, password):
pass
# Constants: UPPER_SNAKE_CASE
MAX_RETRY_COUNT = 3
API_BASE_URL = 'https://api.example.com'
# Private (prefix with _): still snake_case
def _internal_helper():
pass
class MyClass:
def __init__(self):
self._private_attr = None
self.__very_private = None # name-mangled
# Modules/files: snake_case
# user_profile.py, auth_service.py, api_client.py
Java
// Variables and methods: camelCase
String userName = "Alice";
boolean isLoggedIn = false;
public UserProfile getUserProfile(int userId) { ... }
private void calculateTotalPrice(List<Item> items) { ... }
// Classes and interfaces: PascalCase
public class UserAuthenticationService implements AuthService {
private final UserRepository userRepository;
public UserAuthenticationService(UserRepository repo) {
this.userRepository = repo;
}
}
// Constants: UPPER_SNAKE_CASE
public static final int MAX_RETRY_COUNT = 3;
public static final String API_BASE_URL = "https://api.example.com";
// Packages: all lowercase, dot-separated
// com.example.userservice, org.project.auth
// Files: match class name (PascalCase)
// UserAuthenticationService.java
C# (.NET)
C# is unusual — methods use PascalCase, not camelCase:
// Variables: camelCase (local) or _camelCase (private fields)
string userName = "Alice";
private readonly ILogger _logger;
private int _retryCount;
// Properties: PascalCase
public string FirstName { get; set; }
public int MaxRetryCount { get; set; }
// Methods: PascalCase (C# specific!)
public UserProfile GetUserProfile(int userId) { ... }
public async Task<bool> AuthenticateAsync(string email, string password) { ... }
// Classes: PascalCase
public class UserAuthenticationService : IAuthService { ... }
// Constants and readonly: PascalCase (not UPPER_SNAKE)
public const int MaxRetries = 3;
public static readonly string ApiBaseUrl = "https://api.example.com";
// Interfaces: IPascalCase (I prefix)
public interface IUserRepository { ... }
// Enums: PascalCase for type AND values
public enum UserRole { Admin, Editor, Viewer }
Go
Go has a unique convention: exported identifiers (public) start with uppercase; unexported (private) start with lowercase:
// Unexported (private): camelCase
var userName string
func getUserProfile(id int) User { ... }
// Exported (public): PascalCase
type UserProfile struct {
FirstName string
LastName string
Email string
}
func GetUserProfile(id int) (UserProfile, error) { ... }
// Constants: PascalCase (exported) or camelCase (unexported)
const MaxRetryCount = 3 // exported
const defaultTimeout = 30 // unexported
// Acronyms: all caps
type HTTPClient struct { ... }
func ParseURL(raw string) *URL { ... }
// NOT HttpClient, ParseUrl
// Files: snake_case
// user_profile.go, http_client.go
Rust
// Variables and functions: snake_case
let user_name = "Alice";
fn get_user_profile(user_id: u32) -> UserProfile { ... }
// Structs and enums: PascalCase
struct UserProfile {
first_name: String,
last_name: String,
}
enum UserRole {
Admin,
Editor,
Viewer,
}
// Traits: PascalCase
trait Authenticate {
fn authenticate(&self, credentials: &Credentials) -> bool;
}
// Constants: UPPER_SNAKE_CASE
const MAX_RETRY_COUNT: u32 = 3;
static API_BASE_URL: &str = "https://api.example.com";
// Macros: snake_case! (with exclamation)
// println!, vec!, assert_eq!
// Files/modules: snake_case
// user_profile.rs, auth_service.rs
Ruby
# Variables and methods: snake_case
user_name = 'Alice'
is_logged_in = false
def get_user_profile(user_id)
end
def calculate_total(items, tax_rate: 0.0)
end
# Classes and modules: PascalCase
class UserAuthenticationService
def initialize(db)
@db = db
end
private
def validate_credentials(email, password)
end
end
# Constants: UPPER_SNAKE_CASE
MAX_RETRY_COUNT = 3
API_BASE_URL = 'https://api.example.com'
# Symbols: snake_case
:user_name, :is_active, :created_at
# Files: snake_case
# user_profile.rb, auth_service.rb
Why conventions matter
Consistent naming lets you instantly tell what something is:
// You can infer the type/usage from the name alone:
UserProfile // A class
userProfile // A variable/instance
getUserProfile // A function
USER_PROFILE // A constant
user-profile // A CSS class or URL
user_profile // A Python variable or SQL column
Code reviewers and linters (ESLint, Pylint, Checkstyle) enforce conventions automatically — mixing styles triggers warnings.
Related tools
- Case Converter — convert between all naming conventions
- camelCase vs snake_case Guide — detailed comparison
- PascalCase Guide — classes and types
Related posts
- camelCase — What It Is and Where to Use It in Programming — camelCase capitalizes the first letter of each word except the first: helloWorld…
- camelCase vs snake_case — Which Naming Convention to Use and When — camelCase and snake_case are the two dominant naming conventions in programming.…
- Kebab Case — What It Is and Where to Use kebab-case — Kebab case uses hyphens between lowercase words: hello-world, user-first-name. I…
- PascalCase — What It Is and Where to Use It in Code — PascalCase capitalizes the first letter of every word with no separators: HelloW…
- Snake Case — What It Is, When to Use It, and How to Convert — Snake case uses underscores between words in lowercase: hello_world, user_first_…
Related tool
Convert text between camelCase, PascalCase, snake_case, kebab-case, SCREAMING_CASE, Title Case, sentence case, and more. Bulk mode.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.