Most active commenters
  • 9rx(9)
  • whstl(5)
  • pc86(4)

←back to thread

628 points kiyanwang | 61 comments | | HN request time: 0.598s | source | bottom
1. bob1029 ◴[] No.43630646[source]
Not guessing is perhaps the most important thing to the business.

I developed a lot of my problem solving skills in semiconductor manufacturing where the cost of a bad assumption tends to be astronomical. You need to be able to determine exactly what the root cause is 100% of the time or everything goes to hell really fast. If there isn't a way to figure out the root cause, you now have 2 tickets to resolve.

I'll throw an entire contraption away the moment I determine it has accumulated some opacity that antagonizes root cause analysis. This is why I aggressively avoid use of non-vanilla technology stacks. You can certainly chase the rabbit over the fence into the 3rd party's GitHub repo, but I find the experience gets quite psychedelic as you transition between wildly varying project styles, motivations and scopes.

Being deeply correct nearly all of the time is probably the fastest way to build a reputation. The curve can be exponential over time with the range being the value of the problem you are entrusted with.

replies(5): >>43631055 #>>43631842 #>>43632734 #>>43637040 #>>43638701 #
2. Taek ◴[] No.43631055[source]
I always get a lot of pushback for avoiding frameworks and libraries, and rolling most things by hand.

But, most frameworks and libraries aren't built to be audit-grade robust, don't have enterprise level compatibility promises, can't guarantee that there won't be suprise performance impacts for arbitrary use cases, etc.

Sometimes, a third party library (like sql-lite) makes the cut. But frameworks and libraries that reach the bar of "this will give me fewer complications than avoiding the dependency" are few and far between.

replies(8): >>43631189 #>>43631275 #>>43631326 #>>43632119 #>>43632384 #>>43635012 #>>43635674 #>>43644940 #
3. jppope ◴[] No.43631189[source]
I completely agree - though there are places where I trust an implementation of things like a well known algorithm.

However, to add onto this, I'm consistently shocked at how often it is much CHEAPER to "roll your own." We've done some reviews on systems after a few years and the number of bugs and security vulnerabilities we experience with code based around packages is much MUCH higher. Its hard to put a number to it because the time cost of fixing those issues is variable, but its substantial. Its also amazing to me that it can be cheaper to build your own vs using a 3rd party vendor for something that would appear to be highly specialized - of course opportunity cost is a real thing.

replies(3): >>43631311 #>>43631650 #>>43638956 #
4. noduerme ◴[] No.43631275[source]
This is a hard take, just because we all build on stacks. When we trust that Math.Abs() is going to work in some language, or that some socket library is going to do what it says on the tin, we're standing on the shoulders of giants. I also avoid frameworks as much as possible, but by frameworks I mean anything I'd rather roll myself in a scripting language, particularly when learning and keeping up with the framework seems like more of a hassle. But for the layers and layers of underlying software and hardware behind me writing REST calls and async functions?

Also, there are higher level libraries that are sometimes good, because why reinvent the wheel every time you make something? Pixijs is one I use a lot. Also, Chart.js. Jquery. Moment.js. Good ol' Bootstrap 4 alpha's CSS handles a ton of use cases, and I never need to think about it again. There's very little in those that I haven't at one time or another rolled myself, but having a toolkit that you know and doesn't change much saves you a lot of time. The danger is more getting into libraries that aren't already dead, and are still in active development ;)

replies(1): >>43631652 #
5. noduerme ◴[] No.43631311{3}[source]
Rolling your own, though, does come down to hammering in the extra nails... and hoping that whoever's doing the job knows where to put those supports in place. If you have someone who looks into the future and sees what issues might come up in a few years, then it's way cheaper than relying on frameworks. If you don't, then you're stuck with some janky software that no one else can fix. I think this is why the larger the scale, the more likely companies are to rely on frameworks which themselves are janky, but at least well understood.
6. whstl ◴[] No.43631650{3}[source]
The low quality of modern libraries is something that REALLY shocks me.

