[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
C++ style: variable names, white space, etc.
From: |
John W. Eaton |
Subject: |
C++ style: variable names, white space, etc. |
Date: |
Sun, 20 Feb 2005 01:18:09 -0500 |
On 19-Feb-2005, Steve C. Thompson <address@hidden> wrote:
| Please give some pointers on style. I've read from the GNU Coding
| Standards (http://www.gnu.org/prep/standards/) that it is best to use
| lowercase variables, and plenty of white space. It suggests spelling out
| variable names and avoiding abbreviations when possible.
|
| I took this to the extreme with this example:
Following the GNU coding standards, you would have something that
looks more like this:
// For M_PI
#include <cmath>
#include <octave/oct.h>
DEFUN_DLD (sct_complex_matrix, args, ,
"Returns a complex matrix")
{
octave_value retval;
int subcarrier_number = 128;
int oversample_factor = 4;
int sample_per_block = subcarrier_number * oversample_factor;
ComplexMatrix subcarrier_matrix (subcarrier_number, sample_per_block);
for (int n = 0; n < sample_per_block; n++)
{
for (int k = 0; k < subcarrier_number; k++)
{
double tmp = 2 * M_PI * n * k / subcarrier_number;
subcarrier_matrix(n,k) = Complex (cos (tmp), sin (tmp));
}
}
retval = subcarrier_matrix;
return retval;
}
Take a look at the Octave sources for more examples.
Using Emacs will help a lot with keeping the indentation consistent.
jwe
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------
- C++ style: variable names, white space, etc., Steve C. Thompson, 2005/02/20
- C++ style: variable names, white space, etc.,
John W. Eaton <=
- Using Vim, using tabs, using spaces, Steve C. Thompson, 2005/02/20
- Re: Using Vim, using tabs, using spaces, Paul Laub, 2005/02/20
- Using Vim, using tabs, using spaces, John W. Eaton, 2005/02/20