[Freeciv-Dev] Re: (PR#6948) Quickselect unit
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=6948 >
On Tue, 25 Nov 2003, Arnstein Lindgard wrote:
>
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=6948 >
>
> On Tue, 25 Nov 2003 10:42:32 -0800 Mike Kaufman wrote:
> > it's not to style spec.
>
> Ok, new patch. But which do you think is more readable in this
> particular case? Explicitness is an interesting topic, which is
Doesn't matter.
> related to clarity of mind, and giving reasons is always helpful.
> When skipping brackets, you may loose the ability to easily expand a
> segment. In this case I did it to tell myself that the segment in
> question should remain simple; at the end of the function, one and
> only one value must be returned. If you prefere 2) then maybe you have
> developed the traditional speed-reading skill of skimming a page in
> diagonals with your eyes?
>
> When many if's exist within other if's, using brackets only for those
> that need it, help me see the big picture faster. I never read K&R
> and sure as hell never will, but I want to comply with Freeciv
> CodingStyle. I'm not particularly bothered with any style or having
> to comply with it. I don't want to be argumentative, I only hope you
> may find occasional different views to cause you to constantly
> question and rethink, like I do. If I annoyed you just a little bit,
> I succeded. I quite often re-indent and re-style my code just in
> order to see if I can wrap my mind around the problem in a different
> way.
Experience tells me that when doing a project you should pick a style
and stick with it. It doesn't matter how obstrusive it is, as long as
it is applied consistently. Eventually you will get used to it.
The worst thing that can happen is when each piece of code looks different
and then you take more time understanding the code than should be required.
FWIW I don't program my software using K&R style, but BSD. If you think
K&R is bad, try to see Microsoft style Hungarian notation... Brrr...
> 1)
>
> if (qtype == SELECT_SEA) {
> if (panytransporter) return panytransporter;
> else if (panymovesea) return panymovesea;
> else if (panysea) return panysea;
> else if (panymoveunit) return panymoveunit;
> else if (panyunit) return panyunit;
> }
> else if (qtype == SELECT_LAND) {
> if (panymoveland) return panymoveland;
> else if (panyland) return panyland;
> else if (panymovesea) return panymovesea;
> else if (panysea) return panysea;
> else if (panymoveunit) return panymoveunit;
> else if (panyunit) return panyunit;
> }
> return NULL;
>
> 2)
>
> if (qtype == SELECT_SEA) {
> if (panytransporter) {
> return panytransporter;
> } else if (panymovesea) {
> return panymovesea;
> } else if (panysea) {
> return panysea;
> } else if (panymoveunit) {
> return panymoveunit;
> } else if (panyunit) {
> return panyunit;
> }
> }
> else if (qtype == SELECT_LAND) {
> if (panymoveland) {
> return panymoveland;
> } else if (panyland) {
> return panyland;
> } else if (panymovesea) {
> return panymovesea;
> } else if (panysea) {
> return panysea;
> } else if (panymoveunit) {
> return panymoveunit;
> } else if (panyunit) {
> return panyunit;
> }
> }
> return NULL;
The right answer is 2).
---
Vasco Alexandre da Silva Costa @ Instituto Superior Tecnico, Lisboa
|
|