Shift3 / standards-and-practices

Standards and Practices for Bitwise Industries
https://shift3.github.io/standards-and-practices/
63 stars 41 forks source link

Recommendations for Python Development #131

Open zbyte64 opened 5 years ago

zbyte64 commented 5 years ago

Request for comments: what practices should we include in the writing of python code?

Here are a few to get the ball rolling:

stephengtuggy commented 5 years ago

I don't use black for code formatting. I use Visual Studio Code for that.

@zbyte64 what are your thoughts on this?

stephengtuggy commented 5 years ago

Write tests with pytest? Absolutely. requirements.txt? Definitely.

I might also add:

DropsOfSerenity commented 5 years ago

My advice is:

DropsOfSerenity commented 5 years ago

Other recommendations:

stephengtuggy commented 5 years ago
  • Don't use the django admin as a user facing administration tool, they recommend against this. Instead use it as a low cost administration tool for developers.

I think I have seen that recommendation before. Can you link to a source? Thanks.

DropsOfSerenity commented 5 years ago

image

DropsOfSerenity commented 5 years ago

From django documentation. https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#module-django.contrib.admin

stephengtuggy commented 5 years ago

@DropsOfSerenity Hmm. That's interesting. I had a different takeaway after reading the exact same paragraph. It sounded to me like trusted users / administrators within a client organization could be given access to the admin interface, while the average user would not have that access. That's how it is set up for Ultra Gro.

stephengtuggy commented 5 years ago

Also for Ultra Gro, I ended up writing tests that fit both the pytest and django.test.* paradigms. Example file here.

DropsOfSerenity commented 5 years ago

They explain the position in some django tickets on their issue tracker as well. The general jist of the thing is:

From experience stripping down the admin to a place where the UX is good for a non-technical administrator is not worth the time.

DropsOfSerenity commented 5 years ago

@stephengtuggy You can access the testing database in a regular django TestCase that test should work without that decorator I believe, is there any reason you stuck with both?

stephengtuggy commented 5 years ago

As I recall, the original tests were written for pytest. I wanted to keep my tests backwards-compatible, while also making them compatible with the more usual Django test framework.

In addition, the test code seemed more elegant that way. If one can make the same (test) code serve two different purposes without duplication, why not, y'know?

carlosvargas commented 5 years ago
kennethkoontz commented 5 years ago

couple of thoughts

stephengtuggy commented 5 years ago
zbyte64 commented 5 years ago

I like gunicorn but would encourage others to experiment, especially with all the new asynchronous python going around.

In the same theme of experimentation, I wouldn't want to prevent someone from trying new libraries like: https://github.com/strawberry-graphql/strawberry ; as long as it is shown to have a healthy community and fits the requirements.

DropsOfSerenity commented 5 years ago

Code quality is to me less about a set of perscriptive technologies, and more about a set of techniques to follow to keep your code clean. I agree with @zbyte64 perhaps we should define the borders of what we want "Python Code Quality" to accomplish and where it's boundaries should be.

General recommendation IMO should be preferred, the things I see people running into most in django is things like, not using select_related (not understanding sql), running into n+1 queries, not understanding what the query language can do for you (looping over result sets instead of querying for what you want), not using null, blank, etc. correctly on the models/migrations, not using django admin for purpose, being afraid of class based views, being afraid of django forms, and being afriad to construct their own plain old python classes, so personally that's where i would target the effort.

carlosvargas commented 4 years ago

I agree @zbyte64 and @DropsOfSerenity. We have to point out all those things and let people experiment, but we also need to provide at least some recommended libraries/frameworks/tools that they can use.

The reason is that a lot of people here don't have much experience with Python/Django or simple don't want to spend hours doing research on what's best to use. So we need to provide something for them to get started.

Maybe it should be in a separate Github issue, but it's something that we need to have.

stephengtuggy commented 4 years ago

This may be relevant: https://www.toptal.com/django/django-top-10-mistakes

stephengtuggy commented 4 years ago

As a follow-up to what @carlosvargas said, what about renaming this issue to "Shift3 Recommendations for Python Development" or similar?

DropsOfSerenity commented 4 years ago

The reason is that a lot of people here don't have much experience with Python/Django or simple don't want to spend hours doing research on what's best to use. So we need to provide something for them to get started.

Good point.

michaelachrisco commented 3 years ago

Revisiting this in slack. Looking for feedback from those of you that use Python/Django!

michaelachrisco commented 3 years ago

As per feedback from above, renamed the issue to Recommendations for Python Development. Look forward to getting more feedback from everyone!