See also Ian’s post which has copies of the slides and also will include a link to the YouTube webinar replay when it is available.
Be sure to join us for the next Delphi Developer Debate
Syntax Censor – WITH, GOTO, and LABEL
Wed, Jul 27, 2022 11:00 AM – 12:00 PM CDT
Here are the results from the MVP Survey, be sure to join the webinar for the in-depth conversation.
The following are some of my thoughts to consider for this developer debate. I’ve also included a couple of links to additional resources.
WITH statement
My take: “Deprecate and raise a warning”. Why? There is a lot of existing source code that uses the WITH statement. Warning would help developers identify possible problems for any WITH statements.
Some possible reasons for using or avoiding the WITH statement:
- Reason for using WITH – makes code is easier to read and less wordy.
- Reasons to avoid using WITH – modified code can silently change a program without warning. Hard to use some debugger features (inspect for example).
Note: I could be convinced to change my opinion about the WITH statement if the IDE had a tighter (better?) integration between the project, editor, debugger and a change management system that alerted developers to a WITH statement use being impacted by a change.
GOTO statement and LABEL
My take: Deprecate and raise a warning. Why? There may be some legacy code that still includes GOTO and LABEL. Warning would help identify the code and allow developers to consider possible structured alternatives.
Some possible reasons for using GOTO and Label:
- Reason for using GOTO – GOTO allows for simple transfer of program control unconditionally. Easy for the compiler to optimize to machine code. Reasons for using LABEL – target location for a GOTO. Document a section of code.
- Reasons for avoiding GOTO – use can lead to the creation of spaghetti code. Could be used in a structured programming way but only with careful thought and constant vigilance.
Additional References
Letters to the editor: go to statement considered harmful by Edsger W. Dijkstra
Communications of the ACM
Volume 11 Issue 3
March 1968 pp 147–148
https://dl.acm.org/doi/pdf/10.1145/362929.362947
“For a number of years I have been familiar with the observation that the quality of programmers is a decreasing function of the density of go to statements in the programs they produce. More recently I discovered why the use of the go to statement has such disastrous effects, and I became convinced that the go to statement should be abolished from all higher level programming languages (i.e. everything except, perhaps, plain machine Code) … The unbridled use of the go to statement has an immediate consequence that it becomes terribly hard to find a meaningful set of coordinates in which to describe the process progress … The go to statement as it stands is just too primitive; it is too much an invitation to make a mess of one’s program.”
Edsger W Dijkstra Archive – https://www.cs.utexas.edu/users/EWD/
C2 Wiki – https://wiki.c2.com/?GotoConsideredHarmful
Why Pascal is Not My Favorite Programming Language by Brian W. Kernighan, April 2, 1981 – AT&T Bell Laboratories
https://www.cs.virginia.edu/~evans/cs655/readings/bwk-on-pascal.html
GOTO statement Wikipedia article – https://en.wikipedia.org/wiki/Goto
C language GOTO Statement – https://en.cppreference.com/w/c/language/goto
C++ language GOTO Statemtent – https://en.cppreference.com/w/cpp/language/goto
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition
I’m all for deprecating
with
… as soon as there is a reliable refactoring to remove it.“Goto” should stay as it have some potential i do not use myself but i know that sometimes it can save a tone of time in some projects.
“with” can exist but definitly not in the current form!
Change it to something which require variable names like this e.g.
with f: Form1.label1.font do
Begin
f.color…….
f.fontname….
End