Why should i group related functions in one file?

65 views
Skip to first unread message

Driele Reis

unread,
Jan 18, 2017, 7:20:42 AM1/18/17
to Python GCU Forum

I came to believe that separating one function per file is better than grouping related functions in just one file.

I can't believe python programmers would think it's easier a file with 10 functions instead of 10 files with 1 function.

Is so MUCH clear, each file has one function and dependencies that are necessary to make the function run.

I find myself agonizing when i'm working in a file with several functions, i can't pay attention.

Pros of this design:

  1. If i just have one function per file, it's more clear which dependencies the function need to run.
  2. It's easier to read if you don't have all that code around.
  3. I can think clearly when i'm making a function, since i don't have the distraction of looking to other functions.

Also, with this type of design, i can parse the files and spit an graphic showing how functions relate each other and each dependencies each function needs.

I'm looking for this design in python packages but i'm not finding any, just in node.js and C/C++

This design is very common in node.js and C/C++ programmers, Why not use it in python??

Resolving import problems is easier, i just put in my init.py:

from .some_func import some_func
from .some_func2 import some_func2

Then i just do this when i need import my package:

from some_func import some_func

Thanks.

Reply all
Reply to author
Forward
0 new messages