Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Another Django v Rails question - Which is better for complex webapps? [closed]

I know that there are hundreds of pages written on Django v Rails, but I've been searching for a few days trying to get opinions on a few more subtle points in the debate with no luck, so I thought I'd ask here. I have almost no experience with either framework, but am currently leaning towards Django because of its documentation, speed, and my love for python.

  • Which one is better for quick and maintainable development of complex webapps? I'm not talking about a 'plane-jane' website, but a complicated desktop application-esque webapp. I hear that Python is more performant than Ruby and I also hear that the learning curve in Rails is such that I'll spend a lot of later hours refactoring out newbie mistakes after the webapp progresses beyond simple CRUD. This could be combatted by hiring experienced Rails developers, however.

  • Is there a perception that Rails apps are often more beautiful than Django apps? I know that whether an application is beautiful is not dependent on the framework behind it (case in point mint.com), but this is just a feeling I get and I was wondering if there was any validity to it.

  • Is one easier to deploy than the other? I've deployed a few Rails apps on Apache with some trouble, but never tried to deploy a Django app. I've been thinking about providing potential users with a downloadable executable that would set up a small webserver and deploy the app locally so that they could test it on their own machine before deploying it on their servers - are there tools that make that easier with either framework?

  • Which has better database libraries/ORM? I know that things are pretty simple if I go the NoSQL route, but if I decide to use a relational database, is one framework better than the other?

like image 585
DLaw Avatar asked Mar 06 '11 20:03

DLaw


1 Answers

I'm going to warn you up-front that I'm a Django developer that keeps modest tabs on Rails' development and I've never had to develop or maintain a complex Rails application, so I'm going to focus on the strengths of Django and what I know about Rails' design philosophy, so I welcome experienced Rails users to challenge and correct any wrong assumptions I'm about to make.

Which one is better for quick and maintainable development of complex webapps?

Django has a fantastic layer of modularization that is implemented through Django apps. Your project is nothing more than a Django instance composed of a root URL configuration and a settings file, that serve the main purpose of hooking Django apps into your instance.

Django apps themselves are Python packages, that are by Django's design, meant to be packaged for distribution completely independent of a Django instance and that was initially why I picked up Django. They encapsulate all of the discrete components (models, templates, URL patterns, views, forms, etc.) necessary for providing a certain feature (this app supports user registration; that app provides user authentication; this one is for managing user profiles; this one servers static pages dynamically from the database; this app can take any image, convert it to an RGB JPEG, resize it and upload it to a local path, S3 or to some FTP server) and your encouraged to have a lot of different Django applications to simplify your application structure.

To put it bluntly, in Rails it would be as if your application is solely composed of separate Rails plugins. The Rails architecture encourages people to have a huge app/ structure, where all of the components for a feature are kept separate and collocated together with similar components from other features, and distribute 3rd party code together with their Rails application in vendors/, whereas Django enforces Django apps to be shoulder-to-shoulder top-level packages, be they your instance specific apps or 3rd party apps, that can be independently redistributed and reused across several Django instances in the same environment, wholly encapsulating data fixtures, their own templates, static media, translations, test code, models, views and controllers and their intermediary components.

For instance, take a look at the repository of these two big projects, Zamboni and Redmine. All of Zamboni's application code resides within several dozen Django apps and just by reading the package (folder) names of each, you can see it's obvious that they document where certain parts (features) of the Web application are located and all the code pertaining to that feature is encapsulated within the app. Compare that with Redmine, where a feature's components are kept separate and mixed with other components in predefined directories. You have to do a lot of navigation within and across different directories when your exploring or developing Redmine's Wiki feature and that makes it harder to get a holistic view on everything the Wiki feature provides.

This is just my personal opinion that Django has a better architectural premise for developing and maintaining large code bases.

Is there a perception that Rails apps are more beautiful than Django apps?

