by amix · 16y ago · 0 comments
handler = {
'football': handle_football,
'comedy': handle_comedy,
'crime': hendle_crime
}.get
handler('crime')(...) std::map<std::string, boost::function<void (int)>> handlerMap;
boost::assign::insert(handlerMap)
("football", &handleFootball)
("comedy", &handleComedy)
("crime", &handleCrime);
handlerMap["football"](channelNumber);
Makes the code so much easier to understand. And when the handler functions start getting too complex, you can just add another level: handlerMap["comedy"]["situational_comedy"](channelNumber); getattr(self, 'handle_%s' % action)The inane lisper bon mot is stated backwards: it should be "Data isn't code"