How and where can I break long lines of code?

Possible duplicates:
Where to wrap a line of code, especially long lists of arguments?
Coding Standards and String Length

Hi,

  • Where do you break long lines of code? (Example: before or after the operator)
  • If it's a long string, do you split the string into substrings?
  • What other cases are there when breaking long lines?
+3
source share
6 answers

From a historical point of view, it was an old width of 80 columns due to screen size. However, since this is usually not always the case, I think it is not necessary to strictly follow this.

, , , . - , , , 80 , .

:

1)

if(longVariableName || someOtherVariable ||  
   nextVariable)  
{
   //Some code here.
}

, , , (|| ) , . , .

+4

:

  • .
  • . ​​
  • .

-Cheers.

+3

, , .

  • 79 , ( , ). - 60-, , : -)

  • . , x = 1 * 2 + 3 * (4 + 5); +, - . , "" x, 1 * 2 3 * (4 + 5).

  • , , . , 3 , 4 .

- :

x = 1 * 2 +
    3 * (4 + 5);

if (1 * 2 =
    3 * (4 + 5))
{
    doSomething();
}

, , , . :

if (1 * 2 = 3 * (4 + 5)) {
    doSomething();
}

, if :

if (1 * 2 =
    3 * (4 + 5)) {
    doSomething();
}

.

, , . C , "abc" "def" , "abcdef". (, ), , .

+3

, , " ", , (, ( ), ). , .

, , - , . , , .

+2

: , IDE, , .

, . - , : 80 - , CLI . IDE 80- . , , , IDE (, : XCode, Eclipse MS Visual Studio), .

, , IDE, . .

. , 120 , , . 80 , , .

A 'clause', , , . , - . , if while/for, , statemnt .

OSX Objective-C, XCode . , :: . .

, . ( , ), , . 100 , , , /, , , . , 100 , // ... .. .

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

+2

Since the modern IDE supports horizontal scrolling, I don't care how long the line itself is (unless my command does); just how easy it is to understand. But this rarely matters, because I break things down into lines or methods to make them easier to understand, so the length of each line automatically stays short.

+1
source

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


All Articles