Hello,
Can somebody please proof why it's a bad practice to use solution like this:
In django views in 98% cases you need to use
from django.http import HttpResponseRedirect
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext as _
anyway in my project my every view has these imports and everything is used almost in every second function of a view:
from datetime import datetime
from django.conf import settings
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.core import paginator
from django.db import connection
from django.db.models import Q
from django.http import HttpResponseRedirect, Http404, HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.utils.translation import ugettext as _
Now add some models and forms, and I have 50 lines of bullshit that is impossible to read at all.
First thing that came to my head is of course to make more views, to split some operation and etc and etc.. but still about 30 lines of imports killing my orientation in code.
Then I just decided to put everything that being used in views by 95% of a time, to directory /project/app/imports/view.py. Now I have all common stuff just with ONE import, but my co-worker attacked me, that it's highly hard to read this kind of code, because you can't see what is imported, and why the hell it's so hard to open one more tab in your IDE..??? [especially this goes to vim users, they have FRAMES, and he is using vim]
I did the same with models, my models has it's own dir, because it's over 50 them in there, and those files are not small - about 150 lines each.. Even these files have few models inside.. so I'm just doing something like :
from myapp.models.mymodel import *
and there are some places where I just doing: from myapp.models import *
[init.py of myapp/imports dir takes place in here]
Problems:
1) ok so first problem is namespace, this kind of model importing is maybe really ridiculous.. but decision with views and forms, is just nothing but lazziness to open one more tab in your IDE
2) performance problem? my co-worker really arguing a lot with this argument, that "every import takes 256kb of ram"?? (by running compiled .pyc file? no i don't believe that ;)
The question in fact is about performance problem because of imports.
p.s. I'm really new in python (just 3 month), and I open to OBJECTIVE arguments for all probs and cons about this solution.
UPDATE
Once I asked question about how to move imports to standalone file so nobody complained about this =) question is here