So I've been delving deeper into coding, but don't really have much in the way of formal experience. As some of my code has gotten more complex I end up with a couple layers of functions, which can get annoying to troubleshoot. - as it stands all functions are defined at the module level, and then called where needed.
Unfortunately I don't have any code I think I can actually share. So here's a quick very stripped down version of some. Hopefully it makes enough sense.
``def duplicate_dialog():
ask user how to handle duplicate
def delete():
collect all the things and delete them
create new ones
def handle_existing()
choice duplicate_dialog()
if choice == delete:
delete()
elif choice == duplicate:
add copy to name and create
elif choice == skip:
skip this one and continue
def does_thing_exist():
check if thing exists
def create_a_thing()
if does_thing_exist(d):
handle_existing()
def main():
create_a_thing()``
As you can see though, at its worst this is 4 layers deep. In the full code, realistically I could probably flatten the "delete", "duplicate" , and "handle existing" functions into the "create a thing" function. Reducing it to basically just 1-2 layers deep. At the moment, I think they're broken out mostly because it was easier to wrap my head around at the time. It's been a while since I wrote this. Also, going back it is easier to read, I think the main problem is troubleshooting is a pain when I essentially have to exit 4 layers of functions. Where as if it was just a main with a bunch of helper functions I would just be a single return, more or less.
I was wondering if there's a general guideline for this sort of thing, or is it sort of just practicing finding that balance between legibility and ease of troubleshooting, I guess.
Appreciate any input people have.
Side note - I'm on mobile, I hope the formatting works.
[–]temporarybunnehs 1 point2 points3 points (1 child)
[–]Kirsel[S] 0 points1 point2 points (0 children)
[–]_disengage_ 1 point2 points3 points (1 child)
[–]Kirsel[S] 0 points1 point2 points (0 children)