Hacker News new | ask | show | jobs
by claytongulick 1560 days ago
What I'm referring to is non-trivial function definitions.

Things with optional parameters that can accept a wide variety of types, async callbacks and async variadic return types.

The hoops you need to jump through to make the compiler happy are absurd.

2 comments

Functions like the ones you are describing probably shouldn't exist!

I have no doubt that a sizable portion of these functions' bodies is dedicated to figuring out which type each of our input variables represent (from our wide variety). So now instead of having our editor/compiler help us out, we are now actually writing code to figure it out ourselves... this is more absurd (and less efficient).

And FWIW, using union types makes it trivial to denote that a function can accept a wide variety of types in a type-safe way. But guess what you will be doing first thing in the function body? Discriminating that union!

Sounds like a problem with some API trying to make everyone happy.

Could be avoided by having more functions, one for each case.

(Only if you control the code, of course.)