Don't write complex SQL queries
Say that you want to be a musician, so you buy a nice violin, but you don’t know how to play it and don’t have the patience to learn how to play it, so to produce music you trash the violin on rock and call it music.
This is the case I find with many teams using Rails. They pick up Rails because it’s fancy, a buzz word and they fail to stick with it’s best practices. Yesterday my team mate called me and asked me a doubt, there was a function that just had one line of ORM and it was easy to test, so I told him how. There was another in which a complex join was used, the function spanned 10 lines or so and mostly it was occupied by SQL query.
The function was badly written and it did not have any other documentation that said what it did. I simply couldn’t tell the poor fellow how to test it. It might have been an old code written before the dawn of humanity and it was crap.
One reason I’d been told by the so called Rails people is that writing SQL is efficient than using ORM. The strength of Rails, well, most of it is in ActiveRecord, it’s ORM layer. If you don’t want it why on earth are you using Rails?
Now coming to Rails, it’s true that ORM is inefficient and firing lot of SQL slows down the DB. But haven’t you chosen the Rails and Ruby path because you are concerned with human productivity than with computer efficiency? Is your application so big that it spans more than 100 servers all scaled to max vertically that is making you to take such a drastic decision?
Now what about making computers do lot of work so that humans are productive? Isn’t that progress? There are ways to scale Data Base, be it MySQL or Postgres. Postgres comes with very excellent scaling which you can use to make many servers act like one Posgres DB. For MySQL there are stuffs like ProxySQL that catches and make the DB run more cooler.
Making computer’s work hard makes economic sense too. An Engineer who is supposed to follow computing trends should know that computing costs are getting cheaper and human costs are getting higher.
I wonder why people are bring up so much bane on themselves when there are so much boon that’s been given to us by the Free Software Community? One thing is due to ignorance. Managers push programmers so much and make them accountable for everything, that programmers become like narrow visioned horses which concentrate just on their destination than to think out of the box.
Any technical house should trust it’s engineers, should give them enough resources to them to explore, when you are faced with a problem, the team should come up with 5 to 10 solutions which should be put to the test, out of that which is the most suitable for the team should be chosen.
So if you like to bang things around and want to be a musician, choose to play drums rather than a violin.