Object Relational Mappers are evil (a meditation)

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Tue Oct 6 11:13:49 CEST 2009


Carl Banks a écrit :
> On Oct 5, 7:25 am, Aaron Watters <aaron.watt... at gmail.com> wrote:
>> This is a bit off topic except that many Python
>> programmers seem to be allergic to typing SQL.
>>
>> RESOLVED:  Using ORMs leads lazy programmers
>> to make bad database designs.  It's better to
>> carefully design your database with no invisible
>> means of support and there is no reason to not
>> use SQL directly for this purpose.
> 
> Yeah sure, whatever.  I'm sure a good programmer could use sql
> directly and produce a tighter, faster, better-performing application
> than an ORM-solution, same as you could use C to produce a tighter,
> faster, better-performing application than a pure Python one.

It's certainly way easier to write good SQL than to write a good C 
program, and even when using an ORM, it's sometimes worth "going down" 
to hand-written SQL queries for some more or less complex cases. But I 
guess this falls in the same category as recoding a couple core 
functions in C for improved performances.

> Isn't WordPress written in PHP?  Are ORMs even possible in PHP? 

There are (alas) some attempts. Nothing close to SQLAlchemy nor even 
Django's - PHP is just not hi-level enough.

> I can
> almost rationalize use of direct sql if the alternative is some
> hellspawn PHP ORM.

What _could_ possibly be done in PHP would at least be a higher-level 
representation of sql expressions, that would make it easier to 
dynamically build / modifie / combine queries. Working with "SQL as raw 
strings" is both tiresome and error-prone when it comes to dynamically 
generate complex queries. That part is IMHO *much* more important than 
mapping tuples to objects.



More information about the Python-list mailing list