Readability: splitting lines of code, should the operator be on the first or second line? [closed]

StackOverflow https://stackoverflow.com/questions/20351536

문제

Simple question about formatting code (in my case C++).

If I have a line of code, say:

SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace + IDontActuallyUseVariablesThisLong

Should I split it like:

SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace +
                         IDontActuallyUseVariablesThisLong

or:

SomeSortOfLongVariable = AnotherLongVariableThatTakesUpTonsOfHorizontalSpace 
                         + IDontActuallyUseVariablesThisLong

Another example:

foo = bar->baz;
// Should it be:
foo = bar->
      baz;
//Or:
foo = bar
      ->baz;

Do people have a preference when it comes to this? Is it on a case-by-case basis? They both seem equally clear (or unclear) to me, so I was wondering if there are any standard ways of doing it.

도움이 되었습니까?

해결책

Yes, people have preferences about this.

No, there's no standard or consensus agreement. I'm not aware of any especially strong arguments for either side, either.

So like any coding style issue, you can stick with whatever other people who edit the same code have been doing, or just pick one you like.

(I wouldn't even complain about being inconsistent on this issue.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top