Wellfire Interactive // Expertise for established Django SaaS applications

Breaking out your Django app for great good (This Old Pony #65)

Last week I told you that creating an open source reusable app was a good way of improving its quality. Some of you may have been disappointed, because the benefit is largely due to instrumental reasons which may not apply to your project. And further, creating a separate and open source version of functionality in your project turns out to be a non-trivial level of effort.

That’s okay, because I have good news! You can get many of the benefits without going through all the trouble of creating and publishing an open source package. You can get most of the benefits by simply pulling the functionality into it’s own app. And if you have multiple projects, you can still create and use an installable app without sharing it with the world.

In the Django Standalone App Fieldguide[0] I outline how one of the steps to pulling functionality out into a standalone app, i.e. one that’s published and downloadable on the Python package index, is creating a distinct, uniquely namespaced app in your own project. So for our purposes here you can stop there.

Let’s reiterate why you would do this, that is, what problems are you solving and what benefits should you expect, aside from more experience refactoring?

  • reduce/clean up coupling
  • makes code more reusable within your project
  • simplifies testing of base functionality
  • reduces the scope of what each app must handle In the end the benefits have as much to do directly with changes in the code as they do with changes in how you think about the code. Extracting base functionality can clarify how it can be further simplified or improved in other ways. Aside from making tests easier to write it can making seeing how to test the edges more obvious. And decoupling core logic from Django specific paradigms (e.g. models, views) often makes it far simpler to work directly on that logic.

I’ve given some outlines on how to approach this in the most recent chapter, “Separating your app”.

What kind of obstacles have you faced in extracting code in your Django projects?

Wheel-installably yours
Ben

[0] Still in the editing process, including some content which is being embargoed until it can face minor editing: http://www.django-standalone-apps.com/

Learn from more articles like this how to make the most out of your existing Django site.