The library space has become competitive, and people are running them as business. The goal is not to be correct or even good, but to be a "first mover" and selling tutorials, books, Github sponsorships, Patreon subscriptions...

It's bad not only in terms of security, but also in terms of developer experience.

I am constantly amazed at how little documentation things have, at how many BASIC cases they don't cover (let alone edge cases) and how many security holes those libraries have, and the number of dependencies just keeps getting bigger and bigger.

Another issue is that newer developers are being taught just the newfangled library and have zero experience with the foundations. The number of React devs who don't know how to use HTML forms without a library is nuts.

replies(1): >>43631786 #
7. chrisweekly ◴[] No.43631652{3}[source]
Moment.js is one of those libraries to avoid; the bloat....
replies(1): >>43632154 #
8. GiorgioG ◴[] No.43631786{4}[source]
> The low quality of modern libraries is something that REALLY shocks me.

How could you be shocked? Everything that's happened in the software industry outside of medical/DoD has been about delivering features as fast as you can, quality be damned.

replies(1): >>43638749 #
9. theutopian ◴[] No.43631842[source]
Well said, well written.
10. pc86 ◴[] No.43632119[source]
This is smart if you work for a company that actually needs this level of robustness. The problem is that most don't, and a lot of people who work for these companies wish they were working someone "better"/"more important," so they pretend they actually do need this level of performance.

The guy like you on a mission critical team at a cutting edge company is a godsend and will be a big part of why the project/company succeeds. The guy who wants to build his own ORM for his no-name company's CRUD app is wasting everyone's time.

replies(4): >>43632378 #>>43632716 #>>43632815 #>>43658889 #
11. aabaker99 ◴[] No.43632154{4}[source]
I still like Moment because it offers better control of time zones that aren’t the browsers time zone when compared to the builtin Date APIs.

Do you have a recommendation to replace Moment for that use case?

I’m hopeful for the future with JavaScript Temporal.

replies(2): >>43632877 #>>43637534 #
12. ◴[] No.43632378{3}[source]
13. jon-wood ◴[] No.43632384[source]
This is very contextual. If I'm building a web application for an early stage startup which is basically a bunch of pretty CRUD views I'm absolutely using a framework for it, there's no point in hand rolling everything when the problem being solved is exactly what a framework is designed to do. If it's something safety critical, or where getting software updates out to it is going to be a problem, I'm probably going to end up hand rolling a lot more and depending on frameworks less, because I need to understand what the failure modes are and how it's going to deal with them.
14. ryandrake ◴[] No.43632716{3}[source]
I think many engineers would highly benefit from doing a 1-2 year stint working on safety-critical embedded software, where there are correctness requirements, and lives are lost if you're wrong or careless. It may not be everyone's bowl of soup, but it would at least expose you to that side of the world and you might learn something from the experience. Perhaps if everyone did this kind of tour of duty, something would rub off, and there would not be so much casual yolo carelessness in the "normal" software world.
replies(3): >>43632826 #>>43633862 #>>43634548 #
15. skrebbel ◴[] No.43632734[source]
> This is why I aggressively avoid use of non-vanilla technology stacks

I was with you until this line. I've never seen a codebase where Not Invented Here Syndrome resulted in a stack that "antagonizes root cause analysis" in any way. I once worked at a C++ shop that had NIH'ed a supposedly thread safe string class, and it wasn't pretty.

There's plenty mature robust tech out there, and the chance that your own inventions are equally free of quirks and edge cases as battle-tested frameworks/libraries/databases that have had 1000s of eyeballs on them sounds quite unlikely to me, regardless of your programming skill.

replies(1): >>43635091 #
16. 9rx ◴[] No.43632815{3}[source]
> The guy who wants to build his own ORM for his no-name company's CRUD app is wasting everyone's time.

