Code line packaging convention?

I usually wrap my lines of code so that they take up to 80 characters.

Which packaging looks best to you?

// (A)
std::vector<MyLongClassName::size_type>* myvector
    = new std::vector<MyLongClassName::size_type>();
bool isOneOrAnother = hereIsOneLongCondition
    && hereIsAnotherOne;

// (B)
std::vector<MyLongClassName::size_type>* myvector =
    new std::vector<MyLongClassName::size_type>();
bool isOneOrAnother = hereIsOneLongCondition &&
    hereIsAnotherOne;

I know this is arbitrary, but is there an agreement or preferred method?

+3
source share
5 answers

I would select (B), but for a boolean, I could add not completely necessary parsers, and then align the values ​​inside them. I would add parens just because my emacs would not do this for me without them.

bool isOneOrAnother = ( hereIsOneLongCondition &&
                        hereIsAnotherOne );
+2
source

Another possibility for the second statement (sometimes):

bool isOneOrAnother =
   hereIsOneLongCondition && hereIsAnotherOne;
+1
source

. -, Microsoft , . # , ...

, :
 # .
 # .
 # .
 # .

, , , . , , , , , () , , . , - , , , .

, .

0

, (B), , :

bool isOneOrAnother =
         hereIsOneLongCondition &&
         hereIsAnotherOne;

(B) javascript <cough> broken </cough> . , , , , .

0

. , -

bool someCondition = ( hereIsOneLongCondition &&
                       hereIsAnotherOne &&
                       hereIsYetAnother &&
                       ohNoHereIsMore);

:

bool someCondition = Foo();

Foo() - :

bool Foo()
{

   bool result = true;

   if (!hereIsOneLongCondition)
   {
      result = false;
   }

   if (!hereIsAnotherOne)
   {
      // this was added to fix such-and-such bug
      result = false;
   }

   // etc

   return result;
}

, , , . .

0

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


All Articles