I don't think the code comprehension problems have anything to do with the type of loop, but with the density of the code. If I look at the while loop you wrote, I do not only see a condition, but also up to two side effects (depending on whether or not the evaluation is short-circuited). This single line has up to four different responsibilities.
I actually think a while loop is the more suitable option, but maybe the introduction of one or two explanatory variables could enhance readability a lot.
Code comprehension though is not always a objective term. Sometimes it heavily depends on a person's perception. Throughout my career I've seen different styles of coding and I tend to accept them.
In this case they felt that for is more readable so I let them change it (for me it's tom[a]to, tomat[o]). Now if they chose, to do it with recursion, again I wouldn't object to it.
Recursion is another fine example of a style. Some people love it, it make sense to them. Others are afraid of it.
once we had a guy that only wrote decrementing-for-loop...nowadays everyone hates his legacy code. But if you ask me...they get stuck at details and not the big picture, and the big picture is that he code was a freaking masterpiece. Sometimes hard to read, but he wrote the most resilient consumer services I've ever seen.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi, in this case i find the for loop way more developer friendlier and easier to understand. Thanks for sharing this.
I am trying to understand as to why is a
for loopfriendlier than awhile loopbecause to I've heard a similar thing for
switchesin the past compared toifsI don't think the code comprehension problems have anything to do with the type of loop, but with the density of the code. If I look at the while loop you wrote, I do not only see a condition, but also up to two side effects (depending on whether or not the evaluation is short-circuited). This single line has up to four different responsibilities.
I actually think a while loop is the more suitable option, but maybe the introduction of one or two explanatory variables could enhance readability a lot.
Code comprehension though is not always a objective term. Sometimes it heavily depends on a person's perception. Throughout my career I've seen different styles of coding and I tend to accept them.
In this case they felt that
foris more readable so I let them change it (for me it's tom[a]to, tomat[o]). Now if they chose, to do it with recursion, again I wouldn't object to it.Recursion is another fine example of a style. Some people love it, it make sense to them. Others are afraid of it.
once we had a guy that only wrote decrementing-for-loop...nowadays everyone hates his
legacycode. But if you ask me...they get stuck at details and not the big picture, and the big picture is that he code was a freaking masterpiece. Sometimes hard to read, but he wrote the most resilient consumer services I've ever seen.