Ask YC: Should I use a framework or just write the code myself?
Do YCers here have experience with or without a framework? What would you choose?
Do YCers here have experience with or without a framework? What would you choose?
There are certain things you need for every project: -ways to handle configuration files for different environments -a pattern to map URL's to methods and templates -a basic ORM so you don't have to write SQL for every single CRUD operation -a test framework that simulates an actual web request -a way to handle SQL migrations -a way to get data to and from forms
Almost every production web site needs all of the above. Why spend time doing it yourself when people have solved these problems already? The only reason I can see for writing your own framework is as a pure learning experience.
I'd say it's mostly based on personal preference. If you don't use a framework, you will end up reinventing a lot of stuff that's in mainstream frameworks. OTOH, the stuff you spend reinventing really won't take you much longer than learning the framework, as long as you build off a decent set of libraries (don't try to reinvent your own templating-library/HTML-escaping/database-interface etc.) And if you do switch to a framework, you'll probably be better able to understand the reasoning behind why the framework did what it did.
One other consideration: frameworks make it much easier for somebody new to get up-to-speed with your code, and often tackle thorny deployment issues that you can spend a lot of time on otherwise. Keep that in mind when deciding - for a startup, the priority is to get something up on screen so you can see if you're on the right track, but you do eventually want to be able to grow and scale.
One thing that bothers me in a lot of frameworks is the object wrapping of the database. I can't see much justification for this, it just seems to be adding a layer of complexity on top of a very clearly designed model. How much easier is it to use an object abstraction when you could just do SQL directly?
John.
(ymmv. If you eat, sleep, think, dream, and make love in SQL, I guess you might as well ditch the ORM)
One -- I might want my data to live in multiple places. For instance, I had an app I wrote recently that could persist its data to and from three places -- SQL, a funky XML format, and a private file format. That's too much read/write crap to pollute my app with.
Two -- I might want my data to live in multiple versions. If you've got multiple versions of your data format out there, such as if you were Quicken or something, you want to change/modify the data code in one spot, not all over the place.
Three -- the job of writing the UI is different than the job of knowing about data. Whether it's one box or ten thousand, one table or five, why should I care/know where the data lives? I'm writing the UI for goodness sakes. Just make the stupid stuff go away and come back when I need it. One well-constructed data tier should be able to service a hundred UI developers.
When coding imperatively and using a "short-cut" data access paradigm like RoR or CodeSmith and NetTiers (my favorite), the temptation is to start thinking well gee, if every table is an object, what's the point? Why not just hit the database directly? The answer is that you're coding just using a big shortcut -- it ain't going to work all the time like that. You have to know why the shortcut works and why it doesn't work.
However, being able to rapidly deploy a prototype has been priceless time and time again, and they have the basics that you need down and well tested.
If you don't like ORM, or find yourself writing a lot of custom queries for performance, that is fine. I would still use an ORM now and customize some queries for performance later. The reason? Speed of building your app...I think not writing the DB code saves me about 20% of my time.
I used to be always against using frameworks since they were massive, crappy, and relied on so much magic you didn't know what was going on behind the scenes. I am really glad I went with Django, it saved me from writing almost the identical feature set.
John.
It is especially good about allowing random people to contribute pieces of code that are useful. I also like how their goal is to make everything as straightforward as possible, and eliminate the 'magic' that most frameworks have. If you have any questions about it, feel free to ask.
One of the nice things about Django is that it's just Python. You can always look at the import statements in a module to see exactly what code is being run and where it's coming from. I've never used Ruby on Rails, but I have the impression it can be opaque in this area. ("Just create a file named makeasite.rb and put the single word 'create' in it, and Rails will do the rest!")
Personally, I'm vehemently against "magic" in a framework / programming environment, which is one of the reasons I love Python -- and one of the reasons we don't have a lot of magic in Django.
Let me know if you have any specific questions.
Adrian (Django cocreator / core developer)
While we are on the topic, I have always wondered why the Django team insists on being an MTV (Model Template View) framework..don't you guys think just conforming to MVC would make life easier for people new to Django? (This is a serious question)
The problem with relying on magic is that you won't know what to do when it stops working.
Maybe if it's always just select "star" instead of select object, the difference is not so great, but if you can't use select * for some reason, it becomes unbearable for me...
Also, the automatic loading of linked objects and collections, and the caching, are nice features imo. You only have to write object.getMappedThingies() instead of another SQL request (talking about Java here).
It really depends on what you're doing, but I can't imagine why anyone would want to write SQL by hand. If you really want simplicity, don't use a database at all.
I moved from PHP/PearDB to Java/Hibernate3.0 to Python/DBAPI, and found that Java was by far the most verbose. Even with Hibernate annotations, I was writing more than twice as much code for equivalent functionality.
Perhaps the difference is that you have business objects defined already, and so the cost of Hibernate is only the annotations? My PHP and Python programs keep the SQL and drop the objects, and so they end up with incredibly tiny data access layers.
SQL is optimized for writing data access queries extremely concisely, so I don't see how it could end up as more than 50% of the codebase, unless you're using an exceptionally verbose database library (JDBC certainly counts) or your codebase is exceptionally tiny.
This was an extreme case of course, and was mostly the result of bad design, but I haven't come across a database backed application that couldn't be trimmed down with some sort of SQL generator. SQL is fine for simple queries, but, for me at least, has always gotten unmanageable in the long term. Need to select, insert and update the same columns? Duplication. Conditionally group by or order by different fields? Duplication. Decide after the fact that you need to support multiple databases, or eager and lazy loading? There goes the weekend, and probably most of next week.
You could manage all of the above with some sort of home grown solution, but a good ORM just makes everything so painless. I was strongly anti-database for years, yet I now often find myself using ActiveRecord when a flat file would do, simply because ActiveRecord is easier.
Of course, that's just me. SQL and I were never a good fit, and I'm glad to be mostly rid of it, but I'm sure others have had different experiences.
I used the same library with web.py. Web.py's built-in database library is pretty impractical. Global DB connection means it's very difficult to do testing/mockobjects, and it wouldn't scale beyond one machine.
Frameworks are great if you do a series of similar, straightforward projects like many contractors would do. A framework allows people to get acquainted with your code more quickly, so it's good for companies with high staff turnover. It also has a name that HR can put in a job ad.
If you roll your own, try to do it as a collection of independent libraries, not as a don't-call-us-we-call-you type of framework. That's my conclusion after many attempts at framework writing. It has always been the case that some parts were good and others were crap. You can't throw the crap out if everything is interconnected. The code that connects everything needs to be either the smallest part of the framework or part of the application itself.
But anyway, as long as you stay away from CMS, you're going to be fine.
In general whichever framework you would like to use, will have its own learning curve. Once you overcome that, it should be pretty easy and fast to start working. I think there are some obvious advantages in using a framework:
1- you don't have to reinvent a lot of the stuff
2- the solutions offered to you have passed all their tests as there are many people checking upon them, and many sites already using them
3- if you have a couple of ideas and are thinking of launching all, I think once you finish your first project you will see a huge advantage starting the other ones, and you will move a lot faster
at the end if you pick the right framework, that will satisfy your current needs (the features and options you like to offer) and future needs (such as scalability), you will feel like you are working with a huge group of developers on your site. Its kind of like you have hired other developers and formed a team for yourself.
Also make sure that the framework you pick will have a strong community as it will come handy.
You should make a list of your requirements and make a chart of the frameworks and which ones satisfy what. And in general I would take the following into consideration when choosing a framework (depending on your needs you could add to this list)
- Ease to install - Learning Curve - User Control - Session Control - Extensibility - Scalability - Themability - xHTML/CSS
You'll keep yourself from reinventing the wheel, yet you won't limit yourself on capability by conforming to an obscure set of rules and development practices.
I am not sure how much work it is to create one's own framework, but I suspect it is less than one might think. The hardest part to me seems serious OR mapping+caching.
Personally, I would probably go the same route as Groovy on Grails and build on top of Spring+Hibernate (so leverage existing frameworks, but in my own style).
Also, I don't know any programmers who became famous for using other people's frameworks.
It doesn't have to be a balanced coin: I like Ruby, so my coin was biased toward Rails. Ergo, I learned Rails, and will probably go on to play with Merb and Camping.
Meanwhile, very smart people assure me that Python is nice, and I hope to learn it before I die.
The important thing is to just get moving. Deciding between Rails and, say, Drupal is complicated, with lots of technical, marketing, and business factors in play. But RoR, Django, and the gang are so much alike that the decision comes down to that simple coin flip.
http://uint32t.blogspot.com/2007/11/web-programming-framewor...
John.
- It does not offer an out of box solution to allow authenticated users to create content forming pages as part of a Web site. It offers you a web app framework and you could build upon it your custom CMS from scratch (and it will take you longer to do so)
- but there is a nice binding to the database through the framework
- at the time stability was a bit of an issue!
with all that said there are great applications built upon it such as 37Signals Base Camp
also if you mean built on CMS out of the box, I don't either, and you will have to customize it in order to make something useful, but the point is that with RoR you have to pretty much build from scratch whereas with other CMS like Drupal you already have many functionalities included in the core and you don't have to really reinvent many things, you just customize or add the ones you want