I once unfortunately joined a project where an off-the-shelf ORM had been selected, but when development was well into the deep edge cases started to reveal serious design flaws in the ORM library. A guy wanting (perhaps not a in a joyful sense, but more not seeing any other choice) to build his own ORM that was mostly API-compatible was what saved the project.

This was a long time ago. The state of ORM libraries is probably a lot better today. But the advice of ensuring that a library is SQLite-grade before committing to it does rings true even for simple CRUD ORMs. Perhaps especially so.

replies(7): >>43633292 #>>43634520 #>>43635035 #>>43637001 #>>43638665 #>>43638768 #>>43658894 #
17. tacitusarc ◴[] No.43632826{4}[source]
On the other hand, do I want careless devs working in those industries?
replies(2): >>43633287 #>>43635135 #
18. microflash ◴[] No.43632877{5}[source]
dayjs is a similar library that I’ve used to replace Moment with minimal effort.
19. ryandrake ◴[] No.43633287{5}[source]
I don't think "careless" is a permanent, intrinsic attribute of a developer. It's something they learn to be, and it can be unlearned.

We respond to incentives. If a developer's only incentive is "we reward shipping as fast as possible" then they will carelessly ship slop as fast as they can type it. If that incentive is removed, they can learn a better way...

20. pc86 ◴[] No.43633292{4}[source]
The problem is that for every example like yours where you run into very specific ORM edge cases, and seems completely reasonable, there are about 95 where a story like this is used as justification to spend months building something when a library would have actually worked out just fine and been implemented in weeks or days. And that running into these edge cases is used as justification for "throw the ORM out" not "don't use the ORM for this particular class of query."

One of my favorite features of Entity Framework from my .NET days is that it's very easy to just break out of the ORM functionality, even from within an EF-specific function, or to have multiple instances with slightly different configuration (I never had to do that last bit but I know it was possible a decade ago).

replies(3): >>43633699 #>>43638833 #>>43654183 #
21. 9rx ◴[] No.43633699{5}[source]
In that case it was more that the ORM was, under certain conditions, silently corrupting data and whatnot due to fundamental design problems. It needed a major overhaul to address the issues and at that point a rewrite that didn't deviate too far API-wise was seemingly the easiest/fastest way forward. Like the original comment asserts: Don't be afraid to use libraries, but choose them wisely.

But in your example, even if an ORM doesn't provide native breakout functionality, it should be obvious that you can maintain a bespoke path to the database for cases where the ORM doesn't fit. Where that isn't obvious to someone, perhaps 'creating their own ORM' isn't the waste of time you make it out to be, but is actually necessary education?

If you are No-name CRUD Company you're probably not hiring the million dollar per year devs who have learned all the lessons. You kind of have to accept that you are working with budget workers and thus learning on the job is going to need to take place, even if you wish that weren't the reality you face.

replies(1): >>43634641 #
22. jandrewrogers ◴[] No.43633862{4}[source]
Anecdotally, working on mission-critical always-on systems when I was a junior developer was influential on the development of good habits when writing code that have carried through in contexts where such code quality was not required. In my view I benefited greatly from this exposure early in my career.

A lot of it is pretty basic: checking every single return code, testing every single branch, verifying that the external environment is doing what it claims or should be doing. All of this is muscle memory now, I find it difficult to write a throwaway python script without doing this. I also don’t feel like the degree of thoroughness I put into it significantly slows down development either compared to other developers that YOLO it a bit more; I spend a bit more time writing it, they spend a bit more time debugging it in test. And in prod, the former approach has lower defect rates.

It doesn’t need to be safety critical embedded software, which has a somewhat niche set of problems. Even fairly high-level data infrastructure has many of these same challenges.

