DEV Community

Discussion on: What Makes a DSL Bad? Make, CSS, and how we can do better.

Collapse
stereobooster profile image
stereobooster

I agree with sentiment, but disagree with arguments. A lot of people write SQL manually and are happy with it. There is something else which makes SQL pleasant to work with and CSS less pleasant. My take on this is - predictability

By looking at SQL query I know what the outcome will be, by looking at CSS there is generally no way to predict what the outcome would be. In CSS other rule with the same specifier included later would override rule, or another style with higher specificity, or margins do unexpected things.

Collapse
maxheiber profile image
Max Heiber Author • Edited on

Re what's wrong with CSS: I agree the cascade is the worst part of cascading style sheets, due to the reasons you describe. I think this is related to my idea that the problem is that it doesn't have variables or functions: the cascade is what CSS has instead of functions+variables+data. When writing inline styles in React (for example), one can imitate the cascade selectively using {style1, ...style2}, exactly where one wants, with predictable results.

So no disagreement that SQL is better than CSS. But I still think SQL is bad: when I said no one writes it by hand, I meant that it is usually constructed by code in a host language, which is using things like prepared statements. Some people describe this as writing the SQL by hand, as compared to using an ORM, but I want to point out that the power of variables and functions is coming from the host language. Which is entirely fine. The weird thing is that we're manipulating code as strings, which suggests to me that a better alternative to SQL would be closer to data than code.

This Python/ReQL is easier to manipulate from the host language, safer, and (I expect) easier to learn than the corresponding SQL, as there is no new syntax:

Python/ReQL:

r.table("users").insert({
   "user_id": "f62255a8259f",
   "age": 30,
   "name": "Peter"
})
Enter fullscreen mode Exit fullscreen mode

SQL:

INSERT INTO users(user_id,
                  age,
                  name)
VALUES ("f62255a8259f",
        30,
        Peter)
Enter fullscreen mode Exit fullscreen mode