What is the advantage of this peculiar formatting?

I saw this format used for comma-separated lists in some C ++ code (although this can apply to any language):

void function(  int a
              , int b
              , int c
             )

I was wondering why someone would use this in a more common format, for example:

void function (int a,
               int b,
               int c
              )
+5
source share
12 answers

This is a fairly common coding style when writing SQL statements:

SELECT field1
     , field2
     , field3
--   , field4
     , field5
FROM tablename

Benefits:

  • Allows you to easily add, remove or reorder fields without worrying about this trailing final comma.
  • Allows you to easily comment out a string (TSQL uses a "-") without violating the rest of the statement.

, , SQL, , , .

. ++. , VB.Net , , (_) .

+17

, ().

, , , .

+3

Malice?

, . . , , .

+3

, B C, . , C, .

, , .

+2

, , - , , ..

+1

, .

+1

, , , , ( , , ). :

std::cout << "some info "
    << "some more info " << 4
    + 5 << std::endl;

( , 4 + 5 , , ).

, , if, for while. , .

 std::vector<int> v = ...;
 std::vector<int> w = ...;
 for (std::vector<int>::iterator i = v.begin()
       , std::vector<int>::iterator j = w.begin()
       ; i != v.end() && j != w.end()
       ; ++i, ++j)
           std::cout << *i + *j << std::endl;
+1

, , .

.

void function (int a,
               int b,
               int c
              )
+1

, , - , , ..

, .

+1

, , , , .

+1

, . , , , :

function(
          int a,
          int b,
//          int c,
          int d
        )

, , , :

function (
//             int a
           , int b
           , int c
           , int d
          )

, + .

+1

, sql if, , .

A B
C

, , C if. , , . , , , , .

0
source

All Articles