Improve code readability by simplifying complex conditional expressions and control flow structures. Factor out repeated boolean expressions from nested conditions, use early returns instead of result variables when possible, and consolidate related conditional blocks.
Improve code readability by simplifying complex conditional expressions and control flow structures. Factor out repeated boolean expressions from nested conditions, use early returns instead of result variables when possible, and consolidate related conditional blocks.
Key practices:
Example of factoring out boolean expressions:
// Instead of:
if ((!is_empty && ts_node_end_byte(node) <= self->start_byte) ||
(!is_empty && point_lte(ts_node_end_point(node), self->start_point)))
// Use:
if (!is_empty && (
ts_node_end_byte(node) <= self->start_byte ||
point_lte(ts_node_end_point(node), self->start_point)))
Example of consolidating conditionals:
// Instead of separate error checks:
if (e == PARENT_DONE) {
cleanup();
return TSQueryErrorSyntax;
}
if (e) {
cleanup();
return e;
}
// Use unified approach:
if (e) {
cleanup();
if (e == PARENT_DONE) e = TSQueryErrorSyntax;
return e;
}
Enter the URL of a public GitHub repository