DEV Community

Discussion on: Writing clean code in Python

Collapse
 
fayomihorace profile image
Horace FAYOMI

This is a crazy good article for people who want write nice python code.
But please, why the points #10 Use a main() function and #11 Do not use empty lists as default arguments, I mean which issue might occurs if we do themand in which circumstances ?

Collapse
 
dmerejkowsky profile image
Dimitri Merejkowsky • Edited

Regarding the main() function:

  • having a main() function gives a scopes for lots of variables which would otherwise be globals - and having less globals is often a win ;)
  • having a separate main() function makes it easy to import your module to do something else with it (like write some tests)

Regarding the default arguments : it's all about the principle of least astonishment see :
this nice answer on stack overflow

PS:

This is a crazy good article

Thanks. This is very much appreciated :)