Skip to content

Commit

Permalink
coco
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Sep 24, 2023
1 parent 37d1b72 commit 9f32c61
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 2 deletions.
4 changes: 4 additions & 0 deletions 03-cognitive-complexity/.latexmkrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$pdflatex = 'pdflatex %O -interaction=errorstopmode -halt-on-error --shell-escape %S';
$latex = 'latex %O -interaction=errorstopmode -halt-on-error --shell-escape %S';
$clean_ext = 'crumbs';
$success_cmd = 'texqc && texsc';
3 changes: 3 additions & 0 deletions 03-cognitive-complexity/.texqc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--ignore=You have requested document class
--ignore=You have requested package
--verbose
8 changes: 8 additions & 0 deletions 03-cognitive-complexity/.texsc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--pws=../aspell.en.pws
--ignore=href,ffcode
--ignore=ff,nospell,citet,citep
--ignore=pptPic:pp
--ignore=pptQuote:p
--ignore=pptQuote:p
--ignore=pptSnippet:p
--ignore=innoBook:p
70 changes: 70 additions & 0 deletions 03-cognitive-complexity/03-cognitive-complexity.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
% (The MIT License)
%
% Copyright (c) 2023 Yegor Bugayenko
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
% of this software and associated documentation files (the 'Software'), to deal
% in the Software without restriction, including without limitation the rights
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
% copies of the Software, and to permit persons to whom the Software is
% furnished to do so, subject to the following conditions:
%
% The above copyright notice and this permission notice shall be included in all
% copies or substantial portions of the Software.
%
% THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
% SOFTWARE.

\documentclass{article}
\usepackage{../sqm}
\newcommand*\thetitle{Cognitive Complexity}
\begin{document}

\plush{\sqmTitlePage{3}}

\thought{Cyclomatic complexity is highly inaccurate if being compared with code readability evaluated by a human.}

\pitch{\pptQuote{ann-campbell.jpg}{A guiding principle in the formulation of Cognitive Complexity has been that it should incent good coding practices. That is, it should either ignore or discount features that make code more readable}{G. Ann Campbell, Sonar Source S.A., 2017}}

\pitch{
\pptBanner{Cyclomatic Complexity (CoCo)}
\pptPic{.9}{motive-before.png}\par
``The mathematical model underlying Cyclomatic Complexity gives these two
methods equal weight, yet it is intuitively obvious that the control flow of
\ff{sumOfPrimes} is more difficult to understand than that of \ff{getWords}'' --- G. Ann Campbell}

\pitch{
\pptBanner{Cognitive Complexity}
\pptPic{.9}{motive-after.png}\par
``The Cognitive Complexity algorithm gives these two methods markedly different
scores, ones that are far more reflective of their relative understandability.'' --- G. Ann Campbell}

\pitch{
``Being able to find statistical correlations between code understandability and source code measures would be greatly beneficial for the software development process, which involves a great deal of activities involving program comprehension'' --- \textit{An Empirical Evaluation of the ``Cognitive Complexity'' Measure as a Predictor of Code Understandability}, Journal of Systems and Software (197), 2023.}

\pitch{CoCo is supported in a few static analyzers:
\begin{itemize}
\item in PMD \href{https://pmd.github.io/pmd/pmd_rules_apex_design.html}{since 6.22.0}
\item in Rubocop \href{https://www.rubydoc.info/gems/rubocop/RuboCop/Cop/Metrics/PerceivedComplexity}{since 0.25} (called ``perceived complexity'')
\item in ESLint via \href{https://github.com/SonarSource/eslint-plugin-sonarjs/blob/master/docs/rules/cognitive-complexity.md}{SonarSource plugin}
\item in Flake8 via \href{https://github.com/Melevir/flake8-cognitive-complexity}{this plugin}
\item in Clippy \href{https://rust-lang.github.io/rust-clippy/master/\#/cognitive_complexity}{since 1.35.0}
\item in PHPCS via \href{https://github.com/Rarst/phpcs-cognitive-complexity}{this plugin}
\end{itemize}}

\thought{``Perceived complexity'' is human's impression and conceptualization of a system as being complex.}

\pitch{``\emph{Social code analysis} enriches our understanding of the code quality by overlaying a \emph{developer's behavior} with the \emph{structural analysis} of the code'' --- \href{https://www.thoughtworks.com/en-de/radar/techniques/social-code-analysis}{Technology Radar} of ThoughtWorks, March 2017}

\plush{
\pptBanner{Read this:}\par
\href{https://dl.acm.org/doi/abs/10.1145/3194164.3194186}{Cognitive complexity: an overview and evaluation}, G. Ann Campbell, Proceedings of the International Conference on Technical Debt, 2018\par
\href{https://dl.acm.org/doi/abs/10.1145/3460348}{Neural Software Analysis} by Michael Pradel et al., Communications of the ACM 65(1), 2022\par
}

\end{document}
Binary file added 03-cognitive-complexity/ann-campbell.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 03-cognitive-complexity/motive-after.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 03-cognitive-complexity/motive-before.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,16 @@ SLoC
Cyclomatic
McCabe
cyclomatic
Graylin
Graylin
incent
getWords
sumOfPrimes
understandability
CoCo
PHPCS
Clippy
SonarSource
ESLint
Rubocop
Pradel
ThoughtWorks
2 changes: 2 additions & 0 deletions sqm.sty
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
\plush{\pptThought{\raggedright\textcolor{orange}{\Huge\thethght.} #1}}
}

\newcommand\pitch[1]{\plush{\begin{pptMiddle} #1 \end{pptMiddle}}}

\newcommand\nospell[1]{#1}

\AtBeginDocument{%
Expand Down
2 changes: 1 addition & 1 deletion syllabus/syllabus.tex
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ \section{Лекции}
\setlength\itemsep{0em}
\item Lines of Code
\item McCabe's Cyclomatic Complexity
\item Perceived Complexity
\item Cognitive Complexity
\item Halstead Complexity
\item Coupling
\item GitHub stars
Expand Down

0 comments on commit 9f32c61

Please sign in to comment.