Django best practices — part 1
I have had the chance of mentoring people who are learning programming and also need help fixing some errors. Although I have experience using Python, Ruby, .NET, C# and JavaScript, I’ve learn best practices throughout my years as a Software developer and indeed I am still learning. I am specifically focusing this article on a few best practices I have learnt over the years with Django. You will find out that these best practices are also Python’s best practices
1) Use Meaningful and descriptive names
1. Class names
should always be in Pascal Case. See example
Use TeamMember instead of teamMember, Teammember, team_member or teammember. Using pascal case makes it easy to read and understand.
2. Variable names
Variable names should be snake cased. Avoid using Java styled methods like myDict or mydict instead use my_dict. Use an underscore (_) whenever a space is meant to break the words apart. It is better to have meaningful and readable variable names than a confusing and short variable name.
For example, use
first_name instead of firstName or firstname
calculated_avg_attendance instead of avgatt. Remember code readabiilty is more important.