4 ms·
> Look, I’m all for being clever when cleverness is needed but some of you JS/TS folks take it to the extreme. To be fair, this is very much a toy example mean
by mhink 3y ago
> Look, I’m all for being clever when cleverness is needed but some of you JS/TS folks take it to the extreme.
To be fair, this is very much a toy example meant to demonstrate tail recursion- although I do agree it's not a great example considering you need to understand the evaluation order of ternaries in order to understand why one version is tail-recursive and the other isn't.
That being said: generally speaking, one might argue that using recursion at all is "too clever" and algorithms should just stick to iteration altogether. ¯\_(ツ)_/¯
> While you can nest a recursive function in a tertiary statement coro, don’t.
Man, why do you gotta call me out like this? :D
- akoboldfrying 3y ago>algorithms should just stick to iteration altogether Well, if your algorithm performs 2 or more recursive calls per function invocation (like, say, quicksort), at least one of them needs to be an actual recursive call that uses additional stack space, since TCO is only able to mitigate a single recursive call per function invocation. (You could simulate your own stack and use iteration... but the only reason to do so in practice would be to escape some artificial restriction on native stack size.)
- reactordev 3y ago>”Man, why do you gotta call me out like this?” Because you lose the stack trace most of the time. Only God and you know where the Uncaught PromiseRejection happened. It’s just really hard to debug when things go south. This drives me bonkers with the AWS sdk.