When I was just ten years old, I ventured into the world of programming without any mentor, driven solely by the pure curiosity of a child. My comp...
For further actions, you may consider blocking this person and/or reporting abuse
Interesting discussion, and code illustration, of what seems to generally be regarded as a taboo topic.
Not sure why this is the case. Its use (unconditional branching) is an integral part of assembly language programming. Older legacy code (COBOL, not Java, shells like DOS Batch and DCL) is replete with its use.
I would say professional programmers should be as knowledgeable of it, and its uses, as they should of other language constructs and idioms. They then use this knowledge and their professional judgement, to craft their code.
Finally, I would recommend that this line:
should, for added clarity, be changed to:
Why ? You have an open file handle that will, eventually, need to be closed.
In the example, since the program ends after the final statement, cleanup (including the closing of open files handles) occurs, so is not strictly necessary.
However, if the code were part of a larger construct, correctly performing each step not only adds clarity, but robustness as well.
Thank you for you effort.
Thanks for the feeedback @ajborla !
Appreciated.
I wanted to write a short article about this approach to share a different approach to different awareness with developers and to make them aware of a different flow from the classic loops.
Then, I added my own personal observations about the complexity of this approach. Undoubtedly, the use of goto and label can be effective for someone and in some situations. Everyone makes their own considerations.
The readability considerations are also personal and a consequence of my current style. I remember when I worked with assembly in the past, the goto approach helped me a lot in understanding assembly (but also cobol itself)
I will update the code according to your directions, I agree.
Thank you very much
Wow that example is disorientating!
I only understood it after reading the php documentation.
The part I was stuck on, was the loop. My mind broke on the logic how it got from start to loop.
Php just runs line after line. But the named segments just threw me off.
For people who want to follow the flow:
start -> loop -> loopline (X times) -> endloopline -> loop -> goodbye
It never goes to the closeFile segement?
Thank you @xwero for your valuable feedback!
The article mainly focuses on the approach; the example is on the side, but thanks to your feedback, I can explain the
gotocommand, labels, and execution flow.The
closeFilelabel (as mentioned in the article) is not used through thegotoin the provided code. However, it could be utilized to mark the point where the file handle is closed after processing.But I will change the code to add a
gotoin case of an exception and use thecloseFilelabel.Thank you again. I appreciate your feedback
Kind of funny that in assembly language, GOTOs are effectively everywhere π
Wow! I thought
gotois removed from every modern language!