Question

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.

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top