Aaron Swartz is no diplomat but he made some good points in this rant:

http://www.aaronsw.com/weblog/rewritingreddit

The magic-removal branch addresses the ORM issues he raised.  A
remaining problem is the disorientating namespace.

View modules typically begin with ugly boilerplate like:

---

from django.core.extensions import DjangoContext as Context
from django.core.extensions import render_to_response,
get_object_or_404
from django.core.exceptions import Http404
from django.utils.httpwrappers import HttpResponse,
HttpResponseRedirect
from django.core.template.loader import render_to_string
...

---

As Aaron says, it is not obvious to the outsider what the underlying
structure of the package hierarchy is.  I suspect this is a common
problem in projects that have evolved to meet the needs of a busy
production environment.

The most confusing aspect is the second level of the namespace.  What
is core?  What are utils?  And what counts as an extension?

What about something like this:

django.utils.httpwrappers  -> django.http
django.core.template       -> django.template
                                - includes Context/DjangoContext
django.core.exceptions     -> django.error
django.core.extensions     -> django.shortcuts
                                - includes render_to_string
django.contrib             -> django.apps
django.utils.feedgenerator -> django.feed
django.core.formfields     -> django.form

If the names are kept short and predictable then it becomes feasible
to import and use the second tier directly, which could simplify the
basic boilerplate down to:

---

from django import http, template, error
from django.shortcuts import *

def basic_view(request):
    t = template.get('mytemplate')          # get <- get_template
    c = template.Context({'name':'yehudi'})
    return http.Response(t.render(c))       # Response <- HttpResponse

def shortcut_view(request):
    return render_to_response('mytemplate', {'name':'yehudi'})

---

This might not be a backwards-compatibility nightmare because the
existing namespace could be preserved by importing from the new
namespace.  For example, if django.core.exceptions goes to
django.error then django.core.exceptions becomes:

---

from django.error import *

---

Thoughts?

Kieran

Reply via email to