Live data from Hacker News

I Don't Want to Teach My Garbage DSL, Either

github.com

41–50 of 54 posts

Re: I Don't Want to Teach My Garbage DSL, Either

#41

Earlier quoted context omitted.

Well, Ecto is not an ORM. It's a Data Mapper[0]. Rails' ActiveRecord is ORM. I agree that some DSLs make SQL better and easier to reason about -- and that Ecto is one of them. [0] https://en.wikipedia.org/wiki/Data_mapper_pattern

Aren't data mappers generally referred to as ORMs?

Not to my knowledge. Data Mappers should be the "less batteries included" piece of tech compared to the ORMs.

As a single non-representative example, ActiveRecord has `before_insert` hooks you can simply add as methods to your model class. Ecto doesn't have those.

Re: I Don't Want to Teach My Garbage DSL, Either

#42
post #28
post #2

Unrelated to the article, just found it interesting how he’s using github to literally auto generate his blog via their md-to-html thingy, and issues for comments.

The author may not have intended for the blog posts to be read in that way. Its also hosted at https://cf020031308.github.io/blog/i-dont-want-to-teach-my-g...

That doesn't change the point. The github.io page is still markdown rendered as html, and the comment button still links to a new issue.

Re: I Don't Want to Teach My Garbage DSL, Either

#43

Earlier quoted context omitted.

Some things are irreducibly complicated. You can't set up a lean API contract for a complicated thing without giving up power. The example of SQL is pertinent. Any attempt to set up a lean API contract for a relational database is doomed to be weak and painful to use. Without knowing the specific problem domain the blogger was dealing with, you can't know whether that was the situation. But if we assume they are comp…

complexity != complicated

It literally is though.

com·plex·i·ty n. the state or quality of being intricate or complicated.

Re: I Don't Want to Teach My Garbage DSL, Either

#44

Earlier quoted context omitted.

The trouble with SQL is that its foundation is old and hasn't been given much love with regards to modern language theory, and any attempts to talk about how the language could be improved are shot down on the basis of confusing the language with the application of the language. The trouble with SQL is that it doesn't easily allow for basic building blocks that ORMs benefit from, like composability. This leads many O…

SQL is a great language. It's for querying records from a database. Trying to wrap stateful objects around SQL is where the industry went wrong, IMO. It does make some code more portable across datastores, but for me the price is too high. When you know how to write efficient SQL statements, ORM feels like having a hand tied behind your back.

> It's for querying records from a database.

The application of the language does not make the language itself great. As we have seen with DSLs that often come bundled with ORMs, there are other languages to query databases with (even if they ultimately compile to SQL), and I would argue that some of them do a lot better job than SQL does for providing a comfortable and cohesive environment for developers to write queries in.

In the imperative language space, we have one hundred and one different languages all trying to make things slightly more comfortable to developers. C, Go, and Rust can all be used to write the same kind of application, more or less, but that does not mean all of those languages are equally great. The same is true of declarative queries. Just because SQL is popular does not mean it is great.

> When you know how to write efficient SQL statements, ORM feels like having a hand tied behind your back.

ORMs and SQL are orthogonal concepts, really. There is no reason an ORM couldn't require you to hand-roll every single SQL statement. An ORM's concern is simply mapping the results of that query into the application's objects. That some ORM implementations also include functionality to build queries for you, often on top of the aforementioned DSLs, to make that mapping require less effort on the developer is, I would argue, largely a result of SQL being a bad language.

Re: I Don't Want to Teach My Garbage DSL, Either

#45

Earlier quoted context omitted.

SQL is a great language. It's for querying records from a database. Trying to wrap stateful objects around SQL is where the industry went wrong, IMO. It does make some code more portable across datastores, but for me the price is too high. When you know how to write efficient SQL statements, ORM feels like having a hand tied behind your back.

> It's for querying records from a database. The application of the language does not make the language itself great. As we have seen with DSLs that often come bundled with ORMs, there are other languages to query databases with (even if they ultimately compile to SQL), and I would argue that some of them do a lot better job than SQL does for providing a comfortable and cohesive environment for developers to write qu…

Working with relational databases might be difficult for those not acquainted with them. However, I think the SQL language as an interface primarily for relation databases is a great language.

I think, invariably when you use ORM, you end up having query-specific object structures. For example [1].

You also might be passed objects with deferred fields [2]. This will be completely opaque to someone consuming the resulting object. You'll eventually run into this problem [3]. Solving the lazy load problem requires an understanding of how SQL works in the first place. And if you look at the solution in that example, it's an ORM-wrapped series of joins.

From 3: > For good measure, we add a raiseload to throw an exception if we try to load anything that we didn’t load here.

Who wants to live in this world?

1: https://stackoverflow.com/a/45905714/5573538 2: https://docs.sqlalchemy.org/en/13/orm/loading_columns.html#c... 3: https://engineering.shopspring.com/speed-up-with-eager-loadi...

