-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCleanCode.tex
1454 lines (1406 loc) · 68.3 KB
/
CleanCode.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[14pt,usenames,dvipsnames,svgnames]{beamer}
\usepackage[english]{babel}
\usepackage[misc]{ifsym}
\usepackage{fontspec,mathabx,multicol,listings,comment,fontawesome,pgfornament}
\usepackage[compat=0.2]{TeXnicalities}
\usetikzlibrary{shapes}
\setsansfont{Yanone Kaffeesatz}[
UprightFont = *-Regular ,
BoldFont = *-Bold ,
BoldItalicFont = *-Bold ,
BoldSlantedFont = *-Bold ,
ItalicFont = *-Light ,
SlantedFont = *-Light ,
SmallCapsFont = *-Thin
]
\graphicspath{{Figures/}}
\input{ListingsSetup}
\input{PieTikz}
%Tikz
\tikzset{
%Hexagons
hexagon/.style n args={3}{double arrow, double arrow head extend=0cm, inner sep=3pt, draw=#1, fill=#2, text=#3, thick},
hexagon/.default={black}{gray!20}{black},
hexagonOne/.style={hexagon={#1}{#1!30}{#1}},
hexagonTwo/.style 2 args={hexagon={#1}{#1!#2}{#1}},
hexagonThree/.style n args={3}{hexagon={#1}{#1!#2}{#3}},
hexagonShade/.style n args={3}{double arrow, double arrow head extend=0cm, inner sep=3pt, thick, draw=#1, left color=#2, right color=#3},
%General text element
Shape/.style n args={3}{draw=#1, fill=#2, text=#3},
genShape/.style 2 args={#1, inner sep=3pt, draw=#2, fill=#2!20, text=#2, thick},
halo/.style={preaction={draw, #1, line width=7, -}},
}
%My commands
\newcommand<>{\tc}[2]{\textcolor#3{#1}{#2}}
\newcommand{\myCopyright}{\raisebox{-7pt}{\large\copyright}}
\makeatletter
\patchcmd{\beamer@sectionintoc}
{\vfill}
{\vskip2ex}
{}
{}
\makeatother
\mode<presentation>
{
\usetheme{Z02}
\defbeamertemplate{footline}{Empty}{}
\setbeamersize{text margin left=5mm,text margin right=5mm}
}
%Append code to put more information on titlepage
\appto\titlepage{%
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=south, inner ysep=4pt] at ($(current page.south)!0.58!(current page.south east)+(0mm,1mm)$)
{\includegraphics[width=13mm]{LogoPUNCH}};
\node[anchor=south, inner ysep=0pt] (license) at ($(current page.south)+(0mm,4mm)$)
{\includegraphics[width=10mm]{CC-BY}};
\node[anchor=south, font=\small, text=BGLIGHT]
(Axel) at (license.north) {\href{https://github.com/AxelKrypton}{\faGithub\,AxelKrypton}};
\end{tikzpicture}
}
%===============================================================%
\title{Clean code}
\subtitle{Good practices in general coding}
\author{~\\[-5mm]Alessandro Sciarra}
\institute{Z02~--~Software Development Center\\[1mm] {PUNCH Young Academy -- PUNCH4NFDI}}
\date{23-24 May 2024}
\titlegraphic{\includegraphics[width=16mm]{LogoCRC}}
\titlepagelogo{\includegraphics[width=26mm]{LogoGoethe}}
%===============================================================%
\AtBeginSection[] % <- Empty optional argument, do nothing for \section*
{
\begin{frame}[plain, noframenumbering]{}
\sectionpage
\end{frame}
}
\begin{document}
%===================================================================================================%
\begin{frame}[plain,noframenumbering]
\titlepage
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[plain,noframenumbering]{Prelude}
\vspace{-3mm}
\begin{varblock}{block example}[0.8\textwidth]{Leave me a feedback}
Was the talk clear, useful, inspiring?\\
Would you like to hear more on this/other topic? Which?\\
Any general comment? $\quad$
\tc{PP}{\href{mailto:[email protected]}{{\small\Letter}$\;$Alessandro}}
\end{varblock}
\vspace{3mm}
\PrepareURLsymbol[PT]
\begin{varblock}{block alerted}[0.8\textwidth]{Disclaimer}
\begin{enumerate}
\item Slides are quite full of text for later reading.
\item It is about common sense, exceptions might exist.
\item Let us discuss!
\end{enumerate}
\end{varblock}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[t,plain,noframenumbering]{Outline}
\hspace*{1cm}
\begin{minipage}[c][0.65\textheight]{\textwidth}
\begin{columns}[t]
\begin{column}{.45\textwidth}
\tableofcontents[sections={1-4}]
\end{column}
\begin{column}{.55\textwidth}
\tableofcontents[sections={5-}]
\end{column}
\end{columns}
\end{minipage}
\end{frame}
%===================================================================================================%
%===================================================================================================%
\section{Summary \& Conclusion}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}<1>[label=THM]{Take home message}
\vspace{-1mm}
\begin{varblock}{block example}[70mm]{Clean code}
What it is and why it is worth aiming at it
\end{varblock}
\vspace{1mm}
\begin{itemize}
\item The importance of meaningful names, comments and formatting
\item Strive to respect few very general rules (e.g. DRY, KISS, pathfinder)
\item Functions and classes: small, Single Responsibility and IOSP!
\item Test your code and keep your tests clean (F.I.R.S.T.)!
\end{itemize}
\vspace{2mm}
\begin{varblock}{}[0.94\textwidth]{}
\PB{Have a reason for everything you type $\to$ refactor, refactor, refactor!}
\end{varblock}
\begin{varblock}{block alerted}[0.88\textwidth]{The first \textbf{reader} of your code is \textbf{yourself}}
Try to minimise the time needed by a new reader to understand!
\end{varblock}
\begin{onlyenv}<2>
\begin{tikzpicture}[remember picture, overlay]
\node[draw=PB, rounded corners, anchor=north east, font=\tiny, inner sep=4pt] at ($(current page.north east)-(2mm,2mm)$) {DRY principle $\;\to\;$ \PB{\texttt{\textbackslash{}againframe\{<name>\}}}};
\end{tikzpicture}
\end{onlyenv}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{Tools of developer daily life}{\uncover<2->{Pick one tool from each category and know how to use it}}
\begin{varblock}{example}[0.84\textwidth]{Your toolkit should contain more than you might think!}
\small\PS{Not} just a compiler and a mentor (e.g. Google, Stack Exchange, textbook)
\end{varblock}
\uncover<2->{
\begin{itemize}
\setlength{\itemsep}{0.5ex}
\item \alert{Integrated Development Environment} (e.g. Visual Studio Code, Eclipse)
\item \alert{Tests support -- Build automation} (e.g. CMake)
\item \PB{Version control system} (e.g. Git) $\;\to\;$ GitHub, Redmine, GitLab, etc.
\item Profiler
\item Static analysis -- \PB{Formatter} (e.g. clang suite)
\item Different compilers
\item \textcolor{bg!80!normal text.fg}{Debugger} \Remark{Clean code does not require to be debugged!}
\end{itemize}
}
\end{frame}
%===================================================================================================%
%===================================================================================================%
\section{What are we aiming to?}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[plain,noframenumbering]{}
\begin{tikzpicture}[remember picture, overlay]
\node (O) at (current page.center) {\includegraphics[width=\textwidth]{WTF}};
\node[below = 0mm of O, font=\tiny] {\myCopyright\ 2008 Focus Shift};
\end{tikzpicture}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{}
\begin{overlayarea}{\textwidth}{\textheight}
\begin{varblock*}{quote}[0.85\textwidth]{Clean code}[Michael Feathers]
Clean code always looks like it was written by someone who cares.
There is nothing obvious that you can do to make it better.
[$\ldots$] if you try to imagine improvements, you're led back to where you are.
\end{varblock*}
\begin{onlyenv}<1>
\begin{varblock*}{quote}[0.85\textwidth]{}[Bjarne Stroustrup]
I like my code to be elegant and efficient [$\ldots$] clean code does one thing well.
\end{varblock*}
\begin{varblock*}{quote}[0.85\textwidth]{}[Grady Booch]
Clean code is simple and direct. [$\ldots$] Clean code reads like well-written prose.
\end{varblock*}
\begin{varblock*}{quote}[0.85\textwidth]{}[Ward Cunningham]
You know you are working on clean code when each routine you read turns out to be pretty much what you expected.
\end{varblock*}
\end{onlyenv}
\FrameRemark<1>{Inventor of the SOLID principle, of the C++ language, of the Booch method and of the Wiki, respectively (top to bottom).}
\begin{onlyenv}<2>
\vspace{3mm}
\begin{itemize}
\setlength{\itemindent}{6mm}
\item \alert{Readable}
\item \PQ{Maintainable}
\item Easy to extend\tikzmark{itemCenter}
\item Easy to use
\item Hard to break
\item \alert{Testable/Tested}
\item \ldots
\end{itemize}
\begin{tikzpicture}[remember picture, overlay]
\node[right = 2cm of itemCenter] (fig) {\includegraphics[height=35mm]{CleanCode.jpg}};
\PrepareURLsymbol[PP]
\node[below = 1mm of fig, font=\scriptsize, xshift=-2pt]
{\URL*{http://clean-code-developer.com/}{The Clean Code developer road}};
\node[below = 6mm of fig, font=\tiny] (progress) {
%\href{http://clean-code-developer.com/grades/grade-0-black/}{Black} $\,\to\,$
\PrepareURLsymbol[PQ]
\URL*{http://clean-code-developer.com/grades/grade-1-red/}{Red} $\,\to\,$
\PrepareURLsymbol[PT]
\URL*{http://clean-code-developer.com/grades/grade-2-orange/}{Orange} $\,\to\,$
\PrepareURLsymbol[Goldenrod]
\URL*{http://clean-code-developer.com/grades/grade-3-yellow/}{Yellow} $\,\to\,$
\PrepareURLsymbol[PS]
\URL*{http://clean-code-developer.com/grades/grade-4-green/}{Green} $\,\to\,$
\PrepareURLsymbol[PB]
\URL*{http://clean-code-developer.com/grades/grade-5-blue/}{Blue} $\,\to\,$
\PrepareURLsymbol[white]
\colorbox{PP}{\URL*{http://clean-code-developer.com/grades/grade-6-white/}{White}}
};
\path[to] (progress.359) edge[out=350, in=190, looseness=1.2] (progress.181);
\end{tikzpicture}
\end{onlyenv}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{We will develop the needed code sense!}
\begin{tikzpicture}[remember picture, overlay,
every node/.style={inner sep=0pt}, pgfornamentstyle/.style={color=PB}]
\def\ornsize{11mm}
\node[font=\large](Text) at ($(current page.north)!0.52!(current page.south)$) {%
\begin{tabular}{c}
A gut feeling is like a drill, a simple instrument\\
whose force lies in the quality of its material.\\[1mm]
{\normalsize---~Gerd Gigerenzer~---}
\end{tabular}
};
\node[shift={(-12mm,6mm)},anchor=north west] (CNW)
at (Text.north west) {\pgfornament[width=\ornsize]{61}};
\node[shift={(12mm,6mm)},anchor=north east] (CNE)
at (Text.north east) {\pgfornament[width=\ornsize,symmetry=v]{61}};
\node[shift={(-12mm,-5mm)},anchor=south west] (CSW)
at (Text.south west) {\pgfornament[width=\ornsize,symmetry=h]{61}};
\node[shift={(12mm,-5mm)},anchor=south east] (CSE)
at (Text.south east) {\pgfornament[width=\ornsize,symmetry=c]{61}};
\pgfornamentline{CNW.north east}{CNE.north west}{3}{88}
\pgfornamentline{CSW.south east}{CSE.south west}{3}{88}
\pgfornamentline{CNW.south west}{CSW.north west}{2}{88}
\pgfornamentline{CNE.south east}{CSE.north east}{2}{88}
\end{tikzpicture}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{Why do we need to care?}
\vspace{-8mm}
\begin{overlayarea}{\textwidth}{0.8\textheight}
\begin{onlyenv}<1>
\begin{center}
\vspace{5mm}\includegraphics[width=0.55\textwidth]{Readability.jpg}
\end{center}
\end{onlyenv}
\begin{uncoverenv}<3->
\begin{quoteblock}{The technical debt}[Wikipedia]
It is a concept that reflects the implied cost of additional rework caused
by choosing an easy solution now instead of using a better approach that would take longer.\\[-1ex]
\end{quoteblock}
\end{uncoverenv}
\begin{onlyenv}<2-3>
\begin{itemize}
\item We never write code for one \alert{time-invariant} reader!
\item Learning and applying \PP{few simple rules} increases quality of code base.
\item When a program is modified, its complexity will increase, provided that one does not actively work against this.
\end{itemize}
\end{onlyenv}
\vspace{-8mm}
\begin{onlyenv}<4->
\begin{center}
\begin{tikzpicture}[font=\footnotesize, node distance=9mm]
\coordinate (O) at (0,0);
\begin{scope}[scope on=<4->]
\node[thick, ellipse, Shape={PB}{PB!20}{PB}, text width=19mm, align=center, left = of O] (A) {Quick and dirty implementation};
\node[thick, ellipse, Shape={PP}{PP!20}{PP}, text width=18mm, align=center, above = of O] (B) {Technical debt increases};
\path[to] (A) edge[out=90, in=180] (B);
\end{scope}
\begin{scope}[scope on=<4-5>]
\node[thick, ellipse, Shape={PT}{PT!20}{PT}, text width=18mm, align=center, below = of O] (C) {Harder to add new features};
\path[to] (B) edge[out=0, in=0, looseness=1.26] (C) (C) edge[out=180, in=270] (A);
\end{scope}
\begin{scope}[scope on=<5>]
\node[starburst, starburst point height=15mm, minimum width=7cm, minimum height=5cm,
Shape={red}{yellow!50}{red}, line width=1.5pt, font=\Huge\ttfamily, rotate=10]
at (O) {BOOM};
\end{scope}
\begin{scope}[scope on=<6>]
\node (VC) at ([yshift=-3mm]O) {\includegraphics[height=0.6\textheight]{VisualizedCodebase}};
\end{scope}
\begin{scope}[scope on=<7>]
\node[thick, ellipse, Shape={PS}{PS!20}{PS}, text width=18mm, align=center, right = of O] (D) {Pay back technical debt};
\path[to] (B) edge[out=0, in=102] (D.86) (D.274) edge[out=265, in=270, looseness=0.6] (A);
\node[hexagon={red}{yellow!20}{red}, font=\small] (note) at ([yshift=-8mm]C) {Technical debt naturally tends to increase};
\end{scope}
\end{tikzpicture}
\end{center}
\end{onlyenv}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{As physicist, why having high quality code?}
\vspace{-1mm}
\begin{itemize}
\item It is plenty of problems which need to be approached numerically\\
$\quad\to\;$ Programming is one of the major tasks in physics!
\item Reproducibility should be a pillar of science\\
$\quad\to\;$ One of the main responsibilities of a scientist!
\item Lots of bad code around and passed on across generations\\
$\quad\to\;$ \PB{A huge amount of time is wasted, subtracted to research!}
\end{itemize}
\vspace{-1mm}
\begin{varblock}{alert}{It should not happen\ldots}
\guillemotleft{}Wow! There is definitely \alert{a new physics signal} in these data!\guillemotright\\
{\color{PB}\scriptsize\ldots{}few days/weeks/months/years later\ldots}\\[0.5ex]
\guillemotleft{}Oh, no! It was \alert{just a bug} in the code!\guillemotright
\end{varblock}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[c]{The starting point\ldots}
\uncover<2>{\centerline{\includegraphics[width=0.7\textwidth]{ButItRuns}}}
\end{frame}
%===================================================================================================%
%===================================================================================================%
\section{Meaningful names}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Use intention-revealing names}
\vspace{-2mm}
\begin{varblock}{block example}{\alt<1-2>{Why is it hard to tell what this code is doing?}{Good names are crucial for readability!}}
\begin{onlyenv}<1-2>
\begin{lstlisting}[style=MyCpp]
using std::vector<std::vector<int>> = myVecVec;
myVecVec FC(const myVecVec& b)
{
myVecVec list;
for(const std::vector<int>& c : b){
if(c[0] == 4)
list.push_back(c);
}
return list;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<3>
\begin{lstlisting}[style=MyCpp]
using std::vector<std::vector<int>> = myVecVec;
myVecVec getFlaggedCells(const myVecVec& gameBoard)
{
myVecVec flaggedCells;
for(const std::vector<int>& cell : gameBoard){
if(cell[STATUS_VALUE] == FLAGGED)
flaggedCells.push_back(cell);
}
return flaggedCells;
}
\end{lstlisting}
\end{onlyenv}
\begin{onlyenv}<4>
\begin{lstlisting}[style=MyCpp]
using std::vector<std::vector<int>> = SetOfCells;
SetOfCells getFlaggedCells(const SetOfCells& gameBoard)
{
SetOfCells flaggedCells;
for(const Cell& cell : gameBoard){
if(cell.isFlagged())
flaggedCells.push_back(cell);
}
return flaggedCells;
}
\end{lstlisting}
\end{onlyenv}
\end{varblock}
\begin{uncoverenv}<2->
\begin{itemize}
\setlength{\itemsep}{0mm}
\item What kind of object is contained in \alt<2>{\CPP|list|}{\CPP|flaggedCells|}?
\item What does \alt<2>{\PB{0}}{\CPP|STATUS_VALUE|} represent in the \CPP|if|-clause?
\item What does \alt<2>{\PB{4}}{\CPP|FLAGGED|} mean in the \CPP|if|-clause?
\item How would I use the object being returned?
\end{itemize}
\end{uncoverenv}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Use names which can be searched}
\vspace{-2mm}
\begin{overlayarea}{\textwidth}{\textheight}
\begin{varblock}{alert}[\textwidth]{Rule of thumb}
The length of a name should be chosen w.r.t. to the size of its scope
\end{varblock}
\begin{center}
\begin{minipage}{0.9\textwidth}
\begin{description}
\item[\textbf{Variables:}] Proportionally to their scope size
\item[\textbf{Functions:}] In inverse proportion to their scope (cf.\ C++ STL)
\end{description}
\end{minipage}
\end{center}
\vspace{1mm}
\begin{onlyenv}<1>
\begin{itemize}
\item Single-letter names \textbf{only} for local variables inside \textbf{short scopes}
\item Single-word names \textbf{a must} for functions in widely used \textbf{libraries}
\item IDE very good at renaming variables $\;\Rightarrow\;$ rename, rename, rename!
\end{itemize}
\end{onlyenv}
\vspace{-4mm}
\begin{varblock}{block example}{Something like this\ldots}<only@2>
\begin{lstlisting}[style=MyCpp]
for(int j = 0; j < 34; j++)
s += t[j]*4/5;
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[\textwidth]{\ldots{}or something like this?}<only@3>
\begin{lstlisting}[style=MyCpp]
const int realDaysPerIdealWeek = 4;
int totalRealWeeksNeeded = 0;
for(int j = 0; j < NUMBER_OF_TASKS; j++)
{
int realDaysPerTask = taskDaysEstimate[j] *
realDaysPerIdealWeek;
int realWeeksPerTask = realDaysPerTask/WORKING_DAYS_PER_WEEK;
totalRealWeeksNeeded += realWeeksPerTask;
}
\end{lstlisting}
\end{varblock}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Other important principles}
\vspace{-3mm}
\begin{itemize}
\setlength{\itemindent}{-3mm}
\item Avoid disinformation
\item \alert{Use pronounceable names} $\;\to\;$ \PS{\texttt{timestamp}} better than \PQ{\texttt{ymdhms}}
\item Avoid mental mapping
\item Pick \alert{one} word per concept $\;\to\;$\CPP|get|, \CPP|fetch|, \CPP|retrieve|, \CPP|obtain|
\item Do not be cute
\item \ldots
\end{itemize}
\vspace{-3mm}
\begin{varblock}{alert}[0.5\textwidth]{Take home lesson}
\textbf{Choose carefully every name!}\\[1mm]
$\downarrow$\\[1mm]
Rename when you find better ones!
\end{varblock}
\end{frame}
%===================================================================================================%
%===================================================================================================%
\section{Comments and Formatting}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{Do not comment bad code, rewrite it}
\vspace{-3mm}
\begin{onlyenv}<1>
\begin{tikzpicture}[remember picture, overlay,
every node/.style={inner sep=0pt}, pgfornamentstyle/.style={color=ALERT}]
\def\ornsize{11mm}
\node[font=\large](Text) at ($(current page.north)!0.52!(current page.south)$) {%
\begin{tabular}{c}
Comments are an \textbf{unfortunate necessity},\\
NOT a great achievement!\\[3mm]
{\normalsize---~Robert C. Martin~---}
\end{tabular}
};
\node[shift={(-12mm,6mm)},anchor=north west] (CNW)
at (Text.north west) {\pgfornament[width=\ornsize]{61}};
\node[shift={(12mm,6mm)},anchor=north east] (CNE)
at (Text.north east) {\pgfornament[width=\ornsize,symmetry=v]{61}};
\node[shift={(-12mm,-5mm)},anchor=south west] (CSW)
at (Text.south west) {\pgfornament[width=\ornsize,symmetry=h]{61}};
\node[shift={(12mm,-5mm)},anchor=south east] (CSE)
at (Text.south east) {\pgfornament[width=\ornsize,symmetry=c]{61}};
\pgfornamentline{CNW.north east}{CNE.north west}{3}{88}
\pgfornamentline{CSW.south east}{CSE.south west}{3}{88}
\pgfornamentline{CNW.south west}{CSW.north west}{2}{88}
\pgfornamentline{CNE.south east}{CSE.north east}{2}{88}
\end{tikzpicture}
\end{onlyenv}
\begin{onlyenv}<2>
\begin{quoteblock}{Avoid comments!}[R. C. Martin]
The proper use of comments is to compensate for our failure to express ourself in code.
Note that I used the word \alert{failure}. I meant it. Comments are always failures. [\ldots]
Why am I so down on comments? Because they lie. Not always, and not intentionally, but too often.
The older a comment is, and the farther away it is from the code it describes, the more likely
it is to be just plain wrong.
\end{quoteblock}
\begin{itemize}
\item To keep comments up-to-date costs energy and this energy should rather go into make the code clearer and more expressive!
\item Inaccurate comments are far worse than no comments!
\item \alert{Truth can only be found in one place: the code.}
\end{itemize}
\end{onlyenv}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Explain yourself in the code}
\vspace{-5mm}
\begin{varblock}{block example}[0.85\textwidth]{What you should strive to avoid\ldots}
\begin{lstlisting}[style=MyCpp]
Person e; // The employee we are considering
// Check if the employee is eligible for full benefits
if( (e.flags & HOURLY_FLAG) && e.age > 65 )
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.8\textwidth]{\ldots{}in favour of expressive code}<2->
\begin{lstlisting}[style=MyCpp]
Person employee;
if(employee.isEligibleForFullBenefits())
\end{lstlisting}
\end{varblock}
\begin{uncoverenv}<3>
\begin{itemize}
\item It is simple to come up with good ideas
\item It is often simply matter of creating a function whose name expresses the content of the comment!
\end{itemize}
\end{uncoverenv}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Good comments}{But try to limit them as much as possible!}
\begin{overlayarea}{\textwidth}{0.75\textheight}
\begin{onlyenv}<4->
\vspace{3mm}
\begin{itemize}
\item Informative comment
\item Explanation of intent, Clarification
\item<only@5-> Amplification
\item<only@6-> \PQ{TODO comments}{$\;$\scriptsize $\to\;$border line: really needed in a code? Do not check them in!\tikzmark{todoEnd}}
\item<only@6-> \PQ{Legal comments}{$\;$\scriptsize $\to\;$border line: not legally required \& overlap with version control.}
\end{itemize}
\begin{onlyenv}<6->
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north east] (TD) at ($(current page.north east)-(7mm,3mm)$) {\includegraphics[scale=0.07]{Todo}};
\path[thin, to] ($(TD.south)!0.5!(TD.south east)$) edge[out=270, in=0] (todoEnd);
\end{tikzpicture}
\end{onlyenv}
\end{onlyenv}
\begin{onlyenv}<1-3>
\vspace{-1mm}
\begin{varblock}{block example}[0.98\textwidth]{Informative comment}
\begin{lstlisting}[style=MyCpp]
// Format matched: hh:mm:ss dd Month yyyy
std::regex timePattern("(\\d{2}:){2}\\d{2}, \\d{2} \\S+ \\d{4}");
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.77\textwidth]{Explanation of intent}<uncover@2->
\begin{lstlisting}[style=MyCpp]
// Checking the residuum possibly not every
// iteration allows for speed up on GPUs
if(iterationNumber % CG_CHECK_RESIDUUM_EVERY == 0)
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.77\textwidth]{Clarification when using cryptic external API}<uncover@3>
\begin{lstlisting}[style=MyCpp]
// Check if root was found up to desired precision
if(gsl_fcmp(functionValue, 0.0, epsilon) == 0)
\end{lstlisting}
\end{varblock}
\end{onlyenv}
\begin{varblock}{block example}[0.99\textwidth]{Amplification}<only@4>
\begin{lstlisting}[style=MyCpp]
// See https://stackoverflow.com/a/1736040 for more information.
template<typename T>
std::string getDefaultForHelper(const T& number)
\end{lstlisting}
\end{varblock}
\vspace{-1mm}
\begin{varblock}{block example}[0.99\textwidth]{}<only@4>
\begin{lstlisting}[style=MyCpp]
// Removing trailing spaces is crucial since any would break the
// following algorithm. It might leave the string unchanged, but
// the absence of trailing spaces is at the moment not guaranteed!
boost::trim_right(keyToDecipher);
\end{lstlisting}
\end{varblock}
\begin{onlyenv}<5>
\begin{varblock}{block example}[0.98\textwidth]{TODO comments}
\begin{lstlisting}[style=MyCpp]
// TODO: The following two classes should be merged into one!
\end{lstlisting}
\end{varblock}
\vspace{-2mm}
\begin{varblock}{block example}[0.7\textwidth]{Legal comments}
\begin{lstlisting}[style=MyCpp]
/*******************************************
* Copyright (c) 2018 Alessandro Sciarra *
* *
* This file is part of BaHaMAS. *
*******************************************/
\end{lstlisting}
\end{varblock}
\end{onlyenv}
\vspace{-5mm}
\begin{varblock}{block alerted}[0.96\textwidth]{Automatic documentation comments}<6>
If you are writing a public API, then you should certainly provide a good documentation.
But be aware that documentation comments can be as misleading, misplaced and lying as any other comment.
\end{varblock}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Bad comments}
\begin{overlayarea}{\textwidth}{\textheight}
\begin{onlyenv}<1>
\vspace{-3mm}
\begin{varblock}{block example}[0.94\textwidth]{Several bad habits in one example}<only@1>
\begin{lstlisting}[style=MyCpp]
/**
* @param longTitle The complete title of the CD
* @param longAuthor The complete author of the CD
* @param nTracks The number of tracks of the CD
* @param durationInMinutes The duration of the CD in minutes
*/
void Jukebox::addCD(std::string longTitle,
std::string longAuthor,
/*int nTracks,*/ int durationInMinutes)
{
// Create new CD to be later added to the list
CD cd;
cd.title = longTitle;
cd.author = longAuthor;
//cd.tracks = nTracks;
cd.duration = durationInMinutes;
if(cd.duration<60) // Added by James
throw std::invalid_argument();
cdList.push_back(cd);
} // addCD method
\end{lstlisting}
\end{varblock}
\end{onlyenv}
\begin{onlyenv}<2>
\begin{varblock}{block example}[0.7\textwidth]{The same code cleaned up}
\begin{lstlisting}[style=MyCpp]
void Jukebox::addCD(std::string longTitle,
std::string longAuthor,
int durationInMinutes)
{
CD cd;
cd.title = longTitle;
cd.author = longAuthor;
cd.duration = durationInMinutes;
if(cd.duration<60)
throw std::invalid_argument();
cdList.push_back(cd);
}
\end{lstlisting}
\end{varblock}
\vspace{-2mm}
\begin{varblock}{block example}[0.7\textwidth]{}
The code becomes smaller and it reads well!\\
Why should you add a comment here?!
\end{varblock}
\end{onlyenv}
\begin{onlyenv}<3>
\vspace{3mm}
\begin{itemize}
\item Redundant comments \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\alert{Avoid}}
\item Noise comments \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\alert{Avoid}}
\item Misleading comments \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\alert{Avoid}}
\item Comments instead of a good name \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\PS{Use good name}}
\item Closing brace comments \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\PB{Rarely}}
\item Attribution comments \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\alert{Delete, use version control}}
\item Commented-out code \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\alert{Delete, use version control}}
\item Unclear, cryptic comments \hfill\makebox[55mm][l]{\PP{$\;\to\;$}\alert{Remove or clarify}}
\end{itemize}
\begin{center}
\large
Have \textbf{\tikzmark{GR1}good reasons\tikzmark{GR2}} before adding a comment!
\end{center}
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north, font=\footnotesize, text=ALERT] at ($(GR1)!0.5!(GR2)-(0,2mm)$) {Are they?};
\end{tikzpicture}
\end{onlyenv}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{Formatting}{Yes, formatting is important!}
\begin{onlyenv}<1-4>
\begin{varblock}{alert}[0.6\textwidth]{The 3 most important rules:}
\begin{enumerate}[<+(1)->]
\item Stay coherent with what you find
\item Stay coherent with what you find
\item Stay coherent with what you find
\end{enumerate}
\end{varblock}
\vspace{-2mm}
\begin{varblock}{alert}[0.7\textwidth]{}<uncover@4>
\textbf{This starts with but it is not limited to formatting!}
\end{varblock}
\vspace{-2mm}
\begin{varblock}{alert}[0.85\textwidth]{}<uncover@4>
Especially important when working on an existing codebase!
\end{varblock}
\end{onlyenv}
\begin{onlyenv}<5>
\vspace{-2mm}
\begin{itemize}
\item How big should be a file? \\ $\to\;$ Try to stay \PP{below few hundreds}, the reader will be grateful!
\item Give some vertical breath to your code
\item Care about length of lines (\PP{80} to \alert{140} characters) \\
$\to\;$ Crucial if the code is readable from browser (e.g. \PP{GitHub})
\item Consider horizontal alignment and spacing (e.g. \PP{around operators})
\item Be coherent (e.g. \PP{braces})
\end{itemize}
\vspace{-1mm}
\begin{varblock}{alert}[0.9\textwidth]{How to work when different people write in the same code base?}
Agree on a style and \alert{use a tool} (e.g.\ clang-format) to enforce it
\end{varblock}
% \begin{tikzpicture}[remember picture, overlay]
% \node[anchor=north east, rounded corners=1mm, draw=ALERT, outer sep=6mm] at (current page.north east) {
% \begin{tabular}{c}
% Agree on a style and \alert{use a tool}\\
% (e.g.\ clang-format) to enforce it
% \end{tabular}
% };
% \end{tikzpicture}
\end{onlyenv}
\end{frame}
%===================================================================================================%
%===================================================================================================%
\section{Functions and Classes}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Common general aspects}
\vspace{-1mm}
\begin{overlayarea}{\textwidth}{\textheight}
\begin{varblock}{block alerted}[0.5\textwidth]{SMALL}
Do \alert{one} thing. Do it \alert{well}. Do it \alert{only}!
\end{varblock}
\begin{itemize}[<only@1-3,5>]
\item Functions and classes interfaces should stay small (see next slide)
\item \tc<2>{PP}{Classes should fulfil the single responsibility principle}
\item \tc<3>{PP}{One level of abstraction per function}
\end{itemize}
\begin{onlyenv}<3>
\begin{center}
\begin{minipage}{0.65\textwidth}
\begin{enumerate}
\item Let's start with an example of bad code
\item and then have a look to how it should be
\end{enumerate}
\end{minipage}
\end{center}
\end{onlyenv}
\vspace{-2mm}
\begin{varblock}{block example}[0.51\textwidth]{Single-responsibility class}<only@2>
\begin{lstlisting}[style=MyCpp]
class Version {
public:
int getMajorVersionNumber();
int getMinorVersionNumber();
int getBuildNumber();
// [...]
};
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.8\textwidth]{Impolite, rude code $\to$ up and down to understand it!}<only@4>
\begin{lstlisting}[style=MyCpp]
void MakeCoffee(const Coffee& typeOfCoffee){
auto neededT = temperature(typeOfCoffee);
if(neededT < T)
warmUp(neededT);
while(grinder != nullptr)
prepareGrinder();
grind(calculateGrams(typeOfCoffee));
auto neededP = pressure(typeOfCoffee);
prepareToBrew(neededT, neededP);
if(status == READY_TO_BREW)
brew(typeOfCoffee);
else
throw std::runtime_error("Unable to brew!");
}
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.71\textwidth]{Single-level-of-abstraction function}<only@5>
\begin{lstlisting}[style=MyCpp]
void MakeCoffee(const Coffee& typeOfCoffee){
WarmUpMachineIfNeeded(typeOfCoffee);
GrindCoffee(typeOfCoffee);
SetPressureAndTemperature(typeOfCoffee);
BrewCoffee(typeOfCoffee);
}
\end{lstlisting}
\end{varblock}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{More about this one-thing idea}
\begin{overlayarea}{\textwidth}{0.85\textheight}
\begin{varblock}{quote}[0.75\textwidth]{How big should a function be?}[Robert C. Martin]<only@1,3>
\uncover<3>{
A function should do one thing.
But what's one thing?
A function does one thing, if you cannot meaningfully extract another function from it.
}
\end{varblock}
\begin{varblock}{block example}[0.8\textwidth]{Back to our example}<only@2>
\begin{lstlisting}[style=MyCpp]
void MakeCoffee(const Coffee& typeOfCoffee){
// 1. WarmUpMachineIfNeeded
auto neededT = temperature(typeOfCoffee);
if(neededT < T)
warmUp(neededT);
// 2. GrindCoffee
while(grinder != nullptr)
prepareGrinder();
grind(calculateGrams(typeOfCoffee));
// 3. SetPressureAndTemperature, needs T again
auto neededP = pressure(typeOfCoffee);
prepareToBrew(neededT, neededP);
// 4. BrewCoffee
if(status == READY_TO_BREW)
brew(typeOfCoffee);
else
throw std::runtime_error("Unable to brew!");
}
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.71\textwidth]{Result after extraction}<only@3>
\begin{lstlisting}[style=MyCpp]
void MakeCoffee(const Coffee& typeOfCoffee){
WarmUpMachineIfNeeded(typeOfCoffee);
GrindCoffee(typeOfCoffee);
SetPressureAndTemperature(typeOfCoffee);
BrewCoffee(typeOfCoffee);
}
\end{lstlisting}
\end{varblock}
\end{overlayarea}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{Limit the number of arguments}{Make useful abstractions whenever it helps}
\begin{varblock}{block example}[\textwidth]{When you call the function, which argument is what?}
\begin{lstlisting}[style=MyCpp]
double Distance(double, double, double, double);
double Distance(double, double, double, double, double, double);
\end{lstlisting}
\end{varblock}
\begin{tikzpicture}
\path coordinate (A) at (0,0) coordinate (B) at (3,1);
\fill[PB] (A) circle[radius=1mm]; \fill[PB] (B) circle[radius=1mm];
\draw[<->, >=stealth, shorten <= 4pt, shorten >= 4pt] (A) -- (B);
\node[left = 2mm of A] {$A$};
\node[right = 2mm of B] {$B$};
\end{tikzpicture}
\vspace{-1mm}
\begin{varblock}{block example}[0.72\textwidth]{Isn't this much better?}<uncover@2>
\begin{lstlisting}[style=MyCpp]
struct Point2D { struct Point3D {
double x, y; double x, y, z;
}; };
double Distance(std::pair<Point2D, Point2D>);
double Distance(std::pair<Point3D, Point3D>);
\end{lstlisting}
\end{varblock}
\begin{tikzpicture}[remember picture, overlay]
\draw[visible on=<2>, thick] ($(current page.center)-(0.2,1.7)$) -- ++(0,-1);
\end{tikzpicture}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}[fragile]{\PQ{I}ntegration \PQ{O}peration \PQ{S}egregation \PQ{P}rinciple}
\begin{overlayarea}{\textwidth}{0.85\textheight}
\vspace{-3mm}
\begin{varblock}{block alerted}[\textwidth]{Clear separation of:}
\begin{description}
\item[Operation:] A function which contains exclusively logic, meaning transformations, control structures or API invocations.
\item[Integration:] A function which does not contain any logic but exclusively calls other functions of the code base.
\end{description}
\end{varblock}
\vspace{-1mm}
\begin{varblock}{block example}[0.75\textwidth]{Operation}<only@1>
\begin{lstlisting}[style=MyCpp]
bool isPrime(unsigned int number)
{
if(number == 1) return false;
for(auto i = 2u; i <= std::sqrt(number); ++i)
{
if(number%i == 0) return false;
}
return true;
}
\end{lstlisting}
\end{varblock}
\begin{varblock}{block example}[0.62\textwidth]{Integration}<only@2>
\begin{lstlisting}[style=MyCpp]
int main(int argc, char *argv[])
{
WelcomeUserToTheGame();
Minesweeper minesweeper(argc, argv);
minesweeper.playGame();
PrintGameResult();
}
\end{lstlisting}
\end{varblock}
\end{overlayarea}
\end{frame}
%===================================================================================================%
%===================================================================================================%
\section{Testing your code}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\AlertFrame{I have a full \textasciitilde2h seminar on this topic}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{Software testing}{Test code is just as important as production code}
\begin{columns}[c]
\begin{column}{0.5\textwidth}
\begin{itemize}
\item \PP{Testing levels}
\begin{itemize}
\item \alert<2>{Unit testing}
\item \tc<2>{PQ}{Integration testing}
\item System testing
\item Acceptance testing
\end{itemize}
\vspace{3mm}
\item \PP{Testing types and techniques}
\begin{itemize}
\item \alert<2>{Regression testing}
\item \alert<2>{Automated testing}
\item Continuous testing
\item \ldots
\end{itemize}
\end{itemize}
\end{column}
\begin{column}{0.5\textwidth}
\centering
\begin{uncoverenv}<2>
\includegraphics[height=32mm]{SoftwareTesting.jpeg}$\quad$
\includegraphics[height=32mm]{TDD.jpeg}
\end{uncoverenv}
\end{column}
\end{columns}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{The \PQ{wrong} mental approach to testing}
\vspace{2mm}
\begin{itemize}
\item I do not have time to waste writing tests.
\item \alert{The result is reasonable, the code should be correct!}
\item This part of code is simple, why should I test it?
\item Let me finish to implement this feature so that I can produce some data and in the meanwhile I write some tests.
\end{itemize}
\begin{center}
\begin{tikzpicture}
\node (fig) {\includegraphics[width=0.45\textwidth]{WrongTesting}};
\node[anchor=north, font=\Tiny] at ([yshift=1mm]fig.south) {\url{https://android.jlelse.eu/basics-of-unit-testing-affdd2273310}};
\draw[red, line width=2mm, visible on=<2>] (fig.south east) -- (fig.north west) (fig.south west) -- (fig.north east);
\end{tikzpicture}
\end{center}
\begin{tikzpicture}[overlay, remember picture]
\node[starburst, starburst points=27, starburst point height=16mm, minimum width=12cm, minimum height=5cm,
Shape={red}{yellow!50}{red}, line width=1.5pt, font=\Huge, rotate=10, visible on=<2>] at ([shift={(-0mm,21mm)}]current page.center) {Please, NO!};
\end{tikzpicture}
\end{frame}
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%
\begin{frame}{The \PS{correct} mental approach to testing}
\begin{itemize}
\setlength{\itemindent}{-2mm}
\item Testing is part of the natural evolution of the code (not an overhead)
\item Test code has to fulfil the same clean code rules as production code
\item \alert{Tests are the key to be free to change (improve) the production code!}
\item Keep balance between adding new code, writing tests and refactoring
\end{itemize}
\vspace{3mm}
\begin{uncoverenv}<2>
\begin{center}
\resizebox{!}{0.32\textheight}{
\begin{tikzpicture}
\tikzstyle{Pie}=[font=\Large]
\tikzstyle{PieNum}=[font=\Large\bfseries\ttfamily]
\piechartthreed[scale=0.8, background color=white, mix color= white]{120/PS!50!LimeGreen,120/PP!50!white,120/PT}