3 ms·
They're a very effective tool. I have hand coded and maintained a lot of SQL. And you know what's not fun? Adding or removing a column and going through all th
by mattmanser 14y ago
They're a very effective tool.
I have hand coded and maintained a lot of SQL. And you know what's not fun? Adding or removing a column and going through all the selects, updates, inserts and manually changing them all and still getting bit by the 'Table X has no corresponding column of type Y' for a piece of the system used once in a blue moon.
And every time you want to add a new class creating the table, creating all the boilerplate select, insert, update statements that are exactly the same as the thousands of times I've done this before.
All that pointless busy worked done away with in a second. In a couple of keystrokes.
You, in my opinion, do not know what you're missing.
That's what an ORM is for. It's not a 'little time'. It's only a 'little time' if you don't actually do serious business coding where there are often 100s of tables to effectively solve a problem domain.
An ORM will dissipate that entirely. And when you want to drop down to hand coded SQL, you can! Best of both worlds!
The only problem with ORMs is when novices don't understand what they're requesting the DB to do.
And guess what, SQL has exactly the same problem!
- crazygringo 14y agoI honestly have no idea what you're talking about. "Adding or removing a column and going through all the selects, updates, inserts..." If you're adding a column, you're adding functionality to the program, so of course you're going to have to add the column everywhere it's used! And if removing, then likewise. Because you have code depending on the new/old column that needs to be changed. There's nothing boilerplate about any of this. Every column has unique functionality and integrates into my code in its own unique way, and needs to be treated as such. In fact, going through all the code manually makes sure you discover the once-in-a-blue-moon cases where you need to change the behavior. Using an ORM isn't going to help any of this at all. Or, if your new column is exactly the same as 80 other columns in the table, which are all used in the same way, then you probably shouldn't be using columns at all, but rather rows in an id-attribute-value format, which solves your whole problem of boilerplate code.
- mattmanser 14y agoIt doesn't sound like you code much business code, most of the code the majority of programmers have to deal with. It tends to consist of a lot of classes of fairly shallow functionality with a lot of data access based on different criteria, meaning a lot of different SQL statements doing minor variations on a theme. Business code is boilerplate a lot of the time. An organisation has a name, a phone number, an address, an added on date, an added by date, and on and on. An so does a Person, a Project, an Order, an Enquiry. 99% of columns are simple data stores that have no sort of 'unique functionality' you describe. They exist to store data that's only purpose is to be recorded and later re-displayed or updated. Hell most problems that require a DB don't have this 'unique functionality' you describe. For example a bunch of static methods on an Order class or in a OrderDataAdapter: Order.Get(id) Order.Get(accountCoordinatorUsername) Order.GetUnassigned() Order.GetOrdersByPartner(id, (optional)boolIncludeCompleted) etc., etc. So in reality you add the new propety to your class, let's say 'expectedDealValue', an int for our purposes. But it's mandatory. You then have to add the column to every method that uses this value. You have to go through all those other totally unrelated methods checking and changing each and every single one of them. And this table is probably accessed in other classes too, say like the QuarterlyReport class, so it's now a find and hunt scenario. Unless you're relying on SELECT *, but no sane SQL programmer does that right? In the bad old days you'd start rolling your own ORM to try and manage this mess. It would invariably suck and cause more problems than it solved. Today's ORMs are a god-send to this type of coding.