3 ms·
Good job !! Consistent coding convention :) As a constructive note, think about reversing your conditions (check if something NOT happened) and break huge chun
by lxfontes 14y ago
Good job !! Consistent coding convention :)
As a constructive note, think about reversing your conditions (check if something NOT happened) and break huge chunks of code into functions. This will guarantee a 'sane' amount of nested 'ifs' and improve code readability.
Ex:
for (int i = dn - 1; i >= 0; i--) {
if (!has_child(dlist[i]->d_name)) {
if ((fp = fopen(path, "r")) != NULL) {
.............
} else {
slog(LOG_ERR, "Can't read %s: %m", path);
}
}
}
Notice how the error message is 20 lines far from the actual condition. You can rework that as:
if ((fp = fopen(path, "r")) != NULL) {
do_some_work_with(fp);
} else {
slog(LOG_ERR, "Can't read %s: %m", path);
}
or
if (!(fp = fopen(path, "r")) {
slog(LOG_ERR, "Can't read %s: %m", path);
continue;
}
//removed 1 nesting level
........