2 ms·
> I believe avoiding unnecessary temporary variables in a very valuable thing for the reasonability of code I’m not convinced temp vars are avoidable in produc
by dahart 5y ago
> I believe avoiding unnecessary temporary variables in a very valuable thing for the reasonability of code
I’m not convinced temp vars are avoidable in production code, since usually you end up needing error checking/handling on intermediate results anyway. Teams I’ve worked on generally try to avoid dense nested and/or chained expressions for this reason, but also because too much density or conciseness also limits the readability/reasonability of code.
I like that pipes turn nested expressions right-side out like the article points out, but temp vars already do this too.
The other thing that temp vars help with is making it easier to change functions in the middle of a sequence. If you have a nested expression, sometimes having to refactor something in the middle leads to a bigger avalanche of changes than necessary. Using temp vars might be somewhat less churn in some cases due to already haven broken down the expression into pieces. Maybe this pipes design will allow that too, it’s hard to say without using it for a while.
- xixixao 5y agoIn practice pipes actually work in the opposite direction, the one you like: they allow people to break down nested expressions. Pipes allow the language to report granular line numbers and you can do error handling in them, if it’s functional (not if you need try catch of course). While I’ve been on the team pushing for pipes and for the Hack variant, I do appreciate that there are many instances where giving an expression a name is helpful. This is a tool that comes with great responsibility. My hope is that people will learn how to use it. It’s worth it imho the added language complexity.