Style Flashcards
The practice of rewriting existing code to improve its design is called ANSWER.
refactoring
ANSWER is the name of the code smell for when an instance method doesn’t rely on the state of the instance.
utility function
ANSWER is the name of the code smell for when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.
data clump
When you have two or three items that frequently appear together, the first step in fixing the problem is generally ANSWER.
put them in their own object
The code smell called ANSWER occurs when a code fragment references another object more often than it references itself.
feature envy
A popular Phil Karlton quote is: There are only two hard things in computer science - cache invalidation and ANSWER.
naming things
A class that publishes a getter or setter for an instance variable invites client classes to commit the code smell called ANSWER.
inappropriate intimacy
The prof thinks code should be broken into small pieces in order to make ANSWER easier.
re-using the code
Among other reasons
Scalastyle was originally flagging println as bad practice because in most production code, the usage of println you see is debug messages and people should be using ANSWER instead.
a logging package
The reason scalastyle complains about methods returning null can be seen by considering the type system of Scala. If I have a function that tests a parameter x to see if it is less than 3 and returns 2 if the test is true and null if the test is false, the type of the return value of the function would be ANSWER.
any
The reason scalastyle complains about methods using return also has to do with the type system of Scala. If in the Scala repl if I define a parameterless function f as equal to 3, then f is of type Int. However, if I instead define the function to be equal to return 3, I get an error message telling me that f ANSWER.
needs a result type