diff --git a/slides/12_clean_code.html b/slides/12_clean_code.html new file mode 100644 index 0000000..890e81b --- /dev/null +++ b/slides/12_clean_code.html @@ -0,0 +1,804 @@ + + +
+ + + +Gergő Pintér, PhD
+gergo.pinter@uni-corvinus.hu
+++As aspiring Software Craftsmen we are raising the bar of professional +software development by practicing it and helping others learn the +craft. Through this work we have come to value:
++
+- Not only working software, but also well-crafted +software
+- Not only responding to change, but also steadily adding +value
+- Not only individuals and interactions, but also a community +of professionals
+- Not only customer collaboration, but also productive +partnerships
+That is, in pursuit of the items on the left we have found the items +on the right to be indispensable.
+
not just style guides, also best practices
+just as in the case of natural languages, you ought to use a language +properly
+Clean Code: A Handbook of Agile Software Craftsmanship
+by Robert C. Martin (2009) martin2009clean?
+some recommendations are too specific to C-like languages
+this section is based on the book Clean Code (chapter 2) by +Robert C. Martin martin2009clean?
+UpperCamelCase (PascalCase)
+ +a study states, camelCase is faster to type but snake_case is faster +to read sharif2010eye?
+read the style guide
+++Do not refer to a grouping of accounts as an
+accountList
+unless it’s actually aList
martin2009clean?.
better to use accounts
, it does not depend on the
+collection name
inconsistent spellings is also disinformation
+++disinformative names would be the use of lower-case
+L
or +uppercaseO
martin2009clean?
++It is not sufficient to add number series or noise words, even though +the compiler is satisfied. If names must be different, then they should +also mean something different martin2009clean?.
+
++Noise words are another meaningless distinction. Imagine that you +have a
+Product
class. If you have another called +ProductInfo
orProductData
, you have made the +names different without making them mean anything different martin2009clean?.
++If you can’t pronounce it, you can’t discuss it without sounding like +an idiot martin2009clean?.
+
etid
be an integer?elapsed_time_in_days
be an integer?could be especially important for non-native speakers as some words +are more difficult to pronounce
+++Single-letter names can ONLY be used as local variables inside short +methods. The length of a name should correspond to the size of its scope +martin2009clean?.
+
User
, Activity
user = User()
aggregate_activity
activity_aggregation
with modern IDEs it is pointless to put type or role markers into +names
+Hungarian notation
+source: bhargav2024hungarian?
+++ +Readers shouldn’t have to mentally translate your names into other +names they already know martin2009clean?.
+
++Say what you mean. Mean what you say martin2009clean?.
+
++it’s confusing to have
+fetch
,retrieve
, +andget
as equivalent methods of different classes martin2009clean?
it also helps to search for the term
+++Imagine that you have variables named firstName, lastName, street, +houseNumber, city, state, and zipcode. Taken together it’s pretty clear +that they form an address. But what if you just saw the state variable +being used alone in a method? martin2009clean?
+
addrCity
, addrStreet
,
+addrState
Address
class
+instead to add contextthis section is based on the book Clean Code (chapter 3) by +Robert C. Martin martin2009clean?
+