As far as I can tell, personal preferences aside, both have a clean architectural design. If you follow the conventions and employ the same patterns as your framework does for solving similar problems, your apps should both look and feel beautiful to other framework developers.

So this in part also answers the point people said about the difficult learning curve of Rails, which I believe holds true for Django just as well. Both have a difficult learning curve in that it takes time to understand the basic philosophy and designs of your framework to design and develop beautiful applications that go with, not against the framework. By beautiful I mean that it becomes very natural to discover where a certain feature is implemented, or more discretely, it's data, presentation and behavior and that it's very obvious where new features should be added and how they interact with existing components.

But until you don't have a well founded understanding of your framework to fully appreciate it, you'll most likely take up on novel approaches that extensively configure and customize the framework experience for other developers. I think the only newbie mistake you can make in Rails and Django is to do something that works, but has a very fragile and unintuitive design, something that either goes against documented and proven approaches in an unfashionable manner or otherwise ignores basic framework principles.

Is one easier to deploy than the other?

No, both provide tools for easy packaging and deployment. There are a lot of Ruby and Python Web servers out there in the wild that make deployment a breeze, although I can see most people still deploy their apps for Apache, which is a whole lot of bang for something that's likely to be used solely for instancing and interfacing with your Rails or Django app, so I understand where some of the pain is coming from.

Which has better database libraries/ORM?

Rails and Django diverge on their perception of the database schema. Rails takes your existing schema and maps it to application logic, while Django takes your existing application logic and maps it to a schema. Both have never prevented anyone from building complex applications.

In Rails, your models bubble up from the schema, while in Django your schema bubbles up from the models. I haven't found this mentioned anywhere, but it's very reminiscent of the naked objects pattern, i.e. domain object attributes are not just dumb data holders. The models API facilitates a complete understanding of your data, because each model field is an instance of a complex, reusable and customizable field class that provides the business logic and the presentation for the data. Effectively, Django models can provide complex inheritance scenarios, their schema, manage impedance mismatch and provide the presentation for populating model data through HTML forms and an administrative backend.

The scaffolding in Rails is pretty much a throwaway, it's there to provide the basic CRUD until your provide your own complex presentation and behavior. Django has the admin that introspects your model and dynamically provides an elaborate interface for managing your model data that can be extensively customized through ModelAdmin objects. Even though you'll never provide non-staff users with access to the admin backend and will always have to design CRUD access within your Web site front presentation for other community users, you'll always use it to provide access to your data for users with elevated permissions. Basically, you can describe a model with a few lines and have a full-fledged, production ready interface for managing your domain objects.

The models are the focal point for any data, presentation and behavior triad and make it very easy to develop complex applications. Truth be told, since Django's models are more explicit, it makes it that much harder to customize the assumptions an application has about it's model data. This is never a problem until you start working with 3rd party Django apps, because once they ship a model that says a city's name can only be 72 characters long, your stuck with that. Django is shipping class based generic controllers in the current preview release that's due for a public release shortly, which should provide a much cleaner interface for customizing model interaction at the level of the controller. This should quickly streamline how people can extend and override the logic of 3rd party apps to abstract the assumptions about model data.

Conclusion

Frankly, I just can't see how you can go wrong with either. Rails is indisputably the more popular choice in the wider developer community right now, but I'd believe it should be a purely personal choice which of the two you take, based on the amount of joy you get as a developer from one over the other. At this point, their design and feature set is mature enough to make it possible to do anything you need with both, regardless of how you accomplish it.

That would perhaps only leave you with having to judge the human resource and 3rd party solution pool. Though you can find more Python developers than Ruby developers, you'll surely find more Rails developers than Django developers. Django has picked up enough interest by now that you can find a Django application for anything you need, something Rails has been more established with; as far as languages go, you'll also find a native solution for anything you need in Ruby, something Python is more established with. I think you safely exclude native and framework 3rd party solutions out of the equation when making your choice.

like image 65
Filip Dupanović Avatar answered Sep 18 '22 02:09

Filip Dupanović