News for hackers. Stuff that matters.
Re:SQL is 43 years old – Here’s why we still use it today by charles-salvia on Tuesday May 02, 2017 @08:20AM (#14245730)
The main reason is the object-relational impedance mismatch[1]. Basically, programmers like working with objects that have data fields. This is because most modern, widely-used programming languages treat objects/aggregates with data fields as a first class concept. But SQL isn't designed around objects with fields, it's designed around tables, rows, and result sets from queries. Therefore, working with SQL in most modern programming languages generally requires layers of annoying result-set->object or object->row plumbing/conversion code. (Not to mention the vagaries of type conversions.) Of course, these days, this problem can be substantially mitigated to a certain extent by clever ORMs, but an ORM is generally a leaky abstraction at best. Obviously, whether or not any of this bothers you will depend on your use cases and a lot of other factors.

[1] https://en.wikipedia.org/wiki/Object-relational_impedance_mi...

Re:SQL is 43 years old – Here’s why we still use it today by MarHoff on Tuesday May 02, 2017 @09:29AM (#14246150)
But SQL isn't designed around objects with fields, it's designed around tables and rows.

I think a more correct analogy would be that table are like classes, columns are the properties, and rows are instances. And so defining foreign keys is like setting a pointer to a parent instance.

There is not direct analogy for methods, but you can use function/trigger to do the same job.

PostgreSQL is actually an object-oriented RDMBS, it's not because you are meant to manipulate these objects through SQL that they are less powerful. And SQL is actually Turing Complete with PostgreSQL.

It's clearly not convenient for general programming, but as soon as data manipulation is involved you benefit from a lot of built-in optimization.

Re:SQL is 43 years old – Here’s why we still use it today by metaphorm on Tuesday May 02, 2017 @11:31AM (#14247184)
> defining foreign keys is like setting a pointer to a parent instance.

I can't agree with that statement, though I'm sympathetic to why you would say it. A foreign key is something that essentially doesn't translate from the world of Tables/Rows to the world of Classes/Objects.

In the relational data model the foreign key is a convenient place to include an index for joining on. What does join even mean between two classes? The closest you'll typically get is nested objects, but that's not quite right. A row produced from table joins isn't a nested data structure. It's still flat. The join operation in relational algebra has no direct equivalent in OOP.

Re:SQL is 43 years old – Here’s why we still use it today by judah on Tuesday May 02, 2017 @10:17AM (#14246484)
This breaks down when you deal with classic object oriented concepts like inheritance, encapsulation, or polymorphism.

This is why object/relational mapping (ORM) has been called the Vietnam of Computer Science[0].

[0]: http://blogs.tedneward.com/post/the-vietnam-of-computer-scie...

Re:SQL is 43 years old – Here’s why we still use it today by MarHoff on Tuesday May 02, 2017 @10:45AM (#14246735)
Sorry if I was unclear, I'm not advocating for ORM.

And yes it breaks down because it is similar but different. Row "instances" can perfectly exists outside a table and even be defined outside any table via composites types or even on the fly.

Just saying a RDMS can be a powerful object-oriented environment using solely SQL and no ORM at all.

Re:SQL is 43 years old – Here’s why we still use it today by talaketu on Tuesday May 02, 2017 @10:38AM (#14246678)
> tables are like classes, columns are the properties, and rows are instances.

tables are like functions, columns are the arguments, rows are the invocations

Re:SQL is 43 years old – Here’s why we still use it today by MarHoff on Tuesday May 02, 2017 @10:47AM (#14246751)
functions are actually functions...
Re:SQL is 43 years old – Here’s why we still use it today by talaketu on Saturday May 06, 2017 @06:16AM (#14279586)
functions are relations
Re:SQL is 43 years old – Here’s why we still use it today by corpMaverick on Tuesday May 02, 2017 @10:40AM (#14246695)
I spent years trying to hide the database. Now days I just embrace it. The database is there. Tables and rows are as real as invoices or purchase orders. The database will still be there after my programs and I are gone. I use OOP to construct good gateways into my tables.
Re:SQL is 43 years old – Here’s why we still use it today by dunmalg on Tuesday May 02, 2017 @01:47PM (#14248688)
The struggle is real. Letting go of my local data structures was a surprisingly difficult psychological hurdle. I sometimes wish there'd been someone there to tell me that the easiest paths are basically "all" and "nothing". Unfortunately I was the only programmer in the entire organization so I was making it up as I went along. I struggled for WEEKS playing pull-change-push games with huge duplicate local data structures before it even occurred to me there was a better way.
Re:SQL is 43 years old – Here’s why we still use it today by gnaritas on Tuesday May 02, 2017 @01:47PM (#14248684)
> I use OOP to construct good gateways into my tables.

That's all an ORM is, a good default gateway to the tables that you don't have to write by hand.

Re:SQL is 43 years old – Here’s why we still use it today by corpMaverick on Wednesday May 03, 2017 @10:56AM (#14256194)
ORMs (i.e. Hibernate) try to hide the database. You change the objects and they are magically saved. See http://stackoverflow.com/questions/20863150/in-the-context-o...
Re:SQL is 43 years old – Here’s why we still use it today by gnaritas on Wednesday May 03, 2017 @01:13PM (#14257837)
I've written ORM's, I don't need them explained to me, and no all ORM's don't try and hide the database, that's just one pattern. Others like ActiveRecord simply try and make life simpler without complete hiding behind so much magic you can't figure out what's going on. ORM's abstract the database, that's not the same as hiding the database.
Re:SQL is 43 years old – Here’s why we still use it today by yawaramin on Sunday May 07, 2017 @01:55PM (#14286576)
Except for the times when they load all columns into memory and then you programmatically discard almost everything because you really just needed Person#name.
Re:SQL is 43 years old – Here’s why we still use it today by remotehack on Tuesday May 02, 2017 @07:53PM (#14251842)
An ORM is a gateway...not a good gateway.
Re:SQL is 43 years old – Here’s why we still use it today by gnaritas on Tuesday May 02, 2017 @08:45PM (#14252135)
Most disagree, hence the popularity of ORM's.