I guess readability is subjective, but to me |
That's good feedback though. It does feel a tad over-engineered which is why I asked initially. I feel as though if the expressions get a bit more complicated it might be easier to read them if they're broken up into named lambdas, like this. . . but making them member functions or stand-alone functions seems a bit overboard, cause they're only really used that once.
Also, I like my code to be fairly self documenting, which is why I try to stay away from "magic numbers" and instead try to encapsulate ideas in named lambdas. For instance, if I saw,
if(bunny.getAge() > 2) {}
I'd think, "Ok, so we're checking to see if the bunny's age is over 2, but why?" In the context of this program it means that the bunny is an adult, in the context of another program it could mean something entirely different. Granted, that could possibly be simplified with a named constant like
if(bunny.getAge() > AGE_OF_CONSENT){}
so it really is a preferential thing and I value your feedback.
I'm not saying a capturing lambda is necessarily less efficient. Compilers are very good at optimizing and inline local lambdas.
Good to know :)
They say you write good code by first imitating those who write good code, so I'm just trying to get a sense of how to balance efficiency with readability and elegance and maintainability and all that stuff...
Thanks!