Less stupid paperwork: reduce code with c ++ 20

Less stupid paperwork: Reduce code with C ++ 20

Less work, fewer errors and a more stable program in the result – the principle of the CLEAN Code relies on the basics of software development. The central rule is Do not Repeat Yourself (Dry), because who produces less duplicates, can also reforse his software faster and secure, and thus increase the release cycle.

In mid 2020, C ++ 20 was published; The standard makes a lot in terms of CLEAN code: In particular, comparisons can be reduced to the essentials. A new rule allows the compiler to negate the result of a == surgery and as a result for one != Operation to use. Prior to previously, programmers had to do a lot of dull, but erroneous paperwork.

Work to the compiler

Already C ++ 11 was the syntax = default, which now applies to the comparison operators. In this way, the compiler provides the implementation for the operator == itself, the program compares all data fields of an object with each other. If you add new fields in a class, the equality operator is always up to date – a handful adjustment falls away.

New with on board is the spaceship operator, which consumes gross and small comparisons: In practice, it is not easy to determine the equality or inequality, but the program must recognize whether a value is gross or less than another. Hierfer, the four operators, = and

Many practical examples can be found in the new tutorial of the IX 3/2021, where Andreas’s finished comparisons take under the magnifying glass. The second part of the tutorial in the coming April-IX explains how developers make their code readable.

  • Clean code with C ++ 20
  • Content IX 3/2021
Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: