Tony The Lion
Tony The Lion

Reputation: 63200

Functional Programming better to manipulate lists of database data?

I'm watching some lecture's on Functional Programming and the main 'data structure' so to say, but there really isn't one in FP, is lists, so my question is: when one deals a lot with database's and 'lists' of data, then is Functional Programming not superior to OOP?

Upvotes: 1

Views: 303

Answers (2)

doppelfish
doppelfish

Reputation: 983

Well, Lisp deals with lists, but the lists are heterogenous, and can well represent a tree. Other languages, like Haskell, give you structured types, named and unnamed, and - in contrast to lisp - allow for static type checking.

One thing that pure functional languages do not have is the notion of stateful variables that can be assigned. Some Lisp implementations provide such state - you get a setq opeator -, while Haskell doesn't. Reading and writing databases, however, is all about having state - and lots of it, that's what databases are for - and about reading from and writing into it. So, operating on a database is quite the opposite of using a functional language.

It does, however, make sense to create a database query language which expresses the DB operations in a non-imperative, but in a declarative, and hence in a functional way. That's how SQL makes sense, and that's also how the way LINQ is defined makes sense.

So, it makes sense to have a database language which is functional, but it's not because of the lists.

Upvotes: 2

Mark Byers
Mark Byers

Reputation: 838376

One of the biggest improvements in reading from databases in recent years is LINQ. LINQ is actually based a lot on functional programming principles. In fact SQL is also a very functional style language.

I see no problems with reading data from a database using a functional language.

Now modifying the database... that's a different story. I'll leave that for another day. :)

Upvotes: 6

Related Questions