replies(1): >>43638368 #
23. __mharrison__ ◴[] No.43634520{4}[source]
I would venture that very few open source projects are "SQLite-grade". Very high bar.
24. hiAndrewQuinn ◴[] No.43634548{4}[source]
I'm not averse to working on safety critical stuff in a vacuum but if they expect me to do safety critical stuff at the same pace I do my very non-safety critical stuff I'm going to expect a significant salary premium, probably at least 1.5x up from what I'm making currently. I need to charge more if I'm going to be directly responsible for the loss of lives, because sooner or later I'm going to start losing sleep over it.
25. pc86 ◴[] No.43634641{6}[source]
TIL anyone making less than $1M/yr is budget. I was specifically calling out being able to do so (easily) from within the ORM itself, so I think implying that I don't know you can just call the database directly is a bit of a strawman.

At the risk of going off on a tangent, the median dev salary is something like $100-150k/yr. So half of devs in the country make less than that. Gergely Orosz has a great discussion of this.[0] $1m/yr TC is the top 0.01% of the top tier of companies. Some FAANG-level tech firms are here but otherwise it's almost entirely IB, HFT, hedge funds, that sort of thing. I'd be shocked if anyone making close to $1m/yr TC is ever touching an ORM in their day job.

[0] https://newsletter.pragmaticengineer.com/p/trimodal-nature-o...

replies(2): >>43634965 #>>43645838 #
26. 9rx ◴[] No.43634965{7}[source]
> I was specifically calling out being able to do so (easily) from within the ORM itself

But, as I said, even if it isn't built-in, it doesn't make any difference, does it? Either way there is no reason to throw a perfectly good ORM out the window just because in some cases it isn't the right tool for the job. Surely you agree? That was my interpretation of the intent of your earlier comment.

While it may be true that ORMs today are of SQLite quality, the original commenter's point still stands: You need to make sure that is the case, else you are going to quickly wish that you did write it yourself.

> So half of devs in the country make less than that.

You may take things a bit too literally, but if you want to go down this road, do you truly believe that half of all devs have learned all the lessons there are to learn in software? Color me skeptical. 0.01% is likely even pushing it.

27. tshaddox ◴[] No.43635012[source]
What programming languages are you using? Compilers and interpreters are pretty darn complicated, not to mention operating systems and computer hardware.
28. awkward ◴[] No.43635035{4}[source]
Not to get too off topic, but ORMs are bags of design flaws. They are definitional technical debt, the kind that gets you from proof of concept but needs to be reworked once you get to your target scale.

There are a large number of fundamental impedance mismatches between relational data and object based data. Any ORM can fix some of them at the cost of ignoring others, but the fundamental character of ORMs is such that taking an opinionated line on tough tradeoffs is as good as you can hope for.

This is why ORM guy is wasting everyone's time - his problem is almost definitely not going to have a unique or even valuable perspective on all of those tradeoffs.

replies(2): >>43635196 #>>43637739 #
29. rcxdude ◴[] No.43635091[source]
I think you may have misread, they are saying they will try to stay on something as common and boring as possible, as opposed to NIH.
30. rcxdude ◴[] No.43635135{5}[source]
From my experience in the industry, if the average backend dev went to work in that industry, the average level of competence would go up (compare the average salary, for one thing). The processes are all about making it hard to fuck up really badly, they're very much not going to weed out 'careless' devs, just limit the damage they can do.
31. 9rx ◴[] No.43635196{5}[source]
In realistic practice there is no escaping it, though. Even if you maintain relations throughout the majority of your application, you are almost certainly still going to need to call some kind of third-party API or networked service that requires mapping between relations and objects. Especially if networked services are involved as they nearly always eschew relations in favour of objects to avoid the typical n+1 problems.

Should your application map objects and relations at all isn't usually a question you get to ask unless it is doesn't do much or lives on its own private island. Should you do it yourself or lean on a toolkit to help is the question that you have to contend with.

