ophelius
Member
Hi,
I was just curious, looking at all the examples in GM's help file and also seeing people's code on this forum, I was wondering if the over-use and overly spaced-out distribution of curly brackets is a personal choice or a matter of not understanding that you don't always need them and they can be much more compact.
Example, I see a lot of these types of monsters:
In case you don't know, and in case you want to have more compact code, this is all you need:
That's 8 lines compacted into 2.
Or this for improved readibility(my prefered style):
I mean you could even have it on 1 line:
if(x == 1) y += 1; else y -= 1;
It's only if you have more than 1 statement that you must use curly brackets to combine them all into a block of statements.
Even then I see:
You can start the curly bracket after the 'if' statement, and put the 'else' after the 'if' closing-bracket, and start the 'else' start-bracket right after
(my prefered style):
10 lines reduced to 7.
What are your thoughts? Do some people actually prefer overly spaced-out code? Is it because people assume that's how it has to be formatted to work because of the examples in the help file? Is it easier on the eyes for some?
Anyways, thanks, just wanted to share some thoughts
I was just curious, looking at all the examples in GM's help file and also seeing people's code on this forum, I was wondering if the over-use and overly spaced-out distribution of curly brackets is a personal choice or a matter of not understanding that you don't always need them and they can be much more compact.
Example, I see a lot of these types of monsters:
Code:
if(x == 1)
{
y += 1;
}
else
{
y -= 1;
}
Code:
if(x == 1) y += 1;
else y -= 1;
Or this for improved readibility(my prefered style):
Code:
if(x == 1)
y += 1;
else
y -= 1;
if(x == 1) y += 1; else y -= 1;
It's only if you have more than 1 statement that you must use curly brackets to combine them all into a block of statements.
Even then I see:
Code:
if(x == 1)
{
//multiple
//statements
}
else
{
//multiple
//statements
}
(my prefered style):
Code:
if(x == 1){
//multiple
//statements
}else{
//multiple
//statements
}
What are your thoughts? Do some people actually prefer overly spaced-out code? Is it because people assume that's how it has to be formatted to work because of the examples in the help file? Is it easier on the eyes for some?
Anyways, thanks, just wanted to share some thoughts
Last edited: