Doctrine ORM Good Practices and Tricks

I see what you did there. Good job throwing those acronyms around to look intelligent without adding any value. Command Query Separation (CQS) does not mean that using an ORM for data manipulation and using SQL for querying is any better than using SQL (not the same exact) SQL for both. It just means not having the same function (or class) do both commands and queries at the same time. Saying that using Doctrine for CRUD and using SQL for everything else is not what the creator of CQS had in mind.

What is not being argued here, and is really the heart of my argument is that when using an ORM, you still will need to know SQL really well, your code will always be slower, and you will find yourself fighting against the impedance mismatch to one degree or another as long as it is used.

Look, Doctrine is more-or-less a copy of Hibernate. The Java folks have been debating the merits of ORM's over JDBC for at least a decade. The only argument that the pro-ORM people can ever come up with is that it seems to make writing code a little faster (false) and junior devs don't need to understand SQL or RDMS's (also false). Further, when the ORM falls over, and they always to at some point, those junior devs have no solution and it takes someone senior person to come sort it out. Literally, they throw their hands up. Well you know what, throwing your hands up and saying I give up is not ok. But, devs stuck in the ORM mentality do it all the time. Sorting out why the ORM can't handle the load for common use-cases should not be a senior level task. Saying the ORM is not designed to do reporting when ORM's are always marketed as a way to not have to deal with SQL is disingenuous and unacceptable. If they had done it the right way from the beginning and used tools that really make it difficult to do dumb things by transcending that whole mess, then it would have never been a problem. Even a crappy SQL statement will always be faster than a tuned ORM. Further, fixing a crappy SQL statement is always something that even an intern can do because all CS students are taught SQL and RDMS theory in school. It literally becomes a situation where I can have an intern make the SQL fast or I can have a senior neck beard make the ORM fast, usually by dropping to DQL, or straight SQL, while simultaneously cussing under his breadth that the ORM is stupid. Happens all the time.

Now obviously, someone on the Doctrine Team is never going to agree with me. That is actually totally ok. Do you want to know why? I will tell you. Every day of the week, and twice on Sunday, I can walk into a crappy code base, where the average dev has thrown up his hands because a report is timing out after 5 minutes and make the same exact report finish in < 1 sec. I walk away looking like a hero and I make boat loads of money. So go ahead, keep telling everyone that speed doesn't really matter and lying by saying ORM's mean you don't have to know and use SQL. Keep spouting nonsense that using an ORM makes your development OMG faster over using standard good coding practices. Please do, it's good for my business, real good.

By the way, it looks like you are also part of ZF2. What a slow, bloated, over engineered, rube goldberg, propeller-head, piece of garbage. Much worse than ZF1 (which is also very chunky). That's why it doesn't have any real market share. Great job chief.

/r/PHP Thread Parent Link - youtu.be