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:
// Poor: Function returns true for zero values too
bool IsPositive(const HloInstruction* hlo)
// Better: Name accurately describes behavior
bool IsNonNegative(const HloInstruction* hlo)
// 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:
// 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>();
// Poor: Abbreviated form
bool merge_h_to_d_stream = true;
// Better: Fully descriptive
bool merge_host_to_device_stream = true;
Consistency:
thisIsTheFunctionName()
empty_lines
not emptyLines
These naming practices improve readability, maintainability, and reduce bugs caused by misunderstandings about code behavior.
Enter the URL of a public GitHub repository