Why You Shouldn't Nest Your Code

CodeAesthetic · 3.4M views · 2022 · 8:30

Open on YouTube

Software practice, open source & careersSoftware architecture & designexplainer

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about nested if statements or messy functions, as a concise case for early returns and smaller functions.

Recommended by 2 people across 2 different months, 2023 to 2024.

What it is

A short explainer from the CodeAesthetic channel arguing that deeply nested code is hard to read and should be flattened. It walks through techniques like inverting conditions for early returns and extracting logic into small functions, with code examples.

What people said

Recommends grumBit · 2024-03 · Stack Overflow · on “How to Organize Python Code Into Functions”

I came across this vid, which I think gives really good advice on when and why to break Python code into functions; [this video]

Recommends airtonix · 2024-09 · Stack Overflow · on “Nested if Statement good or bad?”

Bad. Think about the logical progression of your example. How will the less experienced on your team extend it? My approach is to be a never nester [this video] : exit your false conditions early avoid god components, construct your logic blocks as separate compos-able units. if (!loggedIn) { return 'Please Register'; } if(!!row.voted){ return 'You Already voted'; } return 'agree'; Most advice is given under the assumption that your team is either: just you you and other highly disciplined fastidious developers The reality (due to hiring market conditions) is that your team will be time and experience poor. Demonstrate scalable and async ways for code to remain readable in the long run. Avoid the

Cites not a tshirt · 2023-11 · Stack Overflow · on “.EXE did not show selected file! Why after i convert my '.py' file to '.exe', it works but cannot extract the excel file that user chose on interface?”

I'm not too familiar with the Tkinter stuff, however I would assume this to be a path related issue. I believe this is an issue with the sys._MEIPATH vs os.path.abspath('.') . Using sys._MEIPATH allows you to find the pyinstaller temp folder, which is for project specific files, however you are loading a user specified file, which is not necessarily part of the project itself. This means you probably just want to use the regular path to the excel file instead of calling resource_path(file_path) . I would also suggest a few other refactors for readability which I've made below (my own preference, watch [this video] ) Please read the comments in this code to understand what I've done and don't just