3 ms·
Having used functional languages extensively in a job setting and now using C++ more and more, I find that there's nothing wrong in just writing procedural code
by hellofunk 6y ago
Having used functional languages extensively in a job setting and now using C++ more and more, I find that there's nothing wrong in just writing procedural code if that's easier. Easier both to write and easier to read later. I've seen people take 20 minutes to write a single line of functional Javascript or Kotlin, when the underlying work is obvious and just writing the loop directly would be faster to create and much easier to understand later by you or anyone else who has to read the code.
The move to functional-style code the last many years seems a bit silly to me. Even C++ has been moving in a well-known trend of "no raw loops" in favor of the algorithms header in STL. I don't find there is a significant reason to abandon easy code most of the time. If you actually need to use the functional paradigm to swap out behavior in a polymorphic fashion using functions instead of inheritance, for example, then great.
- RHSeeger 6y agoI tend to go with whatever makes the code the most readable; best expresses the intent. If I'm iterating over a list, mapping each element to a lookup somewhere, and then removing those that weren't found... that's a good choice for functional. If I'm iterating over a list, if it matches one thing do something, otherwise filter it some more and do something else... I tend to find procedural is easier to read. Maybe it's a transform vs act-on type of thing; I'm not sure.