2 ms·
I would disagree and say the functional style is perfectly fine in its one-liner form. I'd even say it is preferable in many cases over using intermediate varia
by phamilton 11y ago
I would disagree and say the functional style is perfectly fine in its one-liner form. I'd even say it is preferable in many cases over using intermediate variables. Why? Because naming is hard and more often than not I see the intermediate variables named things like "sorted_histogram" or "sorted_reversed_histogram" which is hardly any clearer than "@histogram.sort_by{..}.reverse" while being much more verbose.
Intermediate variables in functional languages are largely used for memoization. Occasionally are they used for self-documentation but generally I see "people.map(&:full_name)" over "full_names = people.map{ |p| p.first_name + ' ' + p.last_name }".
- dbattaglia 11y agoFor me the debugger tends to drive if I use one liners often or not. In C++ or C# it tends to be easier to step thru code if it's broken out. In Ruby I think it's probably less common to work with a source stepping debugger so it feels more natural to write nice functional one liners that do a lot.