Lessons learned from web development with Django

Django is a web development framework for Python. I used it for a few web sites, including a relatively large one. I must say, my overall impression is rather ambivalent.

First of all, Django is definitely excels when you need stuff done, quickly. A lot of stuff simply works out of the box or with minimum effort, including DB access and ORM, caching, templating and so on. And there are so many extensions available! Probably only some PHP frameworks have more plugins and extensions, but who wants to write in PHP for a living?

On the other hand, writing large projects in Python, or any scripting and dynamically typed language is hard. Of course, it is hard no matter what technology you use. But with Python, heavy refactoring might be a serious nightmare. Which brings is to an important point - you must have lots of tests! Of course, any sane programmer will have a lot of tests no matter what is the language for the project. However, in case of Django/Python your tests will pick up some of the burden which with the statically typed languages is handled by the compiler. Also, despite the reasonably good documentation, it is not always clear how a certain thing works or, more often than not, why something doesn't work. The main remedy is examining the source code of Django or third party extension, which I have been doing rather often. This can, naturally, happen with a framework written in any other language, of course.

That said, what are the alternatives? Play Framework sounds like a great option. I am a fan of Scala (not so much of pure Java), and it seems to have reasonable design guidelines. Alternatively, ASP.NET Core is a solid offering with a promising future. However, there are considerably fewer extensions available for either of them! So if you want to create a shopping web site with an CMS and a forum, you can whip something working up in a matter of days, if not hours. You will be using rather solid extensions, fully open source, and with large user bases, meaning support and stability. With Play! or ASP.NET you will have to write more custom code, or rely on half baked coding summer projects, or pay for commercial products.

So, for the time being I'll continue working with Django and wait for other frameworks to mature.

Comments

I'm curious about your path from looking at C++ as a web framework - to Django. I find myself horrified at Python in general - and Django in particular and am looking at C++ as a possible solution. I want compile-time errors and memory control. I do not want to have to scale out to AWS because it is impossible to build a large enough data-centre to keep up with Python apps. I am tired of writing "temporary" code - code that might be valid today, but when Python 4 comes out will all be obsolete again. I want to be able to BUILD IT ONCE, not forever.
Did you ever evaluate WT, and later on, WT Designer? I'm not clear if these projects are still viable, but I'd sure like to hear if you have given them a shot.

Well, the problem is that I never did any substantial web development in C++. Why? Because there are not that many convenient libraries/frameworks for C++. It's that simple. (I didn't use Wt, but at a glance it seems that it's rather small and not that many features). As opposed to that, Django comes with so many things out of the box, that you get a very considerable leg up from the start. Think about ORM including migrations, session management, caching, templates, security, forms, management script etc etc. There are also a lot of third party modules to provide additional functionality, almost anything you can think of! From ready made CMS, social authentication, forums etc.

Now, I very much feel you with regards to static typing/compilation, I most certainly love these things myself. But again, no large framework for C++, so I'd have to write all this stuff myself, and that is a lot of work. My main goal is a pragmatic one - to have a working product. That said, there are some alternatives to Django which are closer to what you might find more acceptable - something like Play Framework (Java/Scala) or ASP.NET core (C# or even F#). Unfortunately, you'd be surprised, how many more third party modules there are for Django than for both of those put together.

Regarding Python 4 - I think we are like 10 years away from it, given the experience of Python 3 :) And hopefully, there will be much easier transition than from 2 to 3.

As performance goes, I would say this shouldn't be a huge worry. If your site is a "regular" one, than things like SQL queries will be a much heavier burden on your requests than any difference between C++ and Python. So, caching and query optimisation will have much stronger impact on the performance. And if you do discover that Python is the bottleneck, then either check out cython, or even rewrite the critical session in C++ (quite easy with python).

To sum up, Python is not the best choice as a language from my personal point of view, but the feature rich framework and the niche around Django make it a good option when you need to do shit done quickly and with limited development resources.

Add new comment