Skip to content

Commit 3fb6776

Browse files
authored
Make readability-function-cognitive-complexity threshold more strict (#365)
Functions with scores beyond 15 are typically flagged as potentially problematic. Empirical evidence suggests that such functions are more likely to correlate with higher error rates or maintenance challenges. It becomes increasingly hard for developers to follow the control flow, and these functions are prime candidates for refactoring into simpler, more modular parts.
1 parent 7e9c38d commit 3fb6776

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

Diff for: .clang-tidy

+2-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ CheckOptions:
8585
value: lower_case
8686
- key: readability-identifier-naming.IgnoreMainLikeFunctions
8787
value: 1
88+
# Functions with scores beyond 15 are typically flagged as potentially problematic (empirically)
8889
- key: readability-function-cognitive-complexity.Threshold
89-
value: 25 # default: 25
90+
value: 15 # default: 25
9091
- key: misc-include-cleaner.IgnoreHeaders
9192
value: '(opencv2/.*|__chrono/.*)'

Diff for: tasks/mpi/example/src/ops_mpi.cpp

+10-13
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,22 @@ bool nesterov_a_test_task_mpi::TestTaskMPI::ValidationImpl() {
2727
bool nesterov_a_test_task_mpi::TestTaskMPI::RunImpl() {
2828
int rank = -1;
2929
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30-
if (rank == 0) {
31-
// Multiply matrices
30+
31+
auto multiply = [this](bool row_major) {
3232
for (int i = 0; i < rc_size_; ++i) {
3333
for (int j = 0; j < rc_size_; ++j) {
34+
int sum = 0;
3435
for (int k = 0; k < rc_size_; ++k) {
35-
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
36-
}
37-
}
38-
}
39-
} else {
40-
// Multiply matrices
41-
for (int j = 0; j < rc_size_; ++j) {
42-
for (int k = 0; k < rc_size_; ++k) {
43-
for (int i = 0; i < rc_size_; ++i) {
44-
output_[(i * rc_size_) + j] += input_[(i * rc_size_) + k] * input_[(k * rc_size_) + j];
36+
int a = input_[(row_major ? i : k) * rc_size_ + (row_major ? k : i)];
37+
int b = input_[(row_major ? k : j) * rc_size_ + (row_major ? j : k)];
38+
sum += a * b;
4539
}
40+
output_[(i * rc_size_) + j] += sum;
4641
}
4742
}
48-
}
43+
};
44+
45+
multiply(rank == 0);
4946
MPI_Barrier(MPI_COMM_WORLD);
5047
return true;
5148
}

0 commit comments

Comments
 (0)