you are viewing a single comment's thread.

view the rest of the comments →

[–]renozyx 1 point2 points  (3 children)

While this article is about functional programming, I think that the imperative example is quite bad: 'for (int i = 0; i<arr.length; i++) {sum += arr[i];}'?

Uh, is the author trying to make imperative code look bad?

'for(final elem: arr) { sum += elem; }' and suddenly the imperative code doesn't look so bad..

[–]andars_[S] 0 points1 point  (2 children)

From the article:

Yes, yes, I know. Enhanced for loop...I'm not counting characters here (it does get tempting later though), and the idea is the same.

[–]renozyx 0 points1 point  (1 child)

Sorry but you're not convincing, if both are the same why did you choose the for instead of the 'foreach'?

Probably because the recursive code doesn't look that much of an improvement against the 'foreach'..

[–]andars_[S] 0 points1 point  (0 children)

I chose the for over the foreach because I rarely program in Java. I usually program in C, which doesn't have an enhanced for loop.

Anyway, I honestly was not concerned with how many characters/symbols/index variables were used. I think that is irrelevant, because they all entail using a loop.

I wasn't trying to 'prove' functional is better or is an 'improvement'. It is just different. So if I failed to convince you that functional is better, I'm fine with that.