Refactoring#
"code smells"#
Commented code, dead code#
- Remove and commit.
Useless comments#
- Remove and commit.
Express yourself in code rather than comments#
Duplication#
- Extract function, test and commit.
Excessive nesting & magic numbers#
-
Remove the try-catch in
Analyse.m
, test, commit. -
Remove one level of nesting in the main loop of
Analyse.m
, by continuing the loop if short reaction time, test, commit. -
Create a constant, test and commit.
for i=1:NbTrials
% Skips trials where answer came with impossible reaction time
% (negative or before the beginning of the movie)
if TotalTrials{1,1}(i,6)>0.5
% rest of the code
end
end
REACTION_TIME_THRESHOLD_SEC = 0.5;
for i=1:NbTrials
reaction_time_sec = TotalTrials{1,1}(i,6);
if reaction_time_sec <= REACTION_TIME_THRESHOLD_SEC
continue
end
% rest of the code
end
Long functions#
Split into smaller functions, test and commit.
- create at least one function to simply plot a figure
Code Metrics mh_metric
#
miss_hit can help you identify "code smells":
- long files
- complex functions
- too many nesting levels
- too many parameters in a function
mh_metric --ci