2 ms·
If you want to actually solve this problem without doing the thing in the slideshow or shooting yourself, when you see if(self.predicate_function())
by bcoates 11y ago
If you want to actually solve this problem without doing the thing in the slideshow or shooting yourself, when you see
if(self.predicate_function())
foo()
else
bar()
and self.predicate_function() is only called once in the program (this is the case several times in the slideshow example), try pulling the if statement into the function (and simplify), making a
self.handle_case_something()
function instead. If the predicate is called more than once, consider subclassing. You're already doing OO, may as well do it right.
- fleitz 11y agoExactly it seems like you could replace all this code with: send("#{group.type}_notification") or its python equivalent. Maybe a hash table with strings as keys and functions as values for a less 'scripty' language. Perhaps I'm thinking the variable group is of type group, but it also looks like it suffers from poor separation of concerns... eg. Why are groups sending email? Probably also a good candidate for guards instead of nested ifs