天天看點

Effective Django # 作者序

note:

video of this tutorial (https://www.youtube.com/watch?v=nfsjdpm0x54) from pycon is available on

youtube.

django is a popular, powerful web framework for python. it has lots of “batteries” included, and makes it easy to

get up and going. but all of the power means you can write low quality code that still seems to work. so what does

effective django mean? it means using django in a way that emphasizes writing code that’s cohesive, testable, and

scalable. what do each of those words mean?

well, “cohesive” code is code that is focused on doing one thing, and one thing alone. it means that when you write a

function or a method, that it does one thing and does it well.

this is directly related to writing testable code: code that’s doing too much is often difficult to write tests for. when i

find myself thinking, “well, this piece of code is just too complex to write a test for, it’s not really worth all the effort,”

that’s a signal that i need to step back and focus on simplifying it. testable code is code that makes it straight-forward

to write tests for, and that’s easy to diagnose problems with.

finally, we want to write scalable code. that doesn’t just mean it scales in terms of performance, but that it also

scales in terms of your team and your team’s understanding. applications that are well tested are easier for others

to understand (and easier for them to modify), which means you’re more able to improve your application by adding

engineers.

my goal is to convince you of the importance of these principles, and provide examples of how to follow them to build

more robust django applications. i’m going to walk through building a contact management application iteratively,

talking about the choices and testing strategy as i go.

the sample code for this tutorial is available in the effective-django-tutorial (https://github.com/nyergler/effective-

django-tutorial/) git repository.

slides for the tutorial are available at http://effectivedjango.com/slides/tutorial

繼續閱讀