Live data from Hacker News

Databases are the endgame for data-oriented design

spacetimedb.com

141–150 of 157 posts

Re: Databases are the endgame for data-oriented design

#141

I started learning programming in the mid-to-late 90's.. a teenager learning with Turbo C, Turbo Pascal, and VB6... eventually to Visual C++... to then attempting to jump on the OOP bandwagon with Java, I began to dislike coding. I was questioning whether this was the career but, after a few years, decided to give it a go. Job interviews, particulary then, were about "OOP this" and "OOP that" and I would purposely be…

Wow, this really means a lot to me. I'm so glad you enjoyed the article!

Re: Databases are the endgame for data-oriented design

#142

Has anyone here seen a database where your users are users in the db itself? Not just a user(id, name, email, password) table but actual db users with GRANTed permissions and ACLs etc set appropriately, and open access to the DB for these users. It seems like it would solve a lot of problems by eliminating the need for data broker apps / endpoints that simply put POST or GET parameters into different SQL queries base…

SpacetimeDB is one such database. It has the concept of an `Identity` which is just a 256 bit unique identifier for a connected user.

Re: Databases are the endgame for data-oriented design

#143
post #10
post #4

My colleagues hate me, but I also found that SQL is The way to write business logic. Lots of caveats about difficulty to test and weird syntax. But it is just that SQL is the most terse and standard way so express logic. And that in itself is the most important factor to avoid bugs. Not what testing strategy you choose.

that's how you end up with multi-thousand LOC sql files that contain all the historical business logic and edge cases of a company and it just keeps being piled up on and its complexity keeps growing because not everything is expressible in SQL. So you end up having a big monster that someone needs to support and one that's not very testable easily

You can write code in any language without defining functions or modularizing in any way. You can write bad code in any language.

For some reason, folks assume SQL must be written badly since they have only written it badly or seen it written so.

It is absolutely possible and preferable to write maintainable SQL logic into user defined functions, stored procedures, views, materialized views, CTEs, temporary tables, etc. If you're looking at one huge pile of monolithic, untestable SQL, the problem isn't the SQL.

One doesn't write O(n^3) algorithms in C++ and then blame C++ for it being slow. For some reason, folks seem pleased with themselves to do as such with SQL though every day and twice on Sunday.

Got subselects in each of the fifteen outer joins with NULLs all over your schema, and now you're upset performance is horrible and inconsistent? PEBKAC.

Re: Databases are the endgame for data-oriented design

#144

Earlier quoted context omitted.

SQL queries yes, what Bury above probably is talking about is obscure triggers/stored-procs,etc that encodes the business logic inside the database far away from any version control or sane ways to track it.

Tracking triggers etc is pretty straightforward, just put them in a repo and apply them as part of a schema change. Testing them can be tricky, as unit tests aren't as likely to capture the locks/time that can be an issue when the database is under load. Tools like pgreplay can be helpful here.

It's not like tracking events in application logic is somehow just a bucket of unicorn farts and rainbows. At least triggers are deterministic and tracked within transactions. Can't tell you how often folks update the DB with an ORM in application logic but forget to update dependent records in other tables in their one-off branch of logic.

Sometimes it's a hard problem.

That said, I think triggers need very well-maintained dependency charts in the docs/comments to ensure they don't ever go cyclical. Those are bad days.

(But again, events in app logic are in no way shape or form immune to cyclic runaways.)

Re: Databases are the endgame for data-oriented design

#145
post #48

Earlier quoted context omitted.

And in any other language this wouldn’t result in multi-thousand lines of code with historical business logic and edge cases?

Testing code is pretty popular in most non-SQL environments.

Testing SQL is pretty popular in most pro-SQL environments as well. There are many tools for that even if many developers appear to remain willfully ignorant of them.

Re: Databases are the endgame for data-oriented design

#146

Earlier quoted context omitted.

And how many non-technical users do you know who do this?

I think SWEs think of databases only as a kind of generic persistence layer and aren't super interested in a lot of the details (more than one has said to me databases are just an implementation detail) or additional capabilities, which I think is a very limited view. Databases are essentially interpreters, just like Python or Ruby. They come with access to a multiuser persistence (etc) service or engine (super handy…

Mediocre coders fixate on algorithms. Great coders concentrate on data structures.

SQL schema creation and maintenance is all about choosing the right data structures for the job at hand.

If you neglect attention to your data structures, no algorithms will save you, and you really only have yourself to blame. It's a still to be learned and honed like any other.

Re: Databases are the endgame for data-oriented design

#147
post #63

Earlier quoted context omitted.

If your colleagues are not applying basic engineering rules to views and stored procedures, it's not fair to say that this is a problem with views and sprocs. They can and should most definitely be testable, documentable, trackable and version controlled. Should one also judge all backend programming by PHP standards circa 1998?

I tend to judge things by the average-worst-case that they enable and how easily things go wrong, and IME stored procs specifically, go badly real quick.

Data structures can be a hard part of programming. That doesn't mean folks don't chose the wrong data structures all the time in any language.

An array instead of a linked list or vice versa. A dequeue instead of a set or vice versa. A binary tree instead of a B+ tree. You can't just throw column names at a DB schema and hope for the best. There's actual engineering to be done, even if many programmers refuse to admit it when interacting with a relational database engine.

Re: Databases are the endgame for data-oriented design

#148
post #10

Earlier quoted context omitted.

that's how you end up with multi-thousand LOC sql files that contain all the historical business logic and edge cases of a company and it just keeps being piled up on and its complexity keeps growing because not everything is expressible in SQL. So you end up having a big monster that someone needs to support and one that's not very testable easily

What you need is a semantic layer on top of SQL

SQL is the semantic layer on top of relational algebra. Adding another layer on top is like having Google translate from Spanish to Russian before translating back to English. Each level of indirection just opens the door for more nonsense to creep in.

Re: Databases are the endgame for data-oriented design

#149
post #5

Earlier quoted context omitted.

I feel like you've come to the right conclusion, but partly for the wrong reasons. Terseness in and of itself is not useful per se. Code golfing languages are the tersest there is, but we don't write code that way.

Or they just used the wrong word. I'd agree with them, but clarify that SQL is not just terse, but concise. A join or a group by is going to be much clearer than writing the code the query plan is going to generate, creating temporary hash maps, doing nested loops, etc.

Yep, because unlike general purpose programming languages, you describe WHAT data you want from SQL, not HOW to get that data as in most application languages.

Re: Databases are the endgame for data-oriented design

#150

Earlier quoted context omitted.

Of course it buys a lot, you don't blow away program state when you change the program. That's huge for highly stateful programs. Also ecs is a prime example of composition over inheritance

ECS is anti-composition. With composition, you say, "This object A has pieces B, C, and D. The way to get to B, C, and D is by going through A." ECS is the exact opposite: "There are components B, C, and D. They may or may not be associated with entity A. In most cases, you shouldn't care because you should be working with B, C, and D directly and not going through A at all."

I think your latching onto an overly specific definition of composition. The core of composition vs. inheritance is how you add features to a things, and whether that mechanism is decoupled so you can bolt that feature to other things. A feature is a blob of code, as opposed to data, which is a blob of memory.

ECS means to add a feature, you write a new system. Its decoupled because you don't have to do anything to anything else in the program. Adding a system (feature/code) affects nothing. To bring it to life on a subset of entities, you add components, which are the data portion. It only affects the joint of those entities that have the component. So again, data can be dynamically added even at runtime without affecting anything else.

With inheritance. You need to add a subclass, and restart the program, losing all the data in the process, coz the code is coupled with the data (the definition of a class). This can be annoying for some types of program development.

Post reply on HN