PinkeyNBrain
IS-IT--Management
In a previous post the excessive usage of semicolons was brought into light. One poster preferred the minimalist approach, another (myself) added a few extra here and there. This thread is opened to receive input from anyone who who has an opinion, or, are at that point in their day when they're about to start keyboard diving and need a break.
Please note that before I continue, I wish to establish that this posting is intended to be an open discussion. In absolutely no way is this intended to be a slam, dig or otherwise ridiculing of any of the many talented contributors to this forum.
To begin - The two basic camps that I'm aware of at this point are:
1) Minimal usage
a) If not needed, a semicolon should not be used.
b) You'll never see any book example, tutorial, or other using them.
c) Can potentially cause logic errors.
2) Liberal usage
a) Programmers choice / coding style.
First review -
After reading some comments from the minimalist camp, I did cross examine how my code fell. Thinking of logic errors, I came up with the following example:
OK - The code does nothing save for illustrating the point
that neither the -w switch nor the usage of strict will find anything in error here. Should this basic construct be intermingled within a much larger chunk of code, it could easily be lost.
On the other hand, while I can't say for certain that I've never made the above mistake, I can say that I've made the following mistake many times:
By habit, I use indentation to trace through logic. As such, I'll overlook the fact that 'ww' will never be executed if 'xx' is false. Again, neither -w or strict will find an error. However in my defense, by my usage of ;'s after 'if' statements (e.g. if (yy) { zz }
, the missing } would have been pointed out by the parser.
<insert idealist here who states: "For every if-then, there should be an else; even if it isn't used">
..... Hey - we're just working on semicolons here. Start your own thread.
Going back to the fact that you'll never see additional ;'s used in publicated (sp?) material, I offer the following 3 sources:
#1#
Camel book 1st ed, Mar 1992 Ch7-Other Oddments / Common Goofs for Novices:
Camel book 2nd ed, Sep 1996 Ch2-The Gory Details:
Here there is a separation between simple statements and compound statements (i.e. BLOCKs). For simple statements:
Under the description of compound statements, there is no reference toward promoting nor condemning the usage of ;'s.
This next statement is conjecture on my part but, I feel that the trend toward not using ;'s when not needed would be Mr.Tom Christiansen's influence. I've heard him speak before and believe he is a very intelligent individual, he can also be a horses rump.
#3#
And finally, please reference:
In particular the "Comments and statements" section.
To wrap up: I say that if an extra semicolon here or there helps you complete your program, use them. If they cause you problems don't use them. In the manor that I use them, you can't tell me that they shouldn't be there. Its the programmers choice.
Please note that before I continue, I wish to establish that this posting is intended to be an open discussion. In absolutely no way is this intended to be a slam, dig or otherwise ridiculing of any of the many talented contributors to this forum.
To begin - The two basic camps that I'm aware of at this point are:
1) Minimal usage
a) If not needed, a semicolon should not be used.
b) You'll never see any book example, tutorial, or other using them.
c) Can potentially cause logic errors.
2) Liberal usage
a) Programmers choice / coding style.
First review -
After reading some comments from the minimalist camp, I did cross examine how my code fell. Thinking of logic errors, I came up with the following example:
Code:
#!/usr/bin/perl -w
use strict ;
$main::avar = $main::bvar = 0 ;
# logic error inducing semicolon on next line
# We're really wanting avar = 1 + ++bvar ;
$main::avar = 1 ;
+ ++$main::bvar ;
that neither the -w switch nor the usage of strict will find anything in error here. Should this basic construct be intermingled within a much larger chunk of code, it could easily be lost.
On the other hand, while I can't say for certain that I've never made the above mistake, I can say that I've made the following mistake many times:
Code:
if (xx) {
# semicolon intentionally left off the next line
if (yy) { zz }
else {
ww
}
<insert huge chunk of code here >
<that has an extra { or missing }>
}
<insert idealist here who states: "For every if-then, there should be an else; even if it isn't used">
..... Hey - we're just working on semicolons here. Start your own thread.
Going back to the fact that you'll never see additional ;'s used in publicated (sp?) material, I offer the following 3 sources:
#1#
Camel book 1st ed, Mar 1992 Ch7-Other Oddments / Common Goofs for Novices:
#2#* Forgetting the trailing semicolon.
Obviously you've done too much awk hacking recently. Every statement in Perl is terminated by a semicolon.
Camel book 2nd ed, Sep 1996 Ch2-The Gory Details:
Here there is a separation between simple statements and compound statements (i.e. BLOCKs). For simple statements:
A simple statement is an expression evaluated for its side effects. Every simple statement must end in a semicolon, unless it is the final statement in a block. In this case, the semicolon is optional (but strongly encouraged in any multiline block, since you may eventually add another line)
Under the description of compound statements, there is no reference toward promoting nor condemning the usage of ;'s.
This next statement is conjecture on my part but, I feel that the trend toward not using ;'s when not needed would be Mr.Tom Christiansen's influence. I've heard him speak before and believe he is a very intelligent individual, he can also be a horses rump.
#3#
And finally, please reference:
In particular the "Comments and statements" section.
To wrap up: I say that if an extra semicolon here or there helps you complete your program, use them. If they cause you problems don't use them. In the manor that I use them, you can't tell me that they shouldn't be there. Its the programmers choice.