replies(2): >>43635529 #>>43635555 #
32. awkward ◴[] No.43635529{6}[source]
Oh for sure, they fill huge and consistent gap between most databases and most programming languages. The issue is that they are fundamentally a compromise. That means it's not damning to hear that issues crept in with scale and complexity. It's also rarely practical to take on the project of making a slightly different set of compromises from first principles.
replies(1): >>43635731 #
33. seadan83 ◴[] No.43635555{6}[source]
A DB query without ORM is effectively a service. This hides relations in the DB layer, rendering moot the need to model these relations in object oriented code. Thus, eschewing the ORM completely moots the question of whether to map objects and relations. I'd suggest if you are ever asking that question, you are already screwed.
replies(1): >>43635852 #
34. flessner ◴[] No.43635674[source]
I think you're correct, but certain libraries are so widespread enough that it's sensible. Especially S3, SQLite (as mentioned), Postgres and Redis usually offer good abstractions.

Other than that, time and crypto are two things I also wouldn't code myself, both are just too easy to mess up.

35. 9rx ◴[] No.43635731{7}[source]
> The issue is that they are fundamentally a compromise.

Which is no doubt why most newer applications I see these days have trended towards carrying relations as far as they can go, only mapping with objects at the points where it is absolutely necessary.

> It's also rarely practical to take on the project of making a slightly different set of compromise

I suppose that is the other benefit of delaying mapping until necessary. What needs to be mapped will be more limited in scope and can be identified as such. You don't have to build a huge framework that can handle all conceivable cases. You can reduce it to only what you need, which is usually not going to be much, and can determine what tradeoffs best suit in that. In this type of situation it is likely that using a ORM library is going to be a bigger waste of time, honestly.

36. 9rx ◴[] No.43635852{7}[source]
Querying and ORM are very different concepts. Object-relation mapping is concerned with, as it literally asserts, mapping between relations (or, more likely in practice, tables – but they are similar enough for the sake of this discussion) and objects. Maybe you are confusing ORM with the active record pattern (popularized by ActiveRecord, the library) which combines query building and ORM into some kind of unified concept? ActiveRecord, the library, confusingly called itself ORM when it was released which may be the source of that.
replies(2): >>43638417 #>>43640138 #
37. aftbit ◴[] No.43637001{4}[source]
I've developed a deep distrust of ORMs at all. I've found that the majority of simple CRUD projects are better served by just having a DAL with explicitly written (or generated) methods instead.
replies(2): >>43637177 #>>43637512 #
38. sitkack ◴[] No.43637040[source]
You ultimately own all of your dependencies, even if you never look at them. Back in the 90s and early 2000s, when starting a new project I'd do a couple things.

1) look for all the problems we were going to need to solve and look for 3rd party libs that solve those problems

2) I would do a set of PoC using just that 3rd party library and see what the dev experience as like. I build it from source, read the code, look at the code hygiene, etc.

3) Everything would get checked in as source into our repo, a "full build" would build the 3rd party libraries, you would get source level debugging into everything. You could make invasive changes into libs as part of development, etc.

Every dependency had to earn its place, you didn't just pull in a bunch of things because you needed one function.

When you need this capability is at the exact wrong time for your build and dev process to be able to take on this work. People are panicking, shits broken, no one knows what is going on. If you have everything lined up, you can still do solid engineering using the scientific method, fix your problem and move on.

39. plandis ◴[] No.43637177{5}[source]
ORMs have the problem that they are only useful for projects with some complexity but not too much.

It’s overkill for small projects and not expressive enough if you’re doing really complicated stuff. Even if you do have a good use case for an ORM currently as your requirements grow it gets harder to hack stuff on that you need.

40. 9rx ◴[] No.43637512{5}[source]
> just having a DAL with explicitly written (or generated) methods instead.

That's a bit orthogonal. Even if you use an ORM library, you'd be remiss to not put it behind a DAL. But from your DAL if you emit/accept objects of your own transformation: Congratulations, you've just invented an ORM. You can emit/accept relations, which is quite justifiable, but even then you are bound to have to map it to objects at some point. e.g. interfacing with third-parties that require objects. There is really no escaping ORM in any reasonably complex real-world application.

