What are the rules for spaces in fast

I train on a fast playing field, and I could not understand why quickly it is too specific, where the programmer should provide spaces and where not. I asked this question on many sites and in chat rooms, but did not receive an answer.

var j: Int = 34 // Right var j:Int=23 //Wrong 

Also in class

 self.variable-= 5 //Wrong. Error: Consecutive statements must be followed by ; self.variable-=5 // Right self.variable -= 5 // Right 

;

Even this ":" sometimes creates some problems with spaces.

I think that spaces should have absolutely no effect on the code. This is usually for the benefit of the programmer. It just makes the code more readable. What is the best resource for reading all the quick rules about spaces.

+5
source share
1 answer

The answer to the second part of your question can be found here quick documents

A space around the operator is used to determine whether the operator is used as a prefix operator, postfix operator, or binary operator. This behavior is summarized in the following rules:

If an operator has spaces around both sides or around neither side, it is treated as a binary operator. As an example, the + operator in + b and a + b is considered as a binary operator.

If the operator has spaces only on the left side, it is considered as a prefix of the unary operator. As an example, the ++ operator in ++ b is treated as a prefix of a unary operator.

If the operator has spaces only on the right side, it is considered as a postfix unary operator. As an example, the ++ operator in ++ b is treated as a postfix unary operator.

If the operator does not have spaces on the left, but immediately follows the period (.), It is considered as a postfix unary operator. For example, the ++ operator in ++. B is considered as a postfix unary operator (a ++. B, not ++. B).

etc. (read more in the documents)

As for the first part of your question, I have not seen any problems with any way of declaring variables.

 var j: Int = 34 var j:Int=23 

The only problem with the code provided is that you declare j twice in the same scope. Try changing one of j to x or y or something else.

If you are interested about

 var j:Int =10 

or

 var j:Int= 10 

Check out the above rules. = is an operator, so if you were to make any of them, it would be considered as a prefix or postfix, and you will get an error that the prefix / postfix = is reserved

These rules are important due to the existence of operators such as unary pluses and unary minus operators. The compiler should be able to distinguish between binary plus and unary operator. List of operators

+13
source

All Articles