book icon indicating copy to clipboard operation
book copied to clipboard

Poor code example in loop labels

Open ghost opened this issue 2 years ago • 1 comments
trafficstars

The part that got me the most was this: Loop Labels. I was pretty confused when I read it. If you read below, you see: "The outer loop has the label 'counting_up, and it will count up from 0 to 2." It's pretty hard to tell that when I read the code.

If you scroll a little further, you see a variable called "number", and one called "a". The letter a.

My point is the code is really hard to follow, and in several other places there is a lack of good names for functions and variables and little to no abstraction in irrelevant areas (at least in this chapter). I understand if you're teaching conditionals you won't hide the logic for it in a function call. But properly applied abstraction for the rest of the code can go a long way to making it more readable and easier to understand and reason about.

ghost avatar Mar 25 '23 04:03 ghost

I second you. The example is a bit hard to follow.

postmeback avatar Jul 08 '23 09:07 postmeback

Thanks for the report, and sorry that you found it a bit confusing. After reviewing it, though, the complexity is in dealing with nested loops—which is one reason Rust users often use iterator operations instead of nested loops! But here, the code is showing a complicated dance for a reason: because that's what you need to show the value of something like break labels. In general, yeah, you should avoid complicated code like this! But the book can’t, because it needs to show the complicated thing to show how it works!

I am going to go ahead and close this, but thanks for the feedback.

chriskrycho avatar Apr 02 '24 21:04 chriskrycho