-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Document break, @label and continue more thoroughly
#60818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| Because structured control flow is easier to reason about than goto statements, | ||
| goto statements should generally be avoided, and only reached for in the rare cases | ||
| where the ordinary control flow mechanisms will not suffice. | ||
| One such example is optimized state machines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion is perhaps excessively wordy, use what you like from it:
| One such example is optimized state machines. | |
| An example application where it is cleanest to reach for `@goto` is translating an arbitrary finite state machine (FSM) into Julia code. Even so, some classes of FSM have a natural representation in structured control-flow, see the following paper for an example: [^codeFSM]. | |
| [^codeFSM]: | |
| Jones, D.W., 1988. How (not) to code a finite state machine. ACM SIGPlan Notices, 23(8), pp.19-22. |
NB: IMO it is not appropriate to use "optimized" here, so this suggestion removes the word. It is natural to reach for @goto when implementing a state machine, however this has less to do with performance, rather it leads to cleaner code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree - the easiest way to write a FSM is to use an integer as state, and then have a main loop with a big if/ifelse/else chain matching the integer. In my opinion, this is less verbose and easier to follow than a goto-based state machine, but is less efficient.
* Rephrase `break` docstring to mention named break breaks from a named block in general, and not a loop. * Add a compat note to both `break` and `continue` docstrings * In break docstring, also include simple non-labeled usage example * In break docstring, also include non-loop code block break * In break docstring, highlight the returned value of `break name value` * Minor rephrasing of the newly added Manual section
|
Test failures seem unrelated |
Documentation was largely missing from #60481.
Also document
@goto, which was not in the manual.