Lightning talks at the Dutch Django meeting (part one)¶
Lightning talks at the April 2012 Dutch Django meeting
Code with style: PEP8 and Pylint - Johan Otten¶
Readability counts and PEP8 gives you a consistent code style. And it is BDFL-approved.
There’s a tool for it: http://pypi.python.org/pypi/pep8 .
Pylint gives you static program analysis. There’s a lot it checks.
Also look at PEP 257 about docstrings. Read it once or twice, just to get it a bit in the back of your head. It is not that important.
Note: there’s also a django lint.
Very useful: there’s a Jenkins “violations” plugin. This helps you see the number of pep8/pylint violations. Also there’s django-jenkins that helps a lot in setting up Jenkins for Django projects.
(Personal note: I really agree with PEP8, I even helped getting pep8 on
pypi (it was a standalone .py file earlier). And I personally prefer
pyflakes to pylint. Way easier to
run than pylint and you get a lot of the benefits. And if you want to use pep8
and pyflakes in emacs, see
http://reinout.vanrees.org/weblog/2010/05/11/pep8-pyflakes-emacs.html ).
Building apps using high-level models - Jeroen Vloothuis¶
Jeroen worked on a project with a questionaire with lots of pages and questions. Boring code to write, adding all those questions as Django model fields. Lots of model code, lots of view code.
The solution: let’s genereate one data structure to rule everything for me. So
he defined some Questionaire and Question classes that he could define
questionaires with in a simple syntax (one line per question).
He would then use that information to generate the Django models! The same for generationg the forms.
The good thing: it’s really DRY (Don’t Repeat Yourself) and it is nicely
declarative. The bad thing is when you need to do debugging (the code is
generated, so you cannot stick a pdb in there somewhere). And you need
quite some Django skill to pull it off.
Jeroen has a blog post about this, you can see code examples there.