Slowly starting to learn Swift and programming in general. One of the lessons tells about increment, decrement, postfix, prefix record form and so on. But having tried I get this warning:

enter image description here

Because With English as tight as with programming (close to zero) with Google translator, it became clear that all this will be removed in the third version. But why? According to the description are very comfortable things.

    1 answer 1

    Oh, on this topic published a whole document offering the removal. Apparently, the proposal was accepted . Of the significant arguments against :

    • Do not save space.
      Compared to x += 1 expression x++ not particularly shorter.
    • Conflict with the semantics of the rest of the language.
      In Swift, assignments and similar modifying actions return Void . These are not.
    • Confuse the developers.
      Code that uses the return values ​​of these operators is very hard to understand.
      • Swift determines the order of calculation of its constructions, therefore foo(++a, a++) ... at least behaves in a known way (in C ++, say, there is no such luxury), but to understand you need to know the wilds of the language.
        And it is possible, where it is important, to make changes in advance in the right order. The resulting code will even better reflect the algorithm.
    • Rarely applicable.
      They apply to a rather small number of types: integers and real numbers, something iterator-like ... but for complex numbers, matrices, etc., they simply do not make sense.
    • Rarely needed.
      Where to use them? In cycles? Swift already has enough syntactic conveniences for them ( for-in , ranges, enumerate , map and others), so such constructs in the idiomatic Swift-code should not appear at all.

    I consider it necessary to warn that I myself do not know Swift , but from the side of Ruby, where this family of operators is not and was not , it looks like a very meaningful change.

    When it is safe to encapsulate complex ways of iteration inside classes-generators (or other similar mechanisms: in Ruby these are methods with blocks), frequent use of abbreviations like ++ and no longer makes sense.

    And when a construction is rarely used, it makes little sense to have an abbreviated synonym in the language: this is an unnecessary complication of the syntax *, which has a bad effect on the understanding of code by programmers and, as a result, on the stability of the final product.

    I also remind you that the "error per unit" is a very common thing .


    * --x can --x be recognized as -(-x) , two applications of unary minus, which is somewhat different from what pre-decrement does - such syntactic ambiguities make the language more difficult to use, so it makes sense to get rid of them

    • Thanks for the detailed explanation. It is necessary to learn English so that it was easier with programming, but it does not go at all ( - Son'ka V