5 ms·
Well, this is not the best example, imo. I have very littile knowledge of Java, but it's clear as day that we filter only entities with male gender, get their
by konart 10y ago
Well, this is not the best example, imo.
I have very littile knowledge of Java, but it's clear as day that we filter only entities with male gender, get their age values and return average.
I mean... really.
- oconnor663 10y agoI think one of the simple differences between functional and imperative code is just that functional code is less likely to name its intermediate values. Imperative code is probably going to put something in a local variable, which hopefully has a useful name, but functional code is probably going to chain a bunch of generic methods together. This isn't a big deal when what I'm looking at is "students.filter(...MALE)" because that's obviously the "male students". But it quickly gets more confusing. What is "students.filter(... == year - 3)"? Is that "freshman students" or "sophomore students" or something else entirely? Of course there's nothing stopping functional programmers from naming their intermediate results, and nothing stopping imperative programmers from choosing useless 1-letter variable names. But the two different programming styles seem to encourage different things.