Question for Rails and Django users: is there a site that gives definitive best practices for both? I've actually been thinking about building a thrown-together site for just that purpose.
I've tried to get into both Rails and Django twice now (I'm a PHP guy usually), but every time I seem to get going, I get bogged down by StackOverflow after StackOverflow that have seemingly contradictory information or offer a third party solution rather than solving the problem within the framework.
In Rails, for example, Rails is easy enough, until you're dealing with RVM * , Passenger * , and installing correct dev versions of database drivers.
In Django, you deal with South migrations when you want to update your database schemas, virtualenv * , virtualenvwrapper * ; in fact, I've heard that one of the criticisms of Django is that, in order to get to production quality, you essentially have to switch out every component of it with a third party.
* The starred apps don't technically have anything to do with the framework; they're more utilities for managing multiple framework instances. Still, you're likely to find tutorials that use them as a de facto standard, which only adds to noob confusion.
I've started reading Michael Hartl's Rails tutorial, which seems promising. I found that the highly-recommended "Two Scoops of Django" book was a little too narrative for me (just tell me what to do, dammit!); there's definitely a need for more Django tutorials than just the Django website's basic one -- kudos to the author for that.
One thing that Django suffers from is having a long history which means that old best-practices (which no longer are best practices) still float around on blogs and it's hard to know what is what. I understand that the fact that so many people swap out core components with 3rd party libs can make it confusing, but I would disagree that in order to get to production quality it is required. I would even recommend avoiding swapping out core pieces whenever possible and work within the framework.
As I said in the original comment, I didn't find Two Scoops to be effective. It's woefully indirect and is itself riddled with digressions about third party libraries. I just want a list of what to install and why so that I don't have to constantly backtrack.
As one of the authors, I'm not sure what to say to this. I would honestly love to get your feedback.
Just so you know, when the book was more direct we had reviewers saying it was too direct and they wanted more flavor text. Our answer was an appendix of libraries in the back that listed all the recommended packages. Perhaps we should point readers to that earlier?
Also, if you are using Django, using third-party libraries is part of using Django. We feel this is a good thing because you don't want critical libraries standing still waiting for the next major Django release (a roughly yearly event). A good example is OAuth authentication - if Facebook or Twitter changes it's methods, you can upgrade to the latest django-social-auth or django-allauth and expect things to work.
However, as I said, I would love to hear more detailed feedback. That way we can make the book better. :-)
Thanks for the reply! I'd love to go more in-depth with my critique. Keep in mind that, while I'm new to Django and Python, I've worked with PHP, Java, C++, C, and Objective-C for years. I'm familiar with writing reusable code and how to write code that is able to be read by others. I'm also an OOP fanatic, so I'm already on board with most of the conventions that are suggested by most frameworks like Django and Rails. My previous experience with Django was going through the official Django tutorial.
So, while I may be a weird outlier (not a beginner, but I only have a basic understanding of Python), I felt that the book was never really written for me. It lacks an authoritative tone that I want in a "best practices" manual, and the fact that the book spends so much time explaining why best practices are important really made me think that the book was meant for programming beginners. Paradoxically, the book will then randomly drop in a Python package or two without explanation and expect me to know what it is.
Here are some examples:
Using explicit relative imports -- The section explains why explicit relative imports are good. Fair enough. Then, the book provides an example of "bad code" with "implicit relative imports". Keep in mind that you still haven't defined "explicit relative imports." Then, you explain how un-portable and un-reusable these "hard coded" imports are. After that, you convert the snippet to "explicit relative imports". Still no definition. From here, I try to compare the two snippets. Did the authors really spend 2 pages explaining a "best practice" that could easily fixed by just omitting the package name? I honestly thought I was missing something. Then, the fact that "implicit" relative imports had more code than "explicit" relative imports really started messing with my head, so I decided to move on.
Chapter 2
Fixtures -- I wasn't wondering why we weren't using fixtures because I had no idea what they were (they weren't covered in the tutorial). Simply defining fixtures would help here.
The rest of the chapter was all info that applies to every language and isn't specific to Django (dev and prod should be identical, use git, etc.), so I wasn't really getting much out of the chapter.
Chapter 3
Other Alternatives -- why?! I'm trusting you with my life here! Tell me what to do! I am yours to mold into a brilliant Django developer!
Chapter 6
Model managers -- This is where the narrative style really lead to ambiguity for me. Example 6.6 isn't labeled as a BAD EXAMPLE, yet you lead into it with a rhetorical question. My e-reader happened split the page right after the example, so if I had stopped reading there (which is common for me with reference books), I may have not seen that, on the next page, you explain that Example 6.6 is an example of what not to do.
General
My problem getting acclimated to Django isn't the third party libraries necessarily; it's more my lack of knowledge about them at all. Throughout the book, there are tips for libraries to add to Django, but there's hardly ever a thorough explanation or description of the product, just that you think it's important.
Hope that helps! Just in case it needs to be said: none of this is an attack on you at all; I totally appreciate the work that went into this book. Thanks for listening to feedback and let me know if you have any other questions!
If I might make a suggestion, I think a lot of these problems would have been solved by reading the Django project docs before Two Scoops. Unlike many open source projects, Django's docs are of extremely high quality. Their main shortcoming is that while they tell you a great deal about what Django's pieces are and how they work, it leaves out a lot of practical usage stuff. That's where Two Scoops picks up. To me it's less of a book for a pure beginner and more so intended for turning someone who knows the basics into someone who can deploy a real site into production.
That's a fair point. I went through the tutorial and totally overlooked the rest of the docs (with the exception of the ones that I needed). Even still, I think Two Scoops could be a lot more concise and spend less time focusing on why and more time focusing on how. Best practices are means to an end; if someone's reading a book about them, chances are that they're aware of the benefits of following best practices anyway and don't need the constant reminder of why portable, readable code is important.
If you are planning to enter Django world, it's always good to know Python well.
The Hitchhiker’s Guide to Python![1] explains a number of Python related things which beginners(in my experience and opinion) generally either tend to overlook. You do not need to read it all at once. Chapters can almost be read independently and in no particular order.
Secondly, go through Python Ecosystem - An Introduction[2](shameless plug) once. .
> in fact, I've heard that one of the criticisms of Django is that, in order to get to production quality, you essentially have to switch out every component of it with a third party.
This is not necessarily true. Everything in Django is production quality as you will see in several sites in the wild (including the very first Django sites).
No framework will give you the most optimal set of components for every possible scenario. In most cases Django components are swapped out for performance reasons, especially when they are high traffic sites. In other cases, it is due to the NIH syndrome where almost every component has been homegrown (perhaps trying to become more standalone).
> in fact, I've heard that one of the criticisms of Django is that, in order to get to production quality, you essentially have to switch out every component of it with a third party.
where did you hear that? its outright non-sense. everything that ships with django is good enough for production right out of the box.
Hartl's Rails tutorial is comprehensive, but does not spend enough time explaining the underlying principles IMO. Writing a test for everything also muddies the water in that tutorial (which does not mean TDD is not good for you).
Which underlying principles do you have in mind? I might use any suggestions you have to augment the next edition.
By the way, though the feedback on the inclusion of TDD has generally been positive, it can get tedious, even for me. I do hope to produce a simpler, test-free Rails intro at some point as a complement to the present tutorial.
I don't agree with that. I'd say don't worry about south if you're just starting out playing with django and willing to manually delete tables every now and then to get make sure your db matches your models.
As soon as you are doing something that anyone relies on and to save you endless effort you should use South, IMO. Even if it's a one-person project (I have a few of those) South saves you both a lot of time and aggravation.
Absolutely agree. Even something as simple as adding an optional field is just ./manage.py schemamigration --auto <appname> and you're done vs "ALTER TABLE blah blah blah...." on your local system, dev/staging, and then again on production in the right order, every time, manually. Can't imagine anyone wanting to go back to manual after using South.
Welcome to development with open source technology. It takes time and effort to figure out the best practices. There is no magic bullet, sorry. That's not meant to be snarky it's just the way the process works.
Definitely not good advice, regardless of what language or framework you're working with. If there's a solid migration tool available, it is definitely better to use it.
Aside from being a great habit to get into, South (or whatever other migration tool you want to use) will keep your database consistent and predictable to the framework. If you add or alter columns on your own, you run the risk of slight differences between what you've done and what the framework would've done left to its own devices. You may not have done anything wrong, but you don't want that inconsistency.
Migrations are going to be a core feature (quite similar to Ruby on Rails) from Django 1.7, and I personally find it more convenient. Eventually you will need to use migrations anyway.
I honestly find South to be the easiest and most efficient way to make model changes even on a solo project.
The biggest upside to it is that it fully documents all of your chances, and even allows rollbacks if necessary. Editing the database directly doesn't give you any kind of change log unless you do it manually, which is not really sustainable, even while working solo.
>they're more utilities for managing multiple framework instances. Still, you're likely to find tutorials that use them as a de facto standard, which only adds to noob confusion.
That sounds more like a problem of php. Tools like composer should be more widespread and when they are switching to virtualenv probably isn't going to be so much of a hassle.
I've tried to get into both Rails and Django twice now (I'm a PHP guy usually), but every time I seem to get going, I get bogged down by StackOverflow after StackOverflow that have seemingly contradictory information or offer a third party solution rather than solving the problem within the framework.
In Rails, for example, Rails is easy enough, until you're dealing with RVM * , Passenger * , and installing correct dev versions of database drivers.
In Django, you deal with South migrations when you want to update your database schemas, virtualenv * , virtualenvwrapper * ; in fact, I've heard that one of the criticisms of Django is that, in order to get to production quality, you essentially have to switch out every component of it with a third party.
* The starred apps don't technically have anything to do with the framework; they're more utilities for managing multiple framework instances. Still, you're likely to find tutorials that use them as a de facto standard, which only adds to noob confusion.
I've started reading Michael Hartl's Rails tutorial, which seems promising. I found that the highly-recommended "Two Scoops of Django" book was a little too narrative for me (just tell me what to do, dammit!); there's definitely a need for more Django tutorials than just the Django website's basic one -- kudos to the author for that.