Answer the question
In order to leave comments, you need to log in
What is the correct way to use operator brackets?
Good afternoon!
I always used operator brackets when working with loops, an if block, regardless of whether several statements were nested inside or not. The programming teacher says that the operator bracket should only be used when there are several operators inside, otherwise it should be written in this form:
if() k=321;
else z = 256;
if(){
k=321;
}else{
z = 256;
}
Answer the question
In order to leave comments, you need to log in
The programming teacher says that the operator bracket should only be used when there are several operators inside, otherwise it should be written in this formtell him he's a theoretician.
It's best to use vendor-recommended coding rules
www.oracle.com/technetwork/java/javase/documentati...
The Yii2 documentation recommends
if() k = 321;
else z = 256;
if()
k = 321;
else
z = 256;
if(){
k = 321;
} else {
z = 256;
}
in descending order of priority:
in my humble opinion, if curly braces can be supplied, they should be.
// and don't forget about code formatting!!1
We are required to use this code at work:
if(){
k=321;
}else{
z = 256;
}
Thank you all very much for your replies.
Then I will not exclude the use of brackets when working with blocks that have only one operator inside. If the teacher swears, then I will give him a link to the repository.
You are right in an unexpected place.
Your version is potentially less problematic when debugging (when you constantly comment on pieces of code and uncomment them back).
The instructor's option is "kinda easy to read" but may cause unexpected syntax shifts.
I hope you have indents.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question