Difference between revisions of "Talk:Code Style"

(Thoughts about operators and control blocks.)
 
Line 56: Line 56:
  
 
--[[User:Boolsheet|Boolsheet]] 20:07, 26 June 2012 (BST)
 
--[[User:Boolsheet|Boolsheet]] 20:07, 26 June 2012 (BST)
 +
 +
== Pointer affinity ==
 +
I didn't expect that change. Why would you want to make it look like an indirection or address-of? Then again, personal preference.
 +
 +
--[[User:Boolsheet|Boolsheet]] 02:10, 28 June 2012 (BST)

Revision as of 01:10, 28 June 2012

Math and stuff

There are other operators that may need a style enforced on them.

The following should be straightforward.

 x = foo::bar;
 x = foo->bar;
 x = foo.bar;
 ++foo;
 bar--;
 x = foo[bar];
 x = -foo;
 x = !foo;
 x = ~foo;
 x = *foo;
 x = &foo;
 delete[] foo;

But what about C casts?

 x = (foo)bar;
 x = (foo) bar;

Or go C++ all the way with casts? I personally don't like the noise C++ casts add even though they might help catch an error early while writing code.

--Boolsheet 20:07, 26 June 2012 (BST)

Control blocks

What about situations where the blocks have mixed one- and multi-liners? Should it always use braces?

 if (foo)
     bar;
 else
 {
     moreFoo;
     moreBar;
 }


 if (foo)
 {
     bar;
 }
 else
 {
     moreFoo;
     moreBar;
 }

There's also the temptation of packing everything together on one line if it is very short.

 if (foo) return 0;
 if (foo)
     return 0;

--Boolsheet 20:07, 26 June 2012 (BST)

Pointer affinity

I didn't expect that change. Why would you want to make it look like an indirection or address-of? Then again, personal preference.

--Boolsheet 02:10, 28 June 2012 (BST)