replies(1): >>43638221 #
41. g8oz ◴[] No.43637534{5}[source]
A maintainer of moment.js has moved on with an immutable rewrite called luxon.js. Highly recommended.

https://github.com/moment/luxon/blob/master/docs/why.md

42. bob1029 ◴[] No.43637739{5}[source]
> There are a large number of fundamental impedance mismatches between relational data and object based data

My experience tells me that the largest among these impedance mismatches is the inability for OOP languages to express circular dependencies without resorting to messy hackarounds. Developers often fail to realize how far they are into the dragon's den until they need to start serializing their object graphs.

https://github.com/dotnet/runtime/issues/29900

43. necovek ◴[] No.43638221{6}[source]
"Objects" implies a few more properties than a simple data carrying container: while it might be expressed in a particular language using classes/objects, you really don't care about any of the "object"-like features other than the ability for it to contain attributes.

Generally, you can go a long way with simple, combined types which are closer to maps/hashes/dicts than to "objects" other than syntax (.attr vs ["attr"]).

And really, that would be my preference: combine a query builder (some ORMs have great ones too) with native types representing the data read from the database.

replies(1): >>43638312 #
44. 9rx ◴[] No.43638312{7}[source]
> "Objects" implies a few more properties than a simple data carrying container:

Agreed. Of course, strictly speaking, a relation is specifically a set of tuples. But if you are working with a SQL database, which has been implied, you are already long past that idea, so it is understood that we're speaking of the concept somewhat more loosely. An instance of a class with a set of basic properties nestled in an array would still reasonably be considered a relation as it pertains to this discussion, as far as I am concerned, and seemingly you too. Fair to say you haven't meaningfully changed the semantics of the data in that.

But that doesn't mean you won't need to map to objects. You almost certainly will at some point in a reasonably complex application, even if only to interface with third-parties.

45. j45 ◴[] No.43638368{5}[source]
It seems like languages like Go promote this kind of development innately. I'm relatively new to it but found that much interesting about it.
46. skydhash ◴[] No.43638417{8}[source]
Was confused by that too (ORM and Active Records), but I spend some time learning about DDD which leads me into enterprise architecture and that's when I all the design pattern for interacting with data. Most web frameworks only have Query Builder and Active Records.
47. diggan ◴[] No.43638665{4}[source]
I think both makes sense, different times/contexts require different solutions. Maybe when the project started, the idea was loosely defined, so being able to change large parts quickly are favored over ideal performance.

But as the idea and project cements itself, you start to see exactly where the biggest flaws are, and you might draw the conclusion that a lot of problems could be fixed at the ORM layer, so you opt for working on that.

Maybe it would have been obvious from the beginning, but chances are the people working on the codebase initially had a very different idea of what exactly is the ideal design, compared to later on in the lifetime of the project.

48. sevensor ◴[] No.43638701[source]
Ooh, I was in semiconductor manufacturing too! As a junior ion implant engineer, I was looking into yield problems. Some of the tests were flaky and I traced the issue back to one of the transistors not delivering enough current. Great, we know how to fix that! More arsenic! I proposed a small scale experiment, those wafers tested great, and we started rolling out the process change. Those wafers tested great too.

Until we got word back from packaging post test. Every single die failed for excessive current draw. Several hundreds of thousands of dollars worth of scrap. I was correct, but I wasn’t deeply correct.

What surprises me in retrospect is that everybody signed off on this. It’s not like we didn’t have processes, I just somehow managed to talk a bunch of people who should have known better into doing it anyway.

49. whstl ◴[] No.43638749{5}[source]
I am shocked because this was not always the reality.

I have qualified my statement with "modern".

50. whstl ◴[] No.43638768{4}[source]
> The state of ORM libraries is probably a lot better today

