If you want to write good code, make sure to format your code by indenting code which is inside brackets. Also place your opening and closing brackets on a new line. Use the tab button to indent, NOT the space.
Unfortunately, this forum doesn't support it but use it in code editors!
Also do NOT use formatter programs like Uncrustify, they mess up the code. Do it by hand!
Separate logical statements from each other like declarations, assignments and function calls.
Bad formatted code:
Good formatted code:
Coding-wise, replace identical code with a function and use variables for dependencies. Do not write 1, 2, 3, 4, 5, ... instead use a variable and increment that. Also do not use possibly unclear statements if a better one exists.
Bad logical code:
Good logical code:
Thanks for reading and I hope it helped you write some better code.
Unfortunately, this forum doesn't support it but use it in code editors!
Also do NOT use formatter programs like Uncrustify, they mess up the code. Do it by hand!
Separate logical statements from each other like declarations, assignments and function calls.
Bad formatted code:
- Code:
doStuff(){self iPrintLn("Hi");
variable = 0;
variable++;
anotherVariable = variable;}
Good formatted code:
- Code:
doStuff()
{
self iPrintLn("Hi");
variable = 0;
variable++;
anotherVariable = variable;
}
Coding-wise, replace identical code with a function and use variables for dependencies. Do not write 1, 2, 3, 4, 5, ... instead use a variable and increment that. Also do not use possibly unclear statements if a better one exists.
Bad logical code:
- Code:
myArray = [];
myArray[0] = 0;
self iPrintLn(myArray[0]);
myArray[1] = 1;
doMoreStuff(myArray[1]);
myArray[2] = 2;
doMoreStuff(myArray[2]);
for(;;)
doEndlessly();
Good logical code:
- Code:
myArray = [];
for(i = 0; i < 3; i++)
{
myArray[i] = i;
print(i);
}
while(1)
{
doEndlessly();
}
print(index)
{
self iPrintLn(myArray[index]);
}
Thanks for reading and I hope it helped you write some better code.