Re: code portability



Frederick Gotham wrote:
Flash Gordon posted:

The reality is that when more than one person works on a project it is
far easier to read if everyone uses the same coding style and in the
real world the majority of complex pieces of software are worked on by
multiple people.


I think this argument is exagerated. I can read any style, so long as it's valid C. I'll admit, that at first, there were some things which puzzled me, things like:

sizeof obj

instead of:

sizeof(obj)

Never gave me a problem.

Or:

int const *p;

instead of:

const int *p;

Neither of these has puzzled me either. However, I have to slow down for the one I'm not used to and if I'm scanning back up to check some aspect of the type of p then instead of scanning and immediately picking out the aspect I want to know I'll have to stop and read it.

But is that not part of learning C? Some people put their function blocks like so:

int Func()
{

}

while others put them like so:

int Func() {

}

It might be a little puzzling the first time you encounter it, and you might even find it disgusting, but if you look at it objectively, you can still read the code.

Yes, but for the style you do not generally use it slows you down. If you see
int Func() {
int i;

You may well have to pause a moment to confirm that there is nothing in the parenthesis and so i is a local variable rather than a parameter.

If you were to supply me with a source file which contained several different styles, I wouldn't have a problem reading it.

I would still be able to read it, I know because I have had to, but it slows most people down. It especially slows people down when they are scanning just to check something.

Some of us can be asked to review a few thousand lines of C code. Anything that slows you down on this in a busy day is undesirable.

For your own code seen by no one else do whatever you please. I'm just explaining why when more than one person is involved it is advisable to stick to a consistent style, and where there is a commonly accepted style it is generally easiest to stick to it.

I'm not going to continue responding to this since it is a style issue and you never get everyone agreeing (I've accepted Pascal coding styles I did not like because it was the standard for the project). Although the fact that most people posting an opinion seem to think your coding style is less readable might give you a hint.
--
Flash Gordon
Still sigless on this computer
.



Relevant Pages