Prev: integer
Next: shared memory question
From: Scott Lurndal on 1 Mar 2010 13:07 Ian Collins <ian-news(a)hotmail.com> writes: >Richard wrote: >> It is ludocrous to recommend the second form. ALL it does is waste a >> line. Indentation is there for a reason. We dont need to see the opening >> bracket on its own wasted line. > >What's the going rate for a line these days? From the utility 'sloccount' for one of our projects: Totals grouped by language (dominant language first): cpp: 98544 (88.41%) ansic: 10896 (9.78%) asm: 1906 (1.71%) sh: 59 (0.05%) python: 56 (0.05%) Total Physical Source Lines of Code (SLOC) = 111,461 Development Effort Estimate, Person-Years (Person-Months) = 28.22 (338.60) (Basic COCOMO model, Person-Months = 2.4 * (KSLOC**1.05)) Schedule Estimate, Years (Months) = 1.91 (22.87) (Basic COCOMO model, Months = 2.5 * (person-months**0.38)) Estimated Average Number of Developers (Effort/Schedule) = 14.81 Total Estimated Cost to Develop = $ 3,811,717 (average salary = $56,286/year, overhead = 2.40). SLOCCount, Copyright (C) 2001-2004 David A. Wheeler SLOCCount is Open Source Software/Free Software, licensed under the GNU GPL. SLOCCount comes with ABSOLUTELY NO WARRANTY, and you are welcome to redistribute it under certain conditions as specified by the GNU GPL license; see the documentation for details. Please credit this data as "generated using David A. Wheeler's 'SLOCCount'."
From: Scott Lurndal on 1 Mar 2010 13:12 James Harris <james.harris.1(a)googlemail.com> writes: >On 27 Feb, 05:19, William Ahern <will...(a)wilbur.25thandClement.com> >wrote: >> In comp.lang.c Ike Naar <i...(a)localhost.claranet.nl> wrote: >> <snip> >> >> > Consider the case where a condition does not fit on a single line: >> >> > =A0 =A0 if (sscanf(input_buffer, "%d %d %d", &length, &width, &height) = >=3D=3D 3 && >> > =A0 =A0 =A0 =A0 sscanf(other_buffer, "%d %d %d", &color, &price, &weigh= >t) =3D=3D 3 && >> > =A0 =A0 =A0 =A0 needs_processing(color)) { >> > =A0 =A0 =A0 =A0 compute_volume(length, width, height); >> > =A0 =A0 =A0 =A0 compute_something_else(price, weight); >> > =A0 =A0 } >> >> I agree that that's a sore spot. But in complex conditions I often like t= >o >> align the logical operators w/ the if statement. >> >> =A0 =A0 if (sscanf(input_buffer, "%d %d %d", &length, &width, &height) = >=3D=3D 3 >> =A0 =A0 && =A0sscanf(other_buffer, "%d %d %d", &color, &price, &weight) = >=3D=3D 3 >> =A0 =A0 && =A0needs_processing(color)) { >> =A0 =A0 =A0 =A0 compute_volume(length, width, height); >> =A0 =A0 =A0 =A0 compute_something_else(price, weight); >> =A0 =A0 } >> >> Along with 8 space aligned indentation, it's not that bad. > >Or, because the condition should be made clear how about setting it >off as follows. > > if ( > sscanf(input_buffer, "%d %d %d", &length, &width, &height) =3D=3D 3 && > sscanf(other_buffer, "%d %d %d", &color, &price, &weight) =3D=3D 3 && > needs_processing(color) > ) { > compute_volume(length, width, height); > compute_something_else(price, weight); > } Personally, I dislike like if expressions that evaluate with side effects, I would declare temps and move the scanfs outside the if statement. It improves the readability too. I personally place the condition operator at the front, as William does, but nested. if ((pointer1 != NULL) && (pointer1->field7 == 0x152)) { return; } scott
From: Richard Bos on 1 Mar 2010 16:15 Julienne Walker <happyfrosty(a)hotmail.com> wrote: > On Feb 24, 2:21=A0pm, Fred <fred.l.kleinschm...(a)boeing.com> wrote: > > On Feb 24, 11:10=A0am, Julienne Walker <happyfro...(a)hotmail.com> wrote: > > > On Feb 24, 1:35=A0pm, Poster Matt <postermatt(a)no_spam_for_me.org> wrote= > > > > 4. Does anyone care where the pointer * is? I prefer keeping to next = > > > > to the type, rather than next to the variable name. > > > > > > EG. I like: char* firstName; and not so much: char *firstName; > > > > > Just make sure you're consistent and nobody will care. :-) > > > > Except that it is very error-prone to do so. > > It's only error prone if you have multiple variables in a declaration > statement (which the OP's example did not). That itself is often > viewed as an unsafe practice. Incorrectly. I would much rather see int x, y, z; int *dx, *dy, *dz; than int x; int y; int z; int* dx; int* dy; int* dz; Richard
From: Julienne Walker on 1 Mar 2010 16:32 On Mar 1, 4:15 pm, ralt...(a)xs4all.nl (Richard Bos) wrote: > Julienne Walker <happyfro...(a)hotmail.com> wrote: > > On Feb 24, 2:21=A0pm, Fred <fred.l.kleinschm...(a)boeing.com> wrote: > > > On Feb 24, 11:10=A0am, Julienne Walker <happyfro...(a)hotmail.com> wrote: > > > > On Feb 24, 1:35=A0pm, Poster Matt <postermatt(a)no_spam_for_me.org> wrote= > > > > > 4. Does anyone care where the pointer * is? I prefer keeping to next = > > > > > to the type, rather than next to the variable name. > > > > > > EG. I like: char* firstName; and not so much: char *firstName; > > > > > Just make sure you're consistent and nobody will care. :-) > > > > Except that it is very error-prone to do so. > > > It's only error prone if you have multiple variables in a declaration > > statement (which the OP's example did not). That itself is often > > viewed as an unsafe practice. > > Incorrectly. I would much rather see I'm sorry you disagree. Perhaps if you made it clear to everyone in the world what you'd rather see, they'll change their beliefs to suit your style. ;-)
From: Ian Collins on 1 Mar 2010 16:50
Julienne Walker wrote: > On Mar 1, 4:15 pm, ralt...(a)xs4all.nl (Richard Bos) wrote: >> Julienne Walker <happyfro...(a)hotmail.com> wrote: >>> On Feb 24, 2:21=A0pm, Fred <fred.l.kleinschm...(a)boeing.com> wrote: >>>> On Feb 24, 11:10=A0am, Julienne Walker <happyfro...(a)hotmail.com> wrote: >>>>> On Feb 24, 1:35=A0pm, Poster Matt <postermatt(a)no_spam_for_me.org> wrote= >>>>>> 4. Does anyone care where the pointer * is? I prefer keeping to next = >>>>>> to the type, rather than next to the variable name. >>>>>> EG. I like: char* firstName; and not so much: char *firstName; >>>>> Just make sure you're consistent and nobody will care. :-) >>>> Except that it is very error-prone to do so. >>> It's only error prone if you have multiple variables in a declaration >>> statement (which the OP's example did not). That itself is often >>> viewed as an unsafe practice. >> Incorrectly. I would much rather see > > I'm sorry you disagree. Perhaps if you made it clear to everyone in > the world what you'd rather see, they'll change their beliefs to suit > your style. ;-) Eh? He did! -- Ian Collins |