Re: I Don't Want to Teach My Garbage DSL, Either

#47

Earlier quoted context omitted.

Aren't data mappers generally referred to as ORMs?

Not to my knowledge. Data Mappers should be the "less batteries included" piece of tech compared to the ORMs. As a single non-representative example, ActiveRecord has `before_insert` hooks you can simply add as methods to your model class. Ecto doesn't have those.

That seems silly. They are a technology for mapping from a relational database to a system based on objects. That's what an ORM is.

> Data Mapper: A layer of Mappers (473) that moves data between objects and a database...

(https://martinfowler.com/eaaCatalog/dataMapper.html)

Sounds like an ORM to me.

Some people try to distinguish between the "data mapper" pattern and the "active record" pattern (it's not just the name of the Rails library, it's a pattern... which the Rails library may or may not implement very well). Both are ORMs, because both are ways of mapping from an rdbms to an object system.

(Neither of which actually has to do with query DSL. We could imagine just taking the part of ActiveRecord that produces queries, but having it return simple hash/string literals. It wouldn't really be an "ORM" (except in the most technical sense that even hashes are objects in ruby), but it would still have the parts you don't like. The nature of query building is actually not related to 'data mapper' vs 'active record' -- you could have an instance of either in which you wrote raw SQL queries, or an instance of either which used the same non-SQL DSL)).

But even distinguishing between "data mapper" and "active record", in actual practice, I don't think there are two completely separate, distinct, and unified camps. I don't think these categories actually serve well to deliniate the ORMs we've got. Instead, there are a just a whole bunch of approaches, some more light weight than others, some more mature/reliable than others, some 'leakier' than others, differing on all sorts of additional dimensions. I agree that some ORMs are better than others -- and some may disagree on which these are -- I don't think saying "data mapper" is actually useful for understanding which these are.

Re: I Don't Want to Teach My Garbage DSL, Either

#48
The article this is in response to says:

> What’s worse than data silos? Data silos that invent their own query language.

and:

> I just want my SQL back. It’s a language everyone understands, it’s been around since the seventies, and it’s reasonably standardized.

Huh? SQL is just as DSL-y as anything else. It's so non-standardized that I can't take any program written for any RDBMS and run it against any other RDBMS, unless the author specifically extracted all the DSL into an interface layer and ported it to that other RDBMS already. Even something as common as "CREATE INDEX" has different syntax on every database I've ever used.

It's even worse than HTML/JS/CSS 10 or 20 years ago, where at least it had a chance of minimally working. And you can't seriously tell me that it's harder to make SQL implementations (where you control the database) portable, compared to, say, C++ compilers (where you don't control the hardware architecture).

Yeah, data silos with their own query languages are bad. But RDBMSs are some of the worst offenders, because they pretend this doesn't apply to them. It's easy for newcomers to justify creating their own SQL-like languages, because every existing database is already merely an SQL-like language.

All these database vendors need to get together and make some "SQL5" that finally works consistently.

Re: I Don't Want to Teach My Garbage DSL, Either

#49
post #48

The article this is in response to says: > What’s worse than data silos? Data silos that invent their own query language. and: > I just want my SQL back. It’s a language everyone understands, it’s been around since the seventies, and it’s reasonably standardized. Huh? SQL is just as DSL-y as anything else. It's so non-standardized that I can't take any program written for any RDBMS and run it against any other RDBMS,…

Huh? SQL is just as DSL-y as anything else. It's so non-standardized that I can't take any program written for any RDBMS and run it against any other RDBMS, unless the author specifically extracted all the DSL into an interface layer and ported it to that other RDBMS already.

There are lots of weird parallels between SQL and Smalltalk. For example, both SQL and Smalltalk are constructed with Douglas Hofstader's "strange loops." All Smalltalk object instances have a class, and the classes themselves are object instances. SQL tables are defined using metadata stored in SQL tables. Another parallel, is that the language variants are very similar, but ultimately incompatible to the point where translation is non-trivial. In Smalltalk, this is due to a toothless language standard, resulting from political maneuvering by various language vendors. Not sure what it is in the case of SQL.

There is a problematic relationship between DSLs and libraries in languages of sufficient power. In programming languages with a certain level of expressive power, it's easy to write a DSL on top of a library, or on top of another DSL.

https://xkcd.com/927/

I used to joke about "lady/gentleman computer scientists." What's the difference? A computer scientist knows how to implement another computer language. A lady/gentleman computer scientist knows when they should know better.

A DSL should be used to super-charge your project's very idiosyncratic special context. The trick is knowing better when you shouldn't. Accessing a database isn't your project's very idiosyncratic special context.

Re: I Don't Want to Teach My Garbage DSL, Either

#50

Earlier quoted context omitted.

complexity != complicated

It literally is though. com·plex·i·ty n. the state or quality of being intricate or complicated.

They exist as distinct words for a reason. The difference is important. Search "complexity vs complicated", I even found a few articles about it right here on hacker news.
Post reply on HN