Difference between revisions of "Talk:Code Style"

(Thoughts about operators and control blocks.)
 
(Swallowed a G.)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Math and stuff ==
+
== Code style proposals ==
There are other operators that may need a style enforced on them.
+
=== Long function call alignment and indentation ===
  
The following should be straightforward.
+
'''Break up a function call into two or more lines if it reaches an uncomfortable length. Use one tab of indentation for the additional lines.'''
 +
 +
  '''YES:'''
  
   x = foo::bar;
+
   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei) width, (GLsizei) height,
   x = foo->bar;
+
   ⇥GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
  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?
+
  '''NO:'''
  
   x = (foo)bar;
+
   glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei) width, (GLsizei) height,
   x = (foo) bar;
+
  ················GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
 +
    
 +
  glTexSubImage2D(GL_TEXTURE_2D,
 +
  ················0,
 +
  ················0,
 +
  ················0,
 +
  ················(GLsizei) width,
 +
  ················(GLsizei) height,
 +
  ················GL_RGBA,
 +
  ················GL_UNSIGNED_BYTE,
 +
  ················data->getData());
  
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.
+
--[[User:Boolsheet|Boolsheet]] 13:14, 7 January 2013 (GMT)
 
 
--[[User:Boolsheet|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;
 
 
 
--[[User:Boolsheet|Boolsheet]] 20:07, 26 June 2012 (BST)
 

Latest revision as of 13:26, 7 January 2013

Code style proposals

Long function call alignment and indentation

Break up a function call into two or more lines if it reaches an uncomfortable length. Use one tab of indentation for the additional lines.

 YES:
 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei) width, (GLsizei) height,
 ⇥GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
 NO:
 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (GLsizei) width, (GLsizei) height,
 ················GL_RGBA, GL_UNSIGNED_BYTE, data->getData());
 
 glTexSubImage2D(GL_TEXTURE_2D,
 ················0,
 ················0,
 ················0,
 ················(GLsizei) width,
 ················(GLsizei) height,
 ················GL_RGBA,
 ················GL_UNSIGNED_BYTE,
 ················data->getData());

--Boolsheet 13:14, 7 January 2013 (GMT)