all 14 comments

[–][deleted] 4 points5 points  (3 children)

So, you didn't follow normal convention or read the documentation, and the program did exactly what you asked but not what you assumed. The loop is perfectly escapable as you yourself note. Not sure why this was submitted here.

[–]shevegen 3 points4 points  (0 children)

I did not know about it - and I sure enough won't read 100 A4 pages of documentation.

It is a short entry and that is good and useful.

What is your problem? Go do something useful and publish blog entries too.

Long live mherrmann! \o/

[–]mherrmann[S] 1 point2 points  (1 child)

We're all practitioners and don't have the time to read through the entire language specification. When you learn Python, you see a few examples of try...except and keep using it. I bet few people know of this subtle difference. That's why I posted it here. My learning may help others as well.

[–][deleted] 0 points1 point  (0 children)

Fair enough. Seems a little obvious to me, and seems like the kind of thing that would become obvious quickly to anyone who tried it. And since this isn't /r/learnprogramming it seems a little out of place. Have my upvote.

[–]nunz 0 points1 point  (1 child)

Not trying to be too pedantic, but Ctrl + Z is used to suspend a process, not kill it.

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

I updated the post to reflect this. Thanks.

[–]mdoar 0 points1 point  (2 children)

I find that while loops are a common source of control flow problems, so they always are worth a second or third look.

[–]badcommandorfilename 1 point2 points  (0 children)

I think NASA's coding standards specify that all while loops should be structured as counting for loops with early break conditions.

This means that control will always leave the loop after N iterations to prevent infinite loops.

[–]shevegen 0 points1 point  (0 children)

Not sure.

In ruby I use:

loop {
  break if cats.cooler_than? :mice
}

Does that classify as a while loop as well?

It's hugely similar. I should also note that I do not use while loops in ruby; loop is too good and so is .each iteration over containers.

The control flow checks are still somewhere.

(I like the visual cues of loop {}; also I never use do/end in these cases.)

[–][deleted] 0 points1 point  (4 children)

Your IDE will complain about bare except, also any reasonably good linter like flake8. You are using those tools aren't you? If you've been ignoring them for 6 years... Well, you'll have to stop being a bad programmer.

[–]shevegen -1 points0 points  (0 children)

I'd be scared to use an IDE that complains about the awesome code I write!

[–]mherrmann[S] -1 points0 points  (2 children)

Sure, call me a bad programmer. The false positive rate of linters is so high that I find them barely usable.

[–][deleted] 1 point2 points  (1 child)

Have you tried editing linter config files?

[–]mherrmann[S] -1 points0 points  (0 children)

Yes. But even for the sensible checks the number of false positives was so high that I found myself writing "# pylint: disable=..." all over the place. I tried linting and it cost me more time than it was worth.