X Xerobit

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,...

Mian Ali Khalid · · 6 min read
Use the tool
Case Converter
Convert text between camelCase, PascalCase, snake_case, kebab-case, SCREAMING_CASE, Title Case, sentence case, and more. Bulk mode.
Open Case Converter →

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

LanguageVariablesFunctionsClassesConstantsFiles
JavaScriptcamelCasecamelCasePascalCaseUPPER_SNAKEkebab-case
TypeScriptcamelCasecamelCasePascalCaseUPPER_SNAKEkebab-case
Pythonsnake_casesnake_casePascalCaseUPPER_SNAKEsnake_case
JavacamelCasecamelCasePascalCaseUPPER_SNAKEPascalCase
C#camelCasePascalCasePascalCasePascalCasePascalCase
GocamelCasecamelCasePascalCasePascalCasesnake_case
Rustsnake_casesnake_casePascalCaseUPPER_SNAKEsnake_case
Rubysnake_casesnake_casePascalCaseUPPER_SNAKEsnake_case
PHPcamelCasecamelCasePascalCaseUPPER_SNAKEPascalCase

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 posts

Related tool

Case Converter

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.