Re: coding style
Byrial Jensen <[email protected]>
| Newsgroups | gmane.comp.gnu.xboard.devel |
|---|---|
| Message-ID | <[email protected]> |
Den 03-01-2012 20:25, Arun Persaud skrev:
> Hi
>
>> I used to intensely dislike that newline, because it makes it impossible
>> with most editors to find the declartion imediately by searching for
>> type + function name. But perhaps this is what the space is supposed
>> to solve.
>
> really? I would think that most editors used for programming would be
> able to search for "^funcname" and should be able to find it easier,
> since that should be the only place where the function name is at the
> beginning of the line.
> If your editor can't search for regexp than I guess the space can indeed
> help.
>
> So is everyone ok with using
>
> int
> funcname (int a, int b)
>
> for functions? If so, I can change all files to this new format over the
> next days...
Indeed. The GNU coding standings says in section 3.4:
"However, it is easy to support pre-standard compilers in most programs,
so if you know how to do that, feel free. If a program you are
maintaining has such support, you should try to keep it working."
You could argue that xboard is trying to support pre-standard compilers,
but that support is already broken. So I find it futile to try and keep
it, especially if no developer can even test it.
But if you are going to change everywhere, it would best if HGM pushed
all his bugfixes etc. first. BTW they should be pushed anyway.
> Guess this is a matter of taste... to me having those extra lines makes
> it a lot more readable than the other version... mostly because I find
> it easier to see where the block starts and ends by having the {} in the
> same column...
I too prefer the extra lines.
>> It is usually possible to eliminate braces by clever use of commas, though.
>> If I knew that braces took two extra lines, I would definitely write
>>
>> if(x>y)
>> h = y, y = x, x = h;
>>
>> rather than waste vertical space on the braces.
>
> for a swap this would perhaps make sense, but if the lines where not
> related, I wouldn't want to have them in the same line...
If the intention is the swap and h is not used again, then it can done
much elegant with a macro, for instance with:
if (x > y)
SWAP(x, y, int);
where SWAP is defined in some header file as
#define SWAP(x, y, the_type) \
do {\
the_type temp = y;\
y = x;\
x = temp;\
} while(0)\