Hacker Newsnew | past | comments | ask | show | jobs | submit | kitsune_'s commentslogin

The ORM is really not good in my opinion because it is ActiveRecord'ish and has all its downsides. I wouldn't use Django for any moderately complex domain. But even with simpler CRUD style apps I don't really see the point in it.


The one thing I really appreciate with the ORM is that you really can get the ORM to make... more or less any sort of SQL query you want.

It can take a while to wrap your head around what fields get used in aggregates and the like, but when working with big models with like 65 fields and juggling a bunch of stuff, not having to futz with serialization/deserialization and "just" expressing your problem in the dumb way is nice.

I want to say this all comes back to bite you in the end but honestly it's more just having wide tables that comes to bite you. A service layer wouldn't really save you. Meanwhile you save yourself a bunch of tedium in the mean time


> The one thing I really appreciate with the ORM is that you really can get the ORM to make... more or less any sort of SQL query you want.

And if you can't make the ORM make the SQL query you want, you can just write it as a SQL query, like this godawful monstrosity:

      x = Site.objects.raw("select id, name, lat, lon, 111.045*degrees(acos(cos( \
        radians(latpoint))*cos(radians(lat)) \
        *cos(radians(lngpoint)-radians(lon)) \
        +sin(radians(latpoint))*sin(radians(lat)))) \
        as distance from sites_site join \
        (select %s as latpoint, %s as lngpoint) as p on 1=1 \
        order by distance limit 5", [float(lat), float(lon)])
... which calculates the Haversine distance from where you are now to the five nearest points.

I am in roughly equal parts proud of and horrified by this creation.


Site.objects.annotate( distance=Degrees(ACos(Cos(.....))), latpoint=float(lat), lngpoint=float(lon), ).order_by("distance")[:5]

for function calls, look at django.db.models.functions, you can find a bunch of stuff in there or create custom ones super easily (like "two lines of codes" easily)

I mean you have a thing that works in theory so it's a bit of navel gazing, though.


That is actually awesome :-) I'll try that.

I was really just going to try and wrap it in a function to stick in the model so I can say something like Site.objects.get(id=thing).distance_from(lat,long) in.

But, now the bit that I was calling that from is actually being done from a websocket handler, and that's written in Go because Django and websockets seems very complex.


I'm not seeing anything that can't be done here without using raw() though?


Yeah I'm not clever enough to do that.

How would you have approached it?


It looks like GeoJSON implements some distance lookups that make this more django-y, that's probably the easiest way. But I doubt they're using raw() either.


What would you have done Instagram from instead of Django?


Elixir and Phoenix.


You'd have written Instagram which was released in 2010 in Elixir which wasn't released to the public til 2012?


So Rails or some PHP framework. It was slightly too early to go full Node. Django was a little unusual too among the developers I knew. Java was still a thing but more for finance related projects.


Well 2010 PHP and the frameworks at the time were still going through the 5.x desert journey, and the prospects weren't entirely clear with the cancellation of PHP 6, so you wouldn't fault your 2010 self for not trying to push some Drupal/Joomla/Magento to that scale.

Kinda took until Facebook showing off Hacklang in 2014 for people to believe in getting more canonical programming features into PHP and make it more performant. So it would have been a good decision if one could predict 10 years into the future, but nobody can.


Rails was fully into growing pains and maintainability crises (some large rails codebases took years to migrate) and PHP was in transition; some good things by then but it was not what it is now.


All of the gripes OP has with Django are arguably worse in Rails.


I think Threads could have been done in Elixir.


Why would you have chosen these? What are the advantages?


I mean if you're doing it this way, you're really not applying best practices as a developer (never mind as a Django developer).

> Models being passed around everywhere, queries happening everywhere.

No, as a developer you still need to be 100% aware of the underlying queries and potential performance issues. No excuse for N+1 problems. ORM is not an excuse to be lazy, but I admit it will probably catch quite a few developers.

Those same developers would probably make a mess out of any other framework or technology though.


Django allowing queries to be anywhere is more or less in line with Python’s overarching “we’re all consenting adults here” ethos. There’s probably one correct way to do it, but if you want to shoot yourself in the foot then here’s your gun.

It definitely takes a bit of discipline. The key layers are somewhat easy to manage—middleware, context processors, views, template tags—but I’ve seen some hairy lasagne further obscuring where the queries happen on top of that. A well-documented abstraction can be useful, but if it is possible to keep it simple and obvious then that’s the way to go.

(Third-party dependencies can further complicate things, but at least you can expect a library using ORM to be in the installed apps list.)


I'm semi-assuming we're talking about professionals who'd excel with their products in any framework and language.

It's highly productive if you do it right.


The other thing that I think people tend to forget is that there are plenty of situations where N+1 queries just aren't that big a deal. Not every view in every application that every developer builds needs to handle massive amounts of traffic with low latency and high cardinality tables. I've built so many apps where there's one or two users, small amounts of data, etc. And even on apps that do have a lot of traffic, there are often internal/admin/maintenance views that don't have the same requirements and no one will notice an N+1 where N = 5 in the worst possible case.

Every time ORMs get discussed, it seems to be dominated by people who are like "but my app has 5 billion concurrent users doing 2 million requests per second and if there's an extra 5ms on my requests, it will all explode!" and can't comprehend that not everyone is building the same kind of systems all the time. Great, maybe an ORM isn't appropriate for your situation.


C.R.E.A.M.


Both Laravel and Django use Active Record, great for CRUD but I have yet to see a project where it worked with more complex domains.


Great for simple CRUD apps but it falls apart with more complex enterprise requirements.



Well I guess that's good bye Pixel and Android for me then.


Would be great if I could use it with my 6700k.


I managed to cook up a fairly useful meta prompt but a byproduct of it is that ChatGPT now routinely makes clearly illegal or ethical dubious proposals.


It's not.


Oxford, Cambridge, ETHZ, EPFL, etc. are probably salivating right now.


Oxbridge suffered a lot of collateral damage from Brexit because of EU funding cuts and massive loss of EU staff and EU students, who now have to pay foreign fees (4-5x regular home fees). An increase in fees also made it prohibitively expensive to hire EU PhD students.

The situation is slowly recovering, as the UK has now first-class access to EU funding programs and there is an open negotiation to bring back home fees for EU students. However, visas are becoming more restrictive and the exceptionally high fees associated with them might be again increasing, which is putting off potential new employees.

Besides, I am not sure Oxbridge has sufficient extra spots for overseas students diverted from the US due to its peculiar tutorial system. There are lots of top EU universities that could collectively benefit from this as they are much cheaper and larger: Heidelberg, TUM, KU, DTU, KI, KTH, etc.


Harvard is liberal arts, so maybe Oxford.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: