Use consistent and descriptive names for variables, components, and functions throughout the codebase. When the same concept appears in multiple places, use identical naming to prevent confusion and bugs. This includes:
Use consistent and descriptive names for variables, components, and functions throughout the codebase. When the same concept appears in multiple places, use identical naming to prevent confusion and bugs. This includes:
// Inconsistent (confusing):
const modelToProviderMap = useMemo(() => {
const modelProviderMap: Record<string, string> = {}; // Different name!
// ...
}, [apiKeys.data]);
// Consistent (clear):
const modelToProviderMap = useMemo(() => {
const modelToProviderMap: Record<string, string> = {}; // Same name
// ...
}, [apiKeys.data]);
// Misleading (no longer a dropdown):
export function DownloadDropdown({ /* ... */ }) {
// Renders a single button, not a dropdown
}
// Clear (matches functionality):
export function DownloadButton({ /* ... */ }) {
// Renders a single button
}
// Less clear:
const autoLocked = useState<boolean>(isExistingWidget);
// More clear:
const isAutoLocked = useState<boolean>(isExistingWidget);
// Inconsistent:
totalTokens: props.observations.map(/* ... */)
// Consistent with other code:
totalUsage: props.observations.map(/* ... */)
// Incorrect:
export const PeakViewTraceDetail = ({ projectId }: { projectId: string }) => {
// Correct (matches file path and context):
export const PeekViewTraceDetail = ({ projectId }: { projectId: string }) => {
Consistent naming reduces cognitive load for developers, makes the codebase more maintainable, and helps prevent bugs caused by name confusion.
Enter the URL of a public GitHub repository