Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think you need to really learn what sql is. It's a 4th generation language, higher level than php or other oo/procedural/functional langauges. If you're finding php and a framework to be better you're underestimating the power of sql.


The SQL statements are not the problem. The problem is turning the list of tuples you get back into a usable data structure.

Also, abstracting away SQL doesn't mean you abstract away set algebra. It means you write "$current_user->messages( text => { -like => 'foo%' })->recipients" to get a list of people the current user sent messages containing the word "foobar" to, instead of some 200-character-long embedded program in another language. A good ORM is an essential abstraction.


By that example, I meant to highlight the DRY aspect of programming and how I realized, as an early beginner at the age of 15, that frameworks and libraries provide a good foundation so you can focus on more complex issues.

The SQL I kept repeating in that application was simple CRUD functions on MySQL tables. I know that SQL is so much more than that.


Sql isn't more than that. That's the whole beauty of relational programming, you only have to write queries and views, and this simple abstraction does most of the work that you need to do (with pl/sql or t-sql it is turing complete and you don't even need to leave the rdbms).


I don't get why some people keep praising SQL like this. SQL is great for complex queries that contain valuable logic, but it's not expressive at all when you want to do something trivial. Getting all the attributes of user X is so much more work, and harder to maintain, in SQL than it is in any ORM.

"select name, pass, hash, email, realname from user where id = ?"

versus

session.get("User", x)


SQL is not particularly nice for complex queries, either. The underlying model is good, but the particular syntax they chose is verbose, confusing, and non-portable.


I kind of agree, but I was conceding the most reasonable argument to the parent.


'SELECT * FROM user WHERE id = ?' OR 'SELECT getUser(?)' presuming you have a stored procedure/function getUser that returns the data you need, and you should (or a view, at least)


SELECT *? A function in the SELECT statment?

Oh dear god, a blasphemer!

The former can cause performance problems if you have blobs as well as being an unnecessary security hole, the latter can cause performance problems over large datasets as it often forces the execution plan away from a set based solution.


The fact that using the most trivial of examples triggers a discussion in on itself helps to prove my point.

Nobody debates session.getUser(id)


Relational programming may be beautiful, sure, I guess in some ideal world.

But SQL syntax is a dog. Especially when it's sitting next to real code, wrapped up inside strings and making everything feel dirty.

If you're using an SQL database from within another language primarily just to dump objects and pull them out, and especially if you're doing a lot of it, I have trouble thinking of a situation where you wouldn't prefer to abstract away the SQL bits. Maybe if you're working in a language with built in SQL syntax support? Even then, it's not exactly compact, and you've got quite a bit to do even after you get your results back from the database...


SQL, or more accurately, relational algebra, is a thing of pure mathematical beauty.

The problem is all the other crap that you have to layer on top of it for it to be really, really useful.


What about the very common cases where you need to do very simple things, like common CRUD operations? Abstracting the SQL required for these simple queries makes a lot of sense to me.


Sql is designed exactly for CRUD. Almost by definition there's no better way to do CRUD than sql. And about CRUD - most software should rightly be CRUD, because CRUD represents the highest level of abstraction in programming that you can get (below natural language interface of course). Sql CRUD abstracts away all hardware and software layers of the computer (the only hardware/software efficiency decision you have to make is where to declare indexes).


It doesn't abstract away the fact that your application is written in terms of polymorphic objects, rather than opaque relations. It also doesn't abstract away the fact that people like to represent their data with data structures richer than "set". SQL works reasonably well for CRUD, but most web applications are not CRUD, they're online transaction processing, where relational databases just get in the way. A good object database is a much better fit. (And no, I don't mean CouchDB.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: