|
How about:
for (int iSomeValue(1); ..)
instead of:
for (int iSomeValue =1; ..)
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
Ohhhhh noo
Assign a value to a variable witn (1) instead of = 1, not for me plz...
- Anders
|
|
|
|
|
Why not? It is exactly the same (they both use the copy-constructor).
Do you never use this kind of assignments?
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
Why? Using that syntax for intrinsic data types is way confusing. Yes you can do it, but you can also call your variables aljkafljkLJljkW2398_D__Sljs38s
I bet you don't do that.
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
Ok, you got me convinced.
--
Alex Marbus
www.marbus.net
But then again, I could be wrong.
|
|
|
|
|
(I Vary),
(i V A R Y),
( i V A R Y ),
( I vary )
Regardz
Colin J Davies
|
|
|
|
|
The options are...
Option 1: Spaces between inside and outside the parentheses.
if ( something )
...
Option 2: Spaces outside parentheses, no space inside.
if (something)
...
Option 3: Spaces inside parentheses, no space outside.
if( something )
...
Option 4: No white space.
if(something)
I would go for "if (something)"
but if it's a functioncall, and not an if I use "SomeFunction(SomeParam)"
I know (some) other programmers do the same, so we have to select both option 2 and 4...
- Anders
|
|
|
|
|
|
I agree.
Phil.
Wise programmers don't play leapfrog with unicorns.
|
|
|
|
|
I would require an additional option. Following the example code, I choose option 2, but as soon as the condition is too large because of long variable or function names, I use option 1 for readability, therefore my style matches both options:
if (x > 0)
...
if ( LogVariableName > 0 )
... Best regards,
Thomas
I am a signature virus!
Help me spread and copy me to your sig!
|
|
|
|
|
This brings up something that I've wondered about for ages. I've been trying to work out why some people use
if(something) and it seemed to me that maybe the thinking was that 'if' is like a function. So you would have
bool b = Foo(m_bar);
if(b) ... To me, 'if' is a keyword, and the parentheses are part of the conditional, and not the 'if'. Am I on the right track in thinking that
if(something) stems from a view that 'if' is like a function?
I dunno. It's all too strange.
cheers,
Chris Maunder
|
|
|
|
|
Well, I can only agree with you...
- Anders
|
|
|
|
|
My personal formatting style is:
no whitespace between function name and opening parenthesis as in
b = foo(bar);
but whitespace between keyword and opening parenthesis as in
if (foo)
for (i = 0; i < whatever; i++)
In case of a typecast, I use whitespace as follows
BYTE *p;
p = (BYTE *) &whatever;
|
|
|
|
|
I put whitespace everywhere - I rarely put 2 lines together with no blank lines in between, unless it's a 2-line block where line 2 is a return or break.
The exception is no spaces inside a cast, such as (LPCTSTR) .
--Mike--
http://home.inreach.com/mdunn/
All your base are belong to ME~!
|
|
|
|
|
How do you enclose expressions in parentheses?
|
|
|
|
|
I really had to think about this, so it's not an issue of religious zeal for me. What I *do* insist on is that there are spaces inside the brackets, like this:
if (X < 0)
NOT
if (X<0)
Why ? Because a standard is needed, and the spaces make it more readable. A standard is needed so I can search all my code for x < 0 and be sure I don't need to search permutations involving whitespace, or lack thereof.
Christian
Be strong, and remember: be yourself, because you have to someone, and
everyone else is already taken.
|
|
|
|
|
I totally agree with you, but I woted "No white space", because I don't like
( x < 0 )
- Anders
|
|
|
|
|
I don't like spaces arround standard compare operations like ==, !=, <
I tends to make more complicated expression with && and || unreadable:
if (x<0 && y==4)
{
...
}
and not
if (x < 0 && y == 4)
{
...
}
Martin
|
|
|
|
|
> I don't like spaces arround standard compare operations
> like ==, !=, < I tends to make more complicated expression
> with && and || unreadable:
I agree. But I prefer something like this
if(x<0 && 4==y)
{
...
}
for(x=0; x<100; ++x)
{
...
}
CollIter iter=coll.begin();
for(;iter!=coll.end(); ++iter)
{
..
}
Am I alone?
Max
|
|
|
|
|
Close... but I like my code like this,
if ( ( x < 0 ) && ( 4 == y ) ) {
<br>
}
for ( x = 0; x < 100; ++x ) {
<br>
}
CollIter iter = coll.begin ();
for (; iter != coll.end (); ++iter ) {
<br>
}
Have a good one,
-Ben
"Its funny when you stop doing things not because they’re wrong, but because you might get caught." - Unknown
|
|
|
|
|
I like whitespace around operators, and I just tend to use more brackets.
ie.
if ((x < 0) && (y == 4))
{
...
}
I like being explicit (ie. don't have to worry about any precedence rules) and the whitespace (in my mind) makes the expression easier to read.
Have fun,
Paul Westcott.
|
|
|
|
|
In the above case I think the following would be preferred:
if(( x < 0 ) && ( y == 4 ))
simply because it is readable and I don't have to go looking up operator precedence just to make sure. I deal a lot with reading others' code and in many different languages (with different precedence tables) and therefore appreciate little things like extra whitespace and parentheses.
|
|
|
|
|
and therefore appreciate little things like extra whitespace and parentheses
But you have no whitespave between the 'if' and the '('
On the topic of precedence I have deliberately never sat down and learned the precedence table off by heart, because I much prefer to be totaly explicit with what I want done first (apart from precedence of + and * - that's a given).
Code such as if (++*var[x] && y == 42) gives me the heeby geebies.
cheers,
Chris Maunder
|
|
|
|