commit 548365d3b9a55bab7fafc5d91fda2dcc6219b5ef
parent 31a29f440c26126f12710df955d5acb9fc9eed24
Author: phoebos <ben@bvnf.space>
Date: Tue, 28 Sep 2021 14:01:48 +0100
README: add style note about assignments
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/README b/README
@@ -69,6 +69,17 @@ BEST: if (x) {
foo();
}
+* assignment should not take place inside an if block or similar, unless it is
+ particularly useful such as in an while block. Use a separate line.
+
+DO: fd = open("path", O_RDONLY);
+ if (fd == -1) {
+ ...
+NOT: if ((fd = open("path", O_RDONLY)) == -1) {
+ ...
+OK: while ((n = read(fd, buf, BUFSIZ) > 0) {
+ ...
+
* there should be spaces between elements in brackets, but not directly inside
the brackets. if in doubt, try to use spaces as you would under english
grammatical rules.