Prompt
Choose names that are both semantically precise and follow consistent conventions. Names should accurately reflect behavior and purpose while adhering to established patterns in the codebase.
Function naming:
- Boolean functions should clearly indicate their predicate meaning
// Poor: Function returns true for zero values too bool IsPositive(const HloInstruction* hlo) // Better: Name accurately describes behavior bool IsNonNegative(const HloInstruction* hlo) - If a function extracts or returns more than a boolean, the name should reflect this
// Poor: Name suggests it only returns true/false bool IsShapedUint8Type(OpBuilder& builder, const Type type, Type& rescaled_type) // Better: Name indicates it extracts information bool ExtractUint8TypeInfo(OpBuilder& builder, const ShapedType type, Type& rescaled_type)
Variable naming:
- Use descriptive names that indicate purpose rather than implementation
// Poor: Technical implementation detail auto a0_pad_const_op = rewriter.create<tosa::ConstOp>(); // Better: Role-based description auto padding_const_op = rewriter.create<tosa::ConstOp>(); - Prefer full words over abbreviations for clarity
// Poor: Abbreviated form bool merge_h_to_d_stream = true; // Better: Fully descriptive bool merge_host_to_device_stream = true;
Consistency:
- Follow established casing conventions:
- Use camelCase for helper functions:
thisIsTheFunctionName() - Use snake_case for variables:
empty_linesnotemptyLines - Be consistent with compound terms: “LiteRt” not “LiteRT”
- Use camelCase for helper functions:
- Maintain consistent naming styles within related components to improve API cohesion
These naming practices improve readability, maintainability, and reduce bugs caused by misunderstandings about code behavior.