Wednesday, 29 March 2017

Existence of repeated patterns as an indicator of potential computer language improvements

I recently came across the following code:
Class Example(Model): def __init__(self, height, width, citizen_density, cop_density,
citizen_vision, cop_vision, legitimacy,
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?

No comments:

Post a Comment