4 ms·
I think that comes down to how comfortable you are with classes and multiple inheritance and whatnot. Django is a shining example of how to do these things righ
by dec0dedab0de 3y ago
I think that comes down to how comfortable you are with classes and multiple inheritance and whatnot. Django is a shining example of how to do these things right, but yes it can be a bit daunting if you're not used to them.
But in my experience, FBVs become a mess even if they're relatively simple, because of the temptation to keep it all within a single function. If you take the time to break things down into separate functions and try to keep it dry, while passing around the related objects then FBVs are ok, but then you're basically recreating classes.
In any case, my point is that function or class views should never be complicated, they should just be taking a request, and returning an appropriate object. If the process for creating the appropriate object is complex, that should be handled outside the view.
Oh and my use of the phrase "you're doing it wrong" is kind of tongue in cheek, and comes from my time doing tech support in my early 20s, where we all thought it was hilariously unhelpful. I agree it's a bit obnoxious, I almost edited it out last night. But I made myself giggle enough that I left it in.
- hitchstory 3y ago>I think that comes down to how comfortable you are with classes and multiple inheritance and what No, not really. Multiple layers of inheritance naturally causes code to lose cohesion no matter how familiar you are with it. It's one of the reasons for the maxim "prefer composition over inheritance". >But in my experience, FBVs become a mess even if they're relatively simple, because of the temptation to keep it all within a single function. If calling functions or classes from within functions is a struggle I dare say you might have bigger problems than whether to use FBVs or CBVs.
- dec0dedab0de 3y agoPreferring composition over inheritance is good for languages that don't do inheritance well. Python does it well. But more importantly, Django is an object oriented framework that makes heavy use of multiple inheritance, and the code is gorgeous. It seems silly to choose a big framework like Django and not take advantage of it's features.