Red_Fist wrote:Like how do you know where to put the semicolon[...]
The semicolon in a programming language is the equivalent to a period at the end of a sentence: it finishes a statement or an instruction.
An "if", "for", "while" and others are not statements, they are "control blocks", and generally they only use curly braces to define the block of code they are going to run, with a couple of exceptions (such as a "do while", which has a semicolon at the end given that the "control" part of the block resides at the end of the block instead of the beginning.
There are many languages however which do not use a semicolon at all, such as in the case of Lua, Visual Basic, Python, and also Javascript and Bash as long as you keep separate statements in different lines, which use new lines (Python, Visual Basic) or other syntactic rules (Lua, Javascript) to discern where a statement starts and where it finishes.
Now what exactly defines a statement depends on the language itself, but almost every language follows a common logic on this, whether or not they use semicolons, which is once again related with how you define things in math.
Declarations, assignments, function calls, returns and language constructs are statements:
Code: Select all
//declarations
var string someText;
local int l;
//assignments
a = f + 1;
l++;
//function calls
k = getK();
doStuff();
//returns
return;
return 100;
//language constructs
continue;
break;
In the case of a "for" loop, it's the only control block which also uses semicolons inside of it, and the reason for this is because each one of those 3 parts (as "l = 1", "l <= 10" and "l++") are actually 3 separate statements, just like I have shown above when I replaced the "for" with a "while".
sektor2111 wrote:As a personal note and for checking brackets well VIA Notepad++ I'm always using EPIC style in placing brackets and not what I see here, I do not have a clue why a bracket (nowadays) needs to open after function at 3/30 TABS from left margin of the page and it is closing at 1 TAB distance. Is way difficult to track if bracket is closed properly. Sample:
Code: Select all
function FixSomething(Actor Other){
//some hackish stuff
}
written by others - and for me is not that fascinating, in my Script is a little wrapped - like EPIC DID
Code: Select all
function FixSomething(Actor Other)
{ //Remark with credits for the ass programming making you to write this function
//some hackish stuff
}
Because NotePad++ is capable of pointing a red-line when you hit a bracket and then you can track its open-close block boundaries looking to not have some remark opened inside ( /* ) else code will have a BIG compiling problem.
Code style is always a subjective thing to discuss, it's mostly opinion based, but generally the decisions on those have to do with how easy is to read code.
Whenever you develop code you should do it as if you wanted someone else or even your future self to easily understand it.
Having that said, I think Epic has a really bad code style overall, except on function definitions.
I personally use a code style which is common in PHP, and which defines the positioning of curly braces as depending on what kind of block they are addressing, and which you can see a sample of here for example:
https://github.com/Feralidragon/php-fer ... ponent.php
It's PHP code but it should get the idea across.
Essentially, anything that is a class, method or function, I put the curly brace in a new line (Epic-style as you would put it), however for anything else, namely control blocks, they get to be in the same line, but with a space between the control part and the actual start of the block.
An exception for this however are anonymous functions, because in practice they act as control blocks themselves, but only some languages support them, with UnrealScript not being one of them.
For example:
Code: Select all
function int getAbsoluteSum(int a, int b)
{
if (a < 0) {
a = -a;
}
if (b < 0) {
b = -b;
}
return a + b;
}
(this is just an example to show the style)
Why?
It has to do with a visual perception of the code. Being easy to read is the most important trait of the code from a maintainer's point of view, and the reason for this difference has to do with the separation of distinct units of logic in such a way that is quicker to discern them from each other.
Therefore, it's my opinion that, this:
Code: Select all
function doStuff()
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
is easier to perceive and read right away even from a distance than this:
Code: Select all
function doStuff() {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
While for control blocks, this:
Code: Select all
function doStuff()
{
if (some_condition) {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
} else {
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
}
allows you to read more code and more neatly so as belonging to that one function, than this:
Code: Select all
function doStuff()
{
if (some_condition)
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
else
{
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
}
this last one just introduces too much empty space in an area meant to be much denser with code, and will make you scroll a lot more and move your eyes more, causing more eye and brain strain reading it.
But this is my opinion, and although is backed up by many many programmers, it's still all very subjective so there's no clear "right" or "wrong" style.
There are "completely wrong" styles for sure though, like putting 50 instructions in the same line, or having lines with 300 columns, or even having very long names given to variables and functions, but from there is all almost a political/religious debate on which style is best.