jeudi 12 décembre 2019

How bad of a practice is using break, continue, or multiple return statements?

I know a professor that is a die-hard stickler to a style guide he gives his students. One of his biggest things, after talking with him for a while, seems to be control-flow statements, such as break, continue, goto, and using return more than one time in a function. He argues that if ... else statements are always better (and possible).

I'm a little skeptical about such a definite claim. I'd imagine they'd have to be pretty widely used if they're a big enough topic for anyone to learn about.

So, to put his claim to the test, I'm curious what professional coders think. Please specify the language or languages you primarily are talking about in your answer.

My questions are:

  1. Does the use of control-flow statements make code harder to maintain and/or read?
  2. Is it generally frowned upon to rely on control-flow statements and are if ... else statements always preferred?
  3. Is it really always practical (or even possible) to not use control-flow statements in code?
  4. Is it every preferable to see a control-flow statement over an if ... else block (in terms of readability and functionality)?

This is very much an opinion question, so I look forward to hearing everyone's thoughts on the matter.

Aucun commentaire:

Enregistrer un commentaire