I recently came across the following code:
| ||
max_jail_term, active_threshold=.1, arrest_prob_constant=2.3, | ||
movement=True, max_iters=1000): | ||
super().__init__() | ||
self.height = height | ||
self.width = width | ||
self.citizen_density = citizen_density | ||
self.cop_density = cop_density | ||
self.citizen_vision = citizen_vision | ||
self.cop_vision = cop_vision | ||
self.legitimacy = legitimacy | ||
self.max_jail_term = max_jail_term | ||
self.active_threshold = active_threshold | ||
self.arrest_prob_constant = arrest_prob_constant | ||
self.movement = movement | ||
self.running = True | ||
self.max_iters = max_iters | ||
self.iteration = 0 | ||
self.schedule = RandomActivation(self) | ||
self.grid = Grid(height, width, torus=True) There seems to be a lot of repetition here. And the problem is not the code itself. The repetitive pattern is required by the language. Seems to me it could be simplified. If not automatically, then perhaps by making it possible to say: "Take all argument of the function and make them properties of the object" Or perhaps, more flexible: "Take all except these ..." One line instead of many. Is it possible and is it a good idea? |
Mostly python and data analysis (small and big). Mixed with random rants and more mild mannered musings.
Wednesday, 29 March 2017
Existence of repeated patterns as an indicator of potential computer language improvements
Subscribe to:
Posts (Atom)