4 ms·
Missed chance to do something like: class User: def calculateCoworkers() = { this.coworkers.clear() for { d <- this.departments } thi
by jmmv 1y ago
Missed chance to do something like:
class User:
def calculateCoworkers() = {
this.coworkers.clear()
for { d <- this.departments }
this.coworkers ++ d.employees
}
and then, somewhere else...
user.calculateCoworkers()
... many lines after ...
for { c <- user.coworkers }
... do something ...
Yes, I've seen code like this many, many, many times where class members are used as "global variables" to pass state across functions. And I've noticed AI likes to generate code like this too (possibly because of the former (large presence of this "pattern" in the training data), which means I'm encountering this now in pull requests...
- sevensor 1y agoBonus points if you do half the calculation in the parent class and the other half in a child class. Double bonus points if one or both of them also hits a database.