News for hackers. Stuff that matters.
Re:TypeScript is terrible for library developers by int_19h on Tuesday August 23, 2022 @08:30PM (#32573511)
I don't see what's complicated about this example. It adds overloads, but those aren't hard, either.
Re:TypeScript is terrible for library developers by nerdponx on Tuesday August 23, 2022 @08:56PM (#32573709)
Fair, it's not "hard". But I stand by my assertion that it's a huge ugly pain in the butt. That doesn't mean it's not worth doing, but that doesn't make it less huge, ugly, or painful.

I also assert that if NDFrame.loc were less polymorphic (e.g. if you had a separate accessor like NDFrame.mask for boolean subsetting) it would be easier to use, easier to reason about, easier to teach, easier to document, and easier to write type hints for.

The worst situation is when you want to have multiple return types depending on the argument values, like Pandas' inplace=True. Putting aside the problem of dependent types, even supporting only literal True and False requires you to write out every single overload twice, creating a literal combinatorial explosion of overloads.

And that's also ignoring the whole world of parametric polymorphism required for higher-order functions, factory functions etc.

Maybe the situation is no better in something like C++, but I don't know enough C++ to have an opinion on it.

Re:TypeScript is terrible for library developers by fshr on Wednesday August 24, 2022 @12:16AM (#32574920)
To be fair, there are few things as here-be-dragons as the guts of Pandas. It'd be hard to find a more rarified example, but it served to further the conversation at least.