|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I, for one, find it much easier to read C++ code which is braced like this:
if(somecondition == 0)
{
// do some stuff
}
else
{
// do something else
}
As opposed to
if(somecondition == 0) {
// do some stuff
}
else {
// do something else
}
Why doesn't the rest of the world understand that?
--
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Halbert <hal### [at] gmailcom> wrote:
> Why doesn't the rest of the world understand that?
Because Brian Kernighan and Dennis Ritchie used the latter style in their
famous book, and because they are God, every C (and consequently C++) coder
must obey the same standard.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Halbert wrote:
> I, for one, find it much easier to read C++ code which is braced like this:
> Why doesn't the rest of the world understand that?
Different languages encourage different indentation schemes, based on
the details of syntax. I use different indenting for C and Pascal, for
example.
I tend to prefer indenting where the things in one column are
sequentially executed. So if I have an if, an assignment, and a while
loop, I'll tend to want to indent things so there are only three lines
in that column, rather than including all the noise words. E.g.,
void codestuff() {
int i;
if (i == j) {
do this thing;
do that thing;
}
j += 1;
while (j < 23) {
do another;
}
}
void morecode() {
}
Having things like switch (especially with fallthrus) and else sometimes
messes up the patterns, depending on just how you manage it. I figure
the fewer rules you need to learn to indent, the easier it is to learn it.
if (i == j) {
stuff;
morestuff;
} else if (yadda) {
another stuff
extra stuff;
} else {
thing one
thing two
}
That looks kind of ugly, but it also stands out as matching "my" rules
in many ways. Doing it as
if (i == j) {
stuff
}
else if (j == 3) {
stuff
}
else {
thing
}
looks nicer, and also kind of works out with the "things in the same
column should be executed sequentially" rule. It also looks nicer when
you have "begin" and "end" instead of { and } :-)
--
Darren New / San Diego, CA, USA (PST)
Helpful housekeeping hints:
Check your feather pillows for holes
before putting them in the washing machine.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Halbert" <hal### [at] gmailcom> wrote in message
news:4863dbb4$1@news.povray.org...
> I, for one, find it much easier to read C++ code which is braced like
this:
>
> if(somecondition == 0)
> {
> if(somecondition == 0) {
> // do some stuff
Whereas I find the first far too spread out to be able to read easily and
use the second as my standard code layout in C-like languages
> Why doesn't the rest of the world understand that?
>
Because the rest of the world doesn't necessarily agree with you?
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Gail Shaw <initialsurname@sentech sa dot com> wrote:
> Whereas I find the first far too spread out to be able to read easily
Compactness does not imply readability. On the contrary.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Warp" <war### [at] tagpovrayorg> wrote in message
news:4863e7ae@news.povray.org...
> Gail Shaw <initialsurname@sentech sa dot com> wrote:
> > Whereas I find the first far too spread out to be able to read easily
>
> Compactness does not imply readability. On the contrary.
I never said it did.
I said that I find the first too spread out to read easily and that I prefer
the second as *I* personally find it easier to read.
If you prefer the former, more power to you. Just don't expect me to code
the same way.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
It's true that its only a preferance I personally have. The rest of the
world doesn't have to agree with me. I just like the way the braces all line
up and make visually clear the beginning and end of each code block. Its
easier for me to see than matching of the ending brace with the associated
expression at the top of the block.
I have been quietly living with that gripe in the back of my mind for the
last 18 or 19 years. Now that it's out in the open, I feel much better.
--
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
"Halbert" <hal### [at] gmailcom> wrote in message
news:4863edeb$1@news.povray.org...
> It's true that its only a preferance I personally have. The rest of the
> world doesn't have to agree with me.
Everyone's entitled to their prefered way of doing things. Life would be
boring if we all agreed on everything
> I have been quietly living with that gripe in the back of my mind for the
> last 18 or 19 years. Now that it's out in the open, I feel much better.
Good.
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Gail Shaw <initialsurname@sentech sa dot com> wrote:
> Life would be boring if we all agreed on everything
I disagree.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Halbert wrote:
> I, for one, find it much easier to read C++ code which is braced like this:
>
> if(somecondition == 0)
> {
> // do some stuff
> }
> else
> {
> // do something else
> }
I, for more than one, do not.
> As opposed to
>
> if(somecondition == 0) {
> // do some stuff
> }
> else {
> // do something else
> }
To me, the latter method is much more like POV-Ray than the first
method. I learned POV first, so I guess that's why I do it.
Since most of the code I write is never seen by another poor soul, you
won't find me bending backwards to tailor it for the "posh" crowd.
> Why doesn't the rest of the world understand that?
I kinda feel bad for the one guy who had to see my C++ code. At least it
was relatively short :)
Sam
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |