2025-04-15
Top-down structure of code

Top-down structure of code

Write code in such a way that the part you want to quickly reference is at the top of the file.

For example, the main() function may depend on func1() and func2(), but that doesn’t mean that the main() function has to be at the bottom of the code.

1
2
3
4
5
6
7
8
9
10
11
12
def main():
func1()
func2()

def func1():
pass

def func2():
pass

if __name__ == '__main__':
main()

Structuring this way is better because now the functionality of the code is more easily apparent without having to scroll down to the bottom of the file.

Read More