Opinions on multiple statements per line?

Just curious as to people's opinions on writing multiple statements on the same line. Some examples of what I've seen:

1
2
using std::vector;   using std::string;
using std::cout;     using std::endl;


and

++begin; ++equal;

So, do you think the rule is hard and fast of one statement per line? Or are you okay with multiple similar, simple statements put onto one line?
In my opinion it is nicer to keep every statement on it's own line as much as possible (even if they are closely related).

It just makes everything easier to read when looking through the code quickly. Of course there are few exceptions where I prefer it such as
1
2
 
int x,y,z 

instead of
1
2
3
int x;
int y;
int z;


But not sure if that really counts. In the end it just comes down to individual programming style.
> Just curious as to people's opinions on writing multiple statements on the same line.

Statements?
1
2
++begin; ++equal; // multiple statements on the same line.
++begin, ++equal ; // a single statement on a line by itself 


I think the guidelines should be more specific: for instance, IMHO, one declaration per line.


IMHO, of course. People have loudly (and somewhat boorishly) asserted that this

int obdurate = 100, *Equus = &obdurate, &mulus = *Equus ;

is not just a great idea, but also the only sensible one.
I do not like this placement of using directive as

1
2
using std::vector;   using std::string;
using std::cout;     using std::endl;


But I see nothing bad in statement

++begin; ++equal;

Moreover the for statement is often an example of such a placement.

for ( ; first != last; ++first, ++value ) { /*...*/ }

Or

1
2
3
4
5
6
7
8
if ( ascend_order )
{ 
   ++begin; ++equal; 
}
else 
{ 
   --begin; --equal; 
}
Last edited on
Just curious as to people's opinions on writing multiple statements on the same line.
Don't do that. It makes it tricky to step through the code in a debugger.

So, do you think the rule is hard and fast of one statement per line?
There are no hard and fast rules. But if you do something different, you should have good reason to do so.
Topic archived. No new replies allowed.