I would say it's not. Sure old ORMs still have their features, but newer ORMs and especially ORMs in newer languages have a fraction of the features of something like ActiveRecord or Entity Framework.

51. whstl ◴[] No.43638833{5}[source]
Entity Framework is in a completely different class from pretty much every ORM out there, with only a handful of exceptions. Even ActiveRecord in Rails is a toy compared to it.

Even back when it was launched EF was miles ahead of most mature ORMs of today, and I believe your 95% number. But other than EF plus a handful of other mature ORMs, the 95% number looks more like 50%.

I would even argue that new-ish ORMs are virtually useless for anything that's not CRUD, and that the CRUD part can be 100% replaced seamlessly by something like PostgREST/Supabase or Hasura without losing much.

I don't disagree with the feeling in general, but I feel like we are making mistakes by having as much faith in modern ORMs and even libraries in general. Veeeeeeery few things even come close to being 1% as good as Entity Framework, ASP.NET, Rails, Postgres or SQLite.

replies(1): >>43643194 #
52. tcfhgj ◴[] No.43638956{3}[source]
How many could potentially discover security vulnerabilities in your code vs popular lib?
53. seadan83 ◴[] No.43640138{8}[source]
First, for definitions, I'd suggest we use wikipedia for ORM [1] and also Active Record Pattern [2].

I believe Active Record is a more specific implementation of something that is ORM-like. We can stop speaking of Active Record since my point holds for the more generic ORM, and therefore holds for Active Record as well.

To clarify my point, there is a fundamental impedance mismatch between object mapping of data vs relational database mapping of data. One implication of this is you cannot use database as a service. Interactions with database must instead be gated behind the ORM and the ORM controls the database interaction.

I'll note that database as a service is very powerful. For example, when there is an API contract exposing a value that is powered by some raw-dog SQL, when the database changes, anything using the API does not need to change. Only the SQL changes. In contrast, when an ORM exposes an object, an attribute might sometimes be loaded, sometimes not. A change to load or not load that attribute ripples through everything that uses that object. That type of change in ORM-land is the stuff of either N+1 problems, or Null-Pointers.

To back up a bit, let me re-iterate a bit about the impedance mismatch. Wikipedia speaks of this [1]: "By contrast, relational databases, such as SQL, group scalars into tuples, which are then enumerated in tables. Tuples and objects have some general similarity... They have many differences, though"

To drive the point home - in other words, you can't do everything in object world that you can do in a database 1:1. A consequence of this is that the ORM requires the application to view the database as a persistence store (AKA: data-store, AKA: object store, AKA: persistence layer). The ORM controls the interaction with database, you can't just use database as a data service.

I believe this point is illustrated most easily from queries.

To illustrate, let's pull some query code [3] from Java's Hibernate, a prototypical ORM.

```

public Movie getMovie(Long movieId) {

    EntityManager em = getEntityManager();

    Movie movie = em.find(Movie.class, new Long(movieId));

    em.detach(movie);

    return movie;
}

```

So, getting a release year might look like this:

```

int movieId = 123;

Movie m = orm.getMovie(movieId);

return m.getReleaseYear();

```

In contrast, if we put some raw-dogged SQL behind a method, we get this code:

```

int movieId = 123;

return movieDao.getMovieReleaseYearByMovieId(movieId);

```

Now, let's illustrate. To do this, let us look at the example of finding the release year of the highest grossing movie. As a service, that looks like this:

```

return dao.findReleaseYearOfHighestGrossingMovie();

```

In contrast, as an ORM, you might have to load all Movies and then iterate. Maybe the ORM might have some magic sugar to get a 'min/max' value though. We can go on though, let's say we want to get the directors of the top 10 grossing movies. An ORM will almost certainly require you to load all movies and then iterate, or start creating some objects specifically to represent that data. In all cases, an ORM presents the contract is an an object rather than as an API call (AKA, a service).

