📜 ⬆️ ⬇️

A couple of useful exceptions to the rules for formatting source code

Flat design (flat design), it is now fashionable and beautiful. Let's make our small contribution to the general trend, let's apply some flat-formatted code.

Indent ladder


Nested sections of code are recommended to be indented relative to the outer section:

{ if () { for() { } } } 

This rule is usually observed absolutely. But you can write the code like this:

 { if () for() { } } 

The use of such a design is of course very limited. For example, can not be used if there is an else block. If this formatting does not cause you discomfort, try a couple of times, maybe you will like it. After all, a decrease by several indents in a deep ladder helps a lot.
')

Double-if


I will share a little secret. Once I sent a specially trained ninju saboteur to build in the compiler the ability to write code like this:

 if () if () { } 

Yes, yes, you will not believe, he succeeded. Since then, you can write constructions

 if (a | b | c) if (d | e) for() if () { } 

This is not a typo, two if one by one and without indentation! double-if is a complete analogue of the && operator.

instead

 if ((a | b | c) && (d | e)) { for() { if () { } } } 

These little examples are revealing, experiment! But I want to warn against mindless use, use flat only where it does not damage the readability of the code.

Source: https://habr.com/ru/post/208750/


All Articles