TrafficService takes parameters ['since', 'till'] to 3 methods Open
def per_day(since: , till: nil, metric_name: self.metric_name)
till ||= now
usage = stats_client.usage(
metric_name: metric_name,
- Read upRead up
- Exclude checks
In general, a Data Clump
occurs 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.
The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.
Example
Given
class Dummy
def x(y1,y2); end
def y(y1,y2); end
def z(y1,y2); end
end
Reek would emit the following warning:
test.rb -- 1 warning:
[2, 3, 4]:Dummy takes parameters [y1, y2] to 3 methods (DataClump)
A possible way to fix this problem (quoting from Martin Fowler):
The first step is to replace data clumps with objects and use the objects whenever you see them. An immediate benefit is that you'll shrink some parameter lists. The interesting stuff happens as you begin to look for behavior to move into the new objects.
TrafficService#now doesn't depend on instance state (maybe move it to another class?) Open
def now
- Read upRead up
- Exclude checks
A Utility Function is any instance method that has no dependency on the state of the instance.
TrafficService#last_traffic_date has the variable name 'i' Open
days_ago = usage.reverse.find_index{|i| i > 0 }
- Read upRead up
- Exclude checks
An Uncommunicative Variable Name
is a variable name that doesn't communicate its intent well enough.
Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.