make your code base a home base
styling C99 for editability
avoiding syntactic special cases
i like being able to easily delete lines and swap lines without having to think about C's syntax;
one useful family of tricks involves avoiding "syntactic special cases" -- basically, the first and last of something should be styled just like the things in the middle
i initialize structs with a trailing comma:
{
a,
b,
c,
}
i sometimes write an else-if ladder with a leading if (0) block (recall 0 is false):
if (0) {
} else if (...) {
...
} else if (...) {
...
} else if (...) {
...
}
here's how i write long AND chains (recall 1 is true):
(1
&& ...
&& ...
&& ...
)
and OR chains:
(0
|| ...
|| ...
|| ...
)
here's a snippet of real code from Conversation's source
B32 is_prinicipal_frame = (1
&& R32_is_zero(part_projection->signed_distance_to_feature_plane)
&& geom3d_vector_has_unit_length(part_projection->normal)
&& R32_are_equal(1.0F, vec3_max(part_projection->normal))
);
if (0
|| !part_projection->is_active
|| !is_prinicipal_frame
) {
...
}
and here's another :)
Void gui2_separator(
Axis split_axis,
String prev_sibling_string,
String next_sibling_string
) {
GUIBox *separator = gui_tracked_box(
"%S_separator_%S",
prev_sibling_string,
next_sibling_string
);
separator->flags = (0
| GUIBoxFlagRenderFill
| GUIBoxFlagLeftClickable
| GUIBoxFlagIsASeparator
);
...
}
it's a shame HolyC didn't catch on, because i think it allowed you to include a trailing comma in function calls and that would have been siiick