Live data from Hacker News

Lessons learned defying Joel Spolsky with Django

speakerdeck.com

81–90 of 155 posts

Re: Lessons learned defying Joel Spolsky with Django

#81
post #54

I didn't understand why ORMs are stupid. Can someone enlighten me?

ORMs pretend to give you full abstraction, but in reality you have to be aware of the underlying SQL layer when you build your object model.

I find that if you are aware of the SQL underneath, they are good for saving time.

Do you really want to write SQL to retrieve data and code to populate an object for every damn thing in your system?

Re: Lessons learned defying Joel Spolsky with Django

#82
post #4

Don't use just one ORM and then declare "ORM's are stupid". The "object = None" / "object_id = None" issue illustrated here is certainly not a mistake every ORM makes.

Obviously there are subtleties to things that may not be apparent, but his example makes sense to me and so does the SQL queries that are generated. The first query is operating at the "object level" and the second is operating at the "attribute level".

The first is retrieving the object and checking if it exists, and the second is just checking the parent's foreign key. Not sure that they are really the same query, if you have unenforced foreign keys.

This is not "dumb", this is analogous to checking if a pointer is null or that the contents of the pointer are null (which is a distinction that some people want to make).

Re: Lessons learned defying Joel Spolsky with Django

#83
post #54

I didn't understand why ORMs are stupid. Can someone enlighten me?

The real issue with ORMs isn't the ORM itself, but over reliance on the ORM to do everything the right way and not validating the ORM is doing things the right way. ORMs are also often heavily leaned on by people who don't understand SQL and relational databases well enough and just want a data dumping ground (would have been better off with a document database).

But, if properly validated, and knowing when to NOT use the ORM, a good ORM can help you get a lot of work done very efficiently. But I've also seen improperly used ORMs turn into MASSIVE time sinks where devs spends days just configuring the stupid thing (hello Hibernate/nhibernate).

Re: Lessons learned defying Joel Spolsky with Django

#84
I don't think Spolsky's argument applies to startups... His argument basically boils down to "You think the code in front of you is a mess, but the reality is you're just having trouble reading somebody else's code which is probably good enough". But what if you wrote the code yourself? In that case, it's probably just a mess.

Re: Lessons learned defying Joel Spolsky with Django

#85

Earlier quoted context omitted.

ORMs pretend to give you full abstraction, but in reality you have to be aware of the underlying SQL layer when you build your object model.

I find that if you are aware of the SQL underneath, they are good for saving time. Do you really want to write SQL to retrieve data and code to populate an object for every damn thing in your system?

I agree. Problems happen if you treat ORMs as a total blackbox.

Re: Lessons learned defying Joel Spolsky with Django

#86
post #18

Earlier quoted context omitted.

You're contradicting yourself. Your first comment indicates that it's wrong to label ORMs as "stupid". Yet in this latest comment, you've labeled all software (which includes ORMs, of course) as "stupid". Like the other commenter requested, can you provide an example of an ORM that isn't "stupid"? Your initial comment makes it sound like you've worked with at least one that isn't. We're curious to learn about which t…

The word "stupid" here is ambiguous, so can be interpreted as, "stupid", "it's stupid to use them" (I disagree), or "stupid", "they don't necessarily understand your intent" (this applies to all software), "stupid", "simple issues are made more complicated than they should be, to an unreasonable extent" (this is a problem that varies to a significant degree based on the ORM in use and cannot be generalized based on t…

The problem with ORMs seems to be that they're a leaky abstraction. I've been very happy using SQLAlchemy for quite a while now, but I'm intentionally only using the SQL Expression API. Based on my experience with Hibernate, there's always something you want to accomplish that necessitates circumventing your ORM.

Not only that, but typically you end up balancing between stuff being unavailable because of lazy-loading, and one pageview taking 30 seconds because the ORM collected all the dependencies.

Re: Lessons learned defying Joel Spolsky with Django

#87
post #70

Earlier quoted context omitted.

So the ORM is too stupid to know that in the case the other_id is NULL, it doesn't need to create a join subquery. But would you rather the PostgreSQL query planner figure this out or do it yourself in python? I would like to see the time difference both queries take, and I don't think I would want Django ORM to do this.

I think you should run EXPLAIN ANALYZE on both queries and see what you find.

I now understand that it won't be optimized away because it's doing something, and I think I still want it to do that something. I've run into plenty of ORM limitations and use custom SQL for procedures and custom joints, but I still wouldn't call Django ORM stupid for doing what it's doing, in this case.

Re: Lessons learned defying Joel Spolsky with Django

#88
post #75
post #26

Earlier quoted context omitted.

Middlewares, context processors, forms, (class based) views, and tons of third party applications. The CTO of a startup where some friends are working thought the same you did, and 2 years ago rewrote everything to Flask. Now they're going back to Django. Django is much more that an ORM and templates.

Django middlewares is a poorly designed system. Flask has all of the things you mentioned except for forms. For that you can use Flask-WTF, but these libraries are becoming outdated anyway because they’re HTML based and don’t work so well for JSON validation.

Could you please explain why do you think that? IMHO it's a really clever approach.

Re: Lessons learned defying Joel Spolsky with Django

#89
post #15

Earlier quoted context omitted.

Why not just write the SQL?

The only problem I see, is we can't rewrite SQL. I.e., in pseudocode: query = SQL("SELECT * FROM entities WHERE owner = ?", owner=me) ... if some_condition: query = query + SQL.WHERE("OR public = TRUE") ... if other_condition: query = query + SQL("LEFT JOIN things AS t" " ON t.entity_id = entities.id") \ + SQL.WHERE("things.value > 0") ... my_nice_list_of_results = run(query + SQL("LIMIT ?", count)) This should be te…

There are libraries which build up a model of a query - selections, constraints, etc, and only turn it into a string at the point of executing it.

SQLAlchemy was already mentioned. In the JavaScript world, there's node-sql. https://github.com/brianc/node-sql

Re: Lessons learned defying Joel Spolsky with Django

#90
post #11

Earlier quoted context omitted.

Agreed, I for one was felt feeling rather in the dark for the last few slides especially...

We are posting a version with audio on our blog on Monday: http://blog.iconfinder.com

I look forward to it!

Only audio, no video?

Post reply on HN