Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Un-nest heavily nested for-loops #129

Open
Kiel-SFU opened this issue Feb 8, 2022 · 0 comments
Open

Un-nest heavily nested for-loops #129

Kiel-SFU opened this issue Feb 8, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@Kiel-SFU
Copy link
Collaborator

Kiel-SFU commented Feb 8, 2022

Generally, nesting more than a few for-loops is considered bad practice in Python because it is known to imply that a) there might be a more efficient way of doing it (for example, through itertools), or if not a), then that b) the code is probably difficult to read.

Because Pylint is now enforcing a max line length of 90 in the codebase, it has become more relevant to reduce line length. To make lines less long on average, generally you would do something like this:

for a in ax:
   for b in bx:
      for c in cx:
         for d in dx:
            // do something in d
         // do something in c
      // do something in b
   // do something in a

would become

for a in ax:
   for b in bx:
      loop_over_c()
      // do something in b
   // do something in a

loop_over_c(){
for c in cx:
   for d in dx:
      // do something in d
   // do something in c
}

We should consider looking for places in the code where this sort of change could be applied, such as in capacity_factor.py.

@Kiel-SFU Kiel-SFU added the enhancement New feature or request label Feb 10, 2022
@Kiel-SFU Kiel-SFU self-assigned this Feb 10, 2022
@Kiel-SFU Kiel-SFU removed their assignment Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant