spcl / dace

DaCe - Data Centric Parallel Programming
http://dace.is/fast
BSD 3-Clause "New" or "Revised" License
491 stars 124 forks source link

Code style issue: too long functions #406

Closed and-ivanov closed 2 years ago

and-ivanov commented 3 years ago

Python google styleguide

Prefer small and focused functions. If a function exceeds about 40 lines, think about whether it can be broken up without harming the structure of the program.

Example

https://github.com/spcl/dace/blob/6e91853c0f4fa06ebdd8672e52b478f9b7219873/dace/transformation/dataflow/map_fusion.py#L194

Pros

Possible solution

Split long functions into small functions across the boundaries defined by comments between chunks of block.

Before

def foo():
  # do action X
  some code
  # do action Y
  some code

After

def do_action_X(...):
   some code
def do_action_Y(...):
   some code
def foo():
  do_action_X(...)
  do_action_Y(...)
definelicht commented 3 years ago

Agree, we did something like this for unparse_tasklet, for example. I would like to specifically mention memlet_copy_to_absolute_strides (in fact, after using it many times, I still don't really understand what this function does).

alexnick83 commented 3 years ago

I agree. This is a matter of identifying what methods would be suitable for replacing the original one. We can make a list of candidate methods and work on them when there is time.

acalotoiu commented 3 years ago

The difficulty is that this is hard to figure out in advance, and finding time is always a nightmare. Even though we all agree I suspect that unless we have some dedicated slot to do this stuff - something like a once every X months we spend 1-2 evenings on this, I am afraid this will always be pushed back by urgent stuff.