Why would one want to couple these two? Doesn't that couple, say, your API interface with your database schema? Whereas in reality these are separate concepts, even if, yes, sometimes you return a 'user' from an API that looks the same as the 'user' in the database? Honest question, I only just recently got into FastAPI and I was a bit confused at first that yes, it seemed like a lot of duplication, but after a little bit of experience, they are different things that aren't always the same. So what am I missing?
The ORM doesn't force you to use the DB model as your API schema. It's a regular Pydantic BaseModel, so you can make separate request/response schemas whenever you need to. For simple CRUD, using the model directly saves boilerplate. For complex cases, you decouple them as usual. The goal is not one model for everything, it's one contract. Everything speaks Pydantic, whether it's your API layer or your database layer.
Suppose an API GET /users/:username call returns a "User" type. If returns the the same type as in your database, wouldn't you also get their password hash as well with that request? How do coupled frameworks deal with this?
You might be interested in a library that flips around the concept of an ORM, like sqlc [1] or aiosql [2]. You specify just what you want from the database, without needing to couple so much API with database tables.
A lot of people have this misconception that Pydantic models are only useful for returning API responses. This is proliferated by all-in-one frameworks like FastAPI.
They are useful in and of themselves as internal business/domain objects, though. For a lot of cases I prefer lighter weight dataclasses that have less ceremony and runtime slowdown with the validation layer, but we use Pydantic models all over the place to guarantee and establish contracts for objects flowing thru our system, irrespective of external facing API layer.
One advantage of something like attrs/cattrs is you can use the regular attrs objects inside the module without all the serialisation/validation baggage, then use cattrs to do the serialisation at the edge where you need it.
With proper DRY, you shouldn't need to repeat the types, docstrings and validation rules. You should be able to say "these fields from user go on its default presenter, there are two other presenters with extra fields" without having to repeat all that info. I have a vague memory that Django Rest Framework does something of the sort.
This feels hard to express in modern type systems though. Perhaps the craziness that is Zod and Typescript could do it, but probably not Python.
With this you don't need to have two sources of truth on the backend. Previously you will end up with one set of DB ORM level validation and a second set of validation on the data transfer object and you have to make sure the types line up. Now the data transfer object will automatically inherit the correct types.
The two sources of truth are for two disparate adapters. Neither the API nor the DB define the domain, but both must adapt the domain to their respective implementation concerns.
The ontology of your persistence layer should be entirely uncoupled from that of your API, which must accommodate an external client.
I'd rather define my db domain in-code so I do not have to worry about writing the queries without type hinting.
Raw sql -> eh, I don't have the patience
Raw sql w type hints -> better, I at least get a compilation error when I do something wrong, and preferably a suggestion
ORM -> this usually introduces it's own abstraction that needs it's own maintenance, but at least it's more code-oriented.
Yes, SQL is an awesome solution to querying DB's, hence I prefer option 2
Well yeah, of course. Sorry, when I said "DB" what I should have said was "data-layer," and this can include: repositories, ORM models, query-builders, etc. All of these are type-hinted "db domain in-code" and, still, not one coupled to your API.
I also find it really strange this weird ORM fascination. Besides the generic "ORM are the Vietnam War of CS" feeling, I feel that with average database to ORM/REST things, end up with at least one of:
a) you somehow actually have a "system of record", so modelling something in a very CRUD way makes sense, but, on the other hand, who the hell ends up building so many system of record systems in the first place to need those kinds of tools and frameworks?
b) you pretend your system is somehow a system of record when it isn't and modelling everything as CRUD makes it a uniform ball of mud. I don't understand what is so important that you can uniformly "CRUD" a bunch of objects? The three most important parts of an API, making it easy to use it right, hard to use it wrong, and easy to figure out the intent behind how your system is meant to be used, are lost that way.
c) you leak your API to your database, or your database to your API, compromising both, so both sucks.
The vietnam of computer science was written 20 years ago (2006 even), and didn't kill off ORMs then. We've only had 20 years of improvement of ORMs since then. We've long ago accepted Vietnam (the country) as what it is and what it will be in the forseeable future. We should do the same with ORM.
I for one don't want to write in a low level assembly language, and shouldn't have to in 2026. Yet, SQL still feels like one.
I've written a lot of one off products using an ORM, and I don't regret any of the time savings from doing so. When and if I make $5-50M a year on a shipped product, okay, maybe I'll think about optimizing. And then I'll hire an expert while I galavant around europe.
SQL is a pretty high-level, declarative language. It's unnecessarily wordy though, and not very composable.
The problem with ORMs is that they usually give you a wrong abstraction. They map poorly on how a relational database works, and what it is capable of. But the cost of it is usually poor performance, rarely it's obvious bugs. So it's really easy to get started to use; when it starts costing you, you can optimize the few most critical paths, and just pay more and more for the DB. This looks like an okay deal for the industry, it seems.
Related to this, has anyone investigated how much typos matter in your chats? I would imagine that typing 'typescfipt' would not be a token in the input training set, so how would the model recognize this as actually meaning 'typescript'? Or does the tokenizer deal with this in an earlier stage?
GP said 'open bar with 2 bartenders'. I.e. commercially priced drinks, and staff. Did you have those? If so, pro tip, next time just get a few cases of various drinks, plonk them on a table with a bunch of glasses (rented, if need be) and call it good. People can't drink soft drink for more than, say, 3 USD worth in an afternoon; and even if you served 12 years Glenfiddich to everyone including the children, enough of it to knock them all out, you still wouldn't have spend more than $1000.
So yeah still wondering what sort of party you threw. I mean, yeah it's easily possible to spend that much, but it's also possible to do it for much less and you don't even need to really try.
You seem to be misreading his comment. Some guy making some observation biased comment is irrelevant. It's flat out wrong that Germans 'need' it less. The obesity curve in Europe trails that of the US a generation or two, yes (and several Asian ones trail it more). But the numbers and trends don't lie.
"a dude like Schwarzenegger is probably well in the overweight category"
For illustration, Arnold was 107 kg at 1m88 at his prime, giving him a BMI of 30.3, which is clinically obese. But yeah, LOL at all these people with 130 cm waists going 'BMI is useless'.
BMI still isn't great for fat people. An active fat person is going to have a significant amount of muscle compared to a sedentary fat person at the same body weight - just doing things carrying around that weight will build muscle. Some health markers, this won't matter for - your heart doesn't like pumping blood to a 300lb body, whether that's at 50% BF or 8% - but for a lot it does. Lipids, insulin resistance, etc. are going to be quite different in someone at 40% BF vs. 20% BF at similar weights with similar genetics.
Unfortunately it's not so easy to get a good BF%. BIA scales are probably what most people have access to, either at home or at their local gym, or calipers, but both are very inaccurate at getting totals and at best can help you understand trend directions. There are places to get cheap DEXAs in a lot of cities these days, but not everywhere, and $30 each time you go is still expensive for some people.
BF% and FFMI are both a lot more useful for everyone than BMI.
"Kind of tired of people taking anabolic steroids and then claiming it's a smaller part of their success"
Sounds like you've never taken steroids brother, and with that mindset you shouldn't, because I'll tell you that no matter how much you shoot into your muscles, if you don't put in the work in the gym, there's no way you're going to get jacked.
That position does not appear to be supported by clinical evidence. [This study](https://onlinelibrary.wiley.com/doi/10.1111/dar.12433) references several studies that show that taking low (in the context of gym users) doses of steriods and not exercising is more effective at building muscle mass than strength training and not taking steroids.
Steroids significantly increase glycogen/water retention in-muscle while on them and for a period of time while coming off of them. This would increase muscle size by the measures noted in Bhasin's study (the big one people reference here), but not increase the amount of actual contractile tissue. There's also a cap there - going up in dosage, going for longer, etc., is not going to continually increase overall muscle size at that rate because you've saturated the stores in the muscle for the glycogen and water.
You will gain some additional contractile tissue doing nothing on gear. The average person, if faced with the two options, will gain more actual contractile tissue opting to lift weights without gear.
You can find huge quantities of people in gyms that are on gear and look like they barely lift.
Bro science bullshit doesn't belong here. I'd rather take roids and not lift than do SS+GOMAD and listen to /fit/ memes. Rich Piana and Zyzz are dead for a reason.
Did you bother to google his handle? While I don't know his pure mathematics credentials, he's nerd-famous enough to not warrant an introduction. In fact, you not recognizing it says something about you.
To be fair, we are on hacker news. I did once use on of his programs, American Fuzzy Lopper (fake advertisement lawsuit incoming if its not american). So he is not nobody apparently
If you're mid-40s (which is the threshold ago where I am), and can afford the up front cost, consider IOL implants. Life changing (for me). (and re: costs, these drops are going to set you back $1000 a year as well, so after 7/8 years implants would be 'cheaper').
I’d really like those. My Mom got them and she said it didn’t help her near vision, which I didn’t understand. I guess she was a weird case because yeah I had just assumed that a new lens would fix the hardening of the lens with aging problem. Thanks for letting me know!
How long should your new lenses last? Did they say? Will they eventually get hard like the human body’s lens or are you set for the rest of your life? It’s really cool you are part cyborg. Did you get a monofocal or multifocal lens?
I was told these lenses are for the rest of my life. I guess I'll know for sure in 40 years. They don't develop cataract like natural lenses do, and I won't develop presbyopia as these lenses don't focus using muscles around them. I have multifocal (trifocal) lenses, for near-, medium- and long distance viewing. Theoretically this means that I need more light to see as well as naturally focusing lenses, which worried me somewhat before, but in practice I do not really experience it - in fact I need less light to see well now than I did when I had glasses. As usual in life, the key to happiness is realistic expectations - as the surgeon told me 'there is no way we will be making your eyes work as well as they did when you were 20'.
Two things I do have: for optimal near vision, I have to keep things closer to my eyes than I did before, 20-ish cm. So I had to adjust my screen viewing and reading posture. Also, I have what are called 'halos' around lights in the dark (this is a known and expected side effect, tons of YT videos that explain why they happen). Driving in the dark on highways with lots of artificial light sources has gotten more straining - meaning I need to focus more and feel more tired after driving say 2 hours in those circumstances than I did before the surgery. All other driving is the same and I don't notice the halos any more in other cases, like say when I'm just walking through the city in the dark. The driving at night price to pay is well worth it for me, may be different for others.
Re: your mom - if she got monofocal lenses (which many people here do as they are the only ones covered by insurance if you're getting lens replacement for cataract), she would have gotten the choice between near- or far focus lenses, and would have decided together with the surgeon which ones are most appropriate for her life. I mean I obviously can't tell as I don't know her, but my dad is the same - he still needs reading glasses after his cataract surgery (IOL implants == cataract surgery).
Most artificial lenses, especially more than 5 years back, had a single focal point and did not adjust. You chose to either have near vision (mostly carless old people), far vision (and still use reading glasses), or blended vision (one eye far one near).
The flexible lens stuff is still relatively new and there are reports of them sort of being like 80% focused 100% of the time, which can suck. Apparently lots of individual variability in results, where as the single-focus lenses are 60s technology and well figured out.
reply