English
[Side Note] Regarding the location of the main function

[Side Note] Regarding the location of the main function

Let's move the `main` function to the top

Introduction

I’ve decided to use the “자투리

” category to share brief insights I’ve learned!

Placing the main Function at the Top

This is something that occurred to me while taking the [CS50](https://www.youtube.com/live/ywg7cW0Txs4?feature=share

) course. Personally, I tend to write code like this:


def example():
	print('hello')
    
def main():
	example()
    
main()

For example, I list all the necessary function definitions at the beginning and then add the main function afterward.

However, I realized that having the main function right at the top definitely makes the code clearer for others to understand.


def main():
	example()
    this_function()

def example():
	print('hello')
    
def this_function():
	print('function')
    
main()

I should move the main function—which demonstrates the overall structure of the code—to the top and list the detailed definitions afterward to better illustrate the code’s functionality.

댓글 작성

게시글에 대한 의견을 남겨 주세요.

댓글 0