I'm trying to make a spreadsheet interface for solving scheduling problems.
Constraint satisfaction and optimization is exactly the sort of problem we should be using computers for, but there's zero chance your neighborhood cafe can figure out prolog or OR-tools or whatever.
There are a couple of attempts in that direction with TypeScript[1,2]. A bit more work than if there was direct language support, but I've used "branded types" to distinguish between UserIds and ProductIds, between different types of currency, and between different unit systems.
> E.g. I couldn’t for the life of me annotate the return value of the pipe function
Don't feel bad, no one can do that (yet! I think it should be possible with Variadic Tuple Types, coming in TS 4). There are a couple of attempts[1][2], but they all lack in some way. Redux does it with a boatload of overloads [3].
I think you might be underestimating how hard breastfeeding is pushed in US hospitals. Our second night in the hospital with my son, my wife's milk hadn't come in yet.
Our son was screaming because he was hungry. The nurse kept saying this was good, that it would encourage breast milk production. It took several tries to convince her that, while it might be good in the long run, we needed some food for this baby.
This was a consistent experience with all nurses we dealt with. Interestingly, breastfeeding specialists tended to be more understanding.
I don’t have any kids, but I can’t figure out what people are actually
complaining about here. Most comments seem to be referring to breast feeding in the hospital in the few days post birth. Is it just hospital culture we’re upset with? My understanding was that breast milk is generally pretty important to do as it helps transmit antibodies and the like. But, having some formula is fine too.
I see older cases about nestle misleading women in developing markets to suggest formula was better, which led to deaths. However this seems to be due to nutritional deficiencies which I, perhaps naively, would assume they have figured out by now.
> I see older cases about nestle misleading women in developing markets to suggest formula was better, which led to deaths. However this seems to be due to nutritional deficiencies which I, perhaps naively, would assume they have figured out by now.
They have, it's fine.
> But, having some formula is fine too.
It is harder to get the baby on the breastfeeding train, if you will, if you're switching between breast and bottle. You can pump but many women find that really distasteful and either way it takes up shitloads of time and their body might still not cooperate. A surprising percentage of babies (admittedly anecdotal, but I'm a parent and know lots of others and the sample size is actually pretty large as a result, though not randomized) have a hell of a time "latching" and actually getting enough milk out, and that's if the mother's body's producing enough, both of which are hard to measure so it's really easy to end up with a baby who's in the "failing to thrive" range which can lead to further hospitalization (and more judgement from nurses and such).
Frankly, as soon as shit gets a little sketchy I'd say just go straight to formula and bottle. It's not as good, sure, but the other way seems to be wildly harder and more difficult to track, unless you get very lucky and have one of those pairings where both mother and baby sync up perfectly and it just goes great, in which case it's merely very time-consuming. This is like 20% of babies at best, in my experience.
The rest get to deal with non-stop stink-eye and condescension from nurses and other care providers while they're stressed out, hurting, and anxious already, to probably still fail at the whole breast feeding thing even if they try hard and feel like shit for weeks and maybe don't get their baby enough food to grow properly while attempting it.
Python is scary sometimes. If it looks like a duck and quacks like a duck and isinstance(duck), it might be an alien masquerading as a duck using metaclasses to accomplish these feats. But with this craziness comes the ability to make a transparent runtime proxy to just about anything in Python, and do so recursively e.g. to track all uses of an object hierarchy.
I think I'm confused. If you want to delegate _everything_, why not just actually use inheritance? Or even the object itself. What's an example of when you would want an ObjectProxy?
Definitely agree about metaclass magic being a blessing and a curse. That superdelegate library was fun to write and uses a metaclass to make the API pleasant.
If you don't know what you're going to need to wrap (heck, it might be something with methods implemented with native code), but you want to override or intercept a certain subset of calls, then composition/delegation is really the only thing you can do. It's significantly more stable than trying to find the class of an arbitrary object at runtime, create a subclass of it, and try to copy the state of the original object.
For instance, I've seen instrumentation libraries monkey-patch database cursors with wrappers around those cursors, so the library can detect usage of the cursor without changing its behavior.
And I'm using wrapt in a project (which I hope to open source) where, by recursively wrapping the return value of every __getitem__ and __getattr__ with a properly-bookkept proxy object, you can see what subgraph of a complicated object hierarchy was actually used by a function call (say, the rendering of a Django or Jinja template). Possibilities of such a transformation are endless!
You don't have to sacrifice type safety, that's a python problem. Other languages (eg: Groovy) accomplish the same thing in a type-safe way (see @Delegate annotation [1]).
reply