For the update case, ORMs often do pretty well. ORMs can get into trouble with the impedance mismatch when doing things like trying to update joined entities. For example, "update all actors in movie X". Further, ORM (and objects) creates issues of stale/warm caches, nullity, mutability, performance, and more... What is worse, all of this is intrinsic, relational data and objects are intrinsically different.

[1] https://en.wikipedia.org/wiki/Object%E2%80%93relational_mapp...

[2] https://en.wikipedia.org/wiki/Active_record_pattern

[3] https://www.baeldung.com/hibernate-entitymanager

replies(1): >>43641076 #
54. 9rx ◴[] No.43641076{9}[source]
> To illustrate, let's pull some query code [3] from Java's Hibernate, a prototypical ORM.

ORM and entity manager – which, in turn, is a query builder combined with a few other features. Your code is really focused on the latter. While the entity manager approach is not the same as active record, that is true, the bounds between query building and ORM, I think, are even clearer. In fact, your code makes that separation quite explicit. I can at least understand how ORM and query building get confused under active record.

> We can stop speaking of Active Record

While I agree in theory, since we are talking about ORM only, if we go by Wikipedia we cannot as is ends up confusing active record and ORM as being one and the same. That is a mistake. But as my teachers, and presumably yours too, told me in school: Don't trust everything you read on Wikipedia.

But we don't need to go to Wikipedia here anyway. Refreshingly, ORM literally tells what it is right in its name. All you need to do is spell it out: Object-Relation Mapping.

55. pc86 ◴[] No.43643194{6}[source]
I've yet to find a simple-to-moderately-complex CRUD use case that Supabase can't handle with almost no manual configuration required. There are a few postgres things they hide that you need for more advanced uses but overall it's a great product especially if you're willing to go full vendor lock-in and use them for auth, blob storage, etc.

I have a side project that uses Clerk for auth but basically every other supabase product there is and it really is great for smaller use cases. I don't know how it stacks up once you start needing really fine-tuned database permissions or functionality though.

replies(1): >>43644021 #
56. whstl ◴[] No.43644021{7}[source]
Yep, that's also my experience, my current job uses it for some products.

I find it that if you accept Supabase as-is, it can get you pretty far and save a lot of time and money.

And for edge cases, it's like you said above about ORMs, we don't have to throw it out, we just handle those cases separately.

57. roguecoder ◴[] No.43644940[source]
Frameworks are just someone else's architecture.

They are helpful if you have the same problems as that other company, but I worry about software that uses frameworks because the programmers don't feel confident building their own. It means when it comes time to evolve beyond the off-the-shelf architecture, programmers keep plowing ahead far past when they should have added another level of abstraction & encapsulation.

On the other hand, I also see applications where people dogmatically avoid using pre-existing architectures but also don't take the time to build their own. You end up with references to one table scattered all across the code base in hand-composed SQL.

I'd much rather take an outgrown-framework over a spaghetti mess.

58. fragmede ◴[] No.43645838{7}[source]
it's not $1m TC but $1m cost to the company, all in, which is still high, but not the top 0.01%
59. yndoendo ◴[] No.43654183{5}[source]
The original designer for my most active product I work on choose EntityFramework. Used it for about 1.5 years before looking at the SQL statements it produced. It was a excessive UNION mess. Things that should be simple where 10x more complex.

Slowly replaced it with Dapper and handwritten SQL, a simple migration versioning system, and database seeding with validation. Once that was done, startup time was cut by more than 10 seconds on a standard SSD and about 30 on CFast. Even finally replacing the database connection with SQLite standard libraries shaved off 2 seconds.

EntityFramework maybe useful but it lacks performance when time to start using the software is important.

60. ◴[] No.43658889{3}[source]
61. methods21 ◴[] No.43658894{4}[source]
I see 'this guy' who wants or does build his own ORM, in every company I've worked with.