4 ms·
But this kind of functional composition often doesn't have first-class support in the language syntax. That is, it often requires you to rely on helper function
by funklute 5y ago
But this kind of functional composition often doesn't have first-class support in the language syntax. That is, it often requires you to rely on helper functions or libraries. As a result, it's not nearly as readable or intuitively obvious as the chaining example (and this is in contrast to mathematical notation, where functional composition is very clear, in my opinion).
- dragonwriter 5y ago> But this kind of functional composition often doesn’t have first-class support in the language syntax. Are we talking about Ruby? Because it does. It has both: (do_thing >> do_another_thing >> do_the_last_thing)[arg0,…,argn] And: (do_the_last_thing << do_another_thing << do_thing)[arg0,…,argn] (Where the things in the composition are procs/lambdas, the closest thing Ruby has to functions as distinct from methods.)
- funklute 5y ago> Are we talking about Ruby? I wasn't thinking specifically of Ruby (and indeed I don't know Ruby, nor was I aware that it has this kind of support). Rather, I was thinking about programming languages in general, since the top-level comment seemed to be talking about the general principle. Out of 5 languages I use on a regular basis, only one of them has _some_ support for function composition. But even then, not as flexible as what you're demonstrating here. So my point is that across programming languages, the chaining approach is generally more readable than the composition approach. And that in turn favours methods over global functions. If I ever start using Ruby, I would probably be on the fence about which approach is better though.