Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #150051 > unrolled thread
| Started by | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| First post | 2020-02-16 06:30 -0800 |
| Last post | 2020-04-04 14:09 -0700 |
| Articles | 2 on this page of 22 — 11 participants |
Back to article view | Back to comp.lang.c
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Coding style for small if statements Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-16 06:30 -0800
Re: Coding style for small if statements David Brown <david.brown@hesbynett.no> - 2020-02-16 16:14 +0100
Re: Coding style for small if statements Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-16 16:40 +0000
Re: Coding style for small if statements David Brown <david.brown@hesbynett.no> - 2020-02-16 17:48 +0100
Re: Coding style for small if statements Robert Wessel <robertwessel2@yahoo.com> - 2020-02-16 17:14 -0600
Re: Coding style for small if statements Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-03-30 00:27 -0700
Re: Coding style for small if statements Ike Naar <ike@sdf.lonestar.org> - 2020-02-16 18:39 +0000
Re: Coding style for small if statements Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-16 20:37 +0000
Re: Coding style for small if statements David Brown <david.brown@hesbynett.no> - 2020-02-17 09:09 +0100
Re: Coding style for small if statements Öö Tiib <ootiib@hot.ee> - 2020-02-17 05:32 -0800
Re: Coding style for small if statements scott@slp53.sl.home (Scott Lurndal) - 2020-02-17 18:07 +0000
Re: Coding style for small if statements Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-02-17 23:48 +0000
Re: Coding style for small if statements Richard Damon <Richard@Damon-Family.org> - 2020-02-17 20:40 -0500
Re: Coding style for small if statements Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-02-23 10:14 -0800
Re: Coding style for small if statements Ike Naar <ike@iceland.freeshell.org> - 2020-02-23 20:16 +0000
Re: Coding style for small if statements Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-03-29 18:56 -0700
Re: Coding style for small if statements Ike Naar <ike@sdf.lonestar.org> - 2020-03-30 06:07 +0000
Re: Coding style for small if statements Jorgen Grahn <grahn+nntp@snipabacken.se> - 2020-03-30 06:45 +0000
Re: Coding style for small if statements David Brown <david.brown@hesbynett.no> - 2020-03-30 10:50 +0200
Re: Coding style for small if statements gazelle@shell.xmission.com (Kenny McCormack) - 2020-03-30 13:04 +0000
Re: Coding style for small if statements Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2020-03-30 06:17 -0700
Re: Coding style for small if statements Tim Rentsch <tr.17687@z991.linuxsc.com> - 2020-04-04 14:09 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Malcolm McLean <malcolm.arthur.mclean@gmail.com> |
|---|---|
| Date | 2020-03-30 06:17 -0700 |
| Message-ID | <8629f27c-b768-4c16-acd3-50b44870ebde@googlegroups.com> |
| In reply to | #150905 |
On Monday, 30 March 2020 14:04:58 UTC+1, Kenny McCormack wrote: > In article <r5sbrt$35j$1@dont-email.me>, > David Brown <david.brown@hesbynett.no> wrote: > >On 30/03/2020 08:45, Jorgen Grahn wrote: > >> On Mon, 2020-03-30, Ike Naar wrote: > >>> On 2020-03-30, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote: > >>>> I don't understand the gain of putting open braces on lines by > >>>> themselves. I've asked lots of people who choose to write code in > >> ... > >>> > >>> I can give you a reason why I find it more readable: > >> ... > >> > >> I hope this doesn't reboot the /whole/ discussion from February ... > >> > > > >Tim has risen from his slumber to resurrect a raft of old threads. You > >can expect a reply or two, then he will go back to sleep for another month. > > > > > > Maybe he actually has a life outside this newsgroup. > > We're on corona virus lockdown. So the computer is the only connection to the outside world.
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2020-04-04 14:09 -0700 |
| Message-ID | <86blo7nejn.fsf@linuxsc.com> |
| In reply to | #150901 |
Ike Naar <ike@sdf.lonestar.org> writes:
> On 2020-03-30, Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:
>
>> I don't understand the gain of putting open braces on lines by
>> themselves. I've asked lots of people who choose to write code in
>> that style what they think the benefits are, but the answers I've
>> gotten always seem circular in one way or another. "I like it
>> because it's more readable" sounds suspiciously like "I like it
>> because I like it." My asking the question is not meant to be
>> argumentative. I ask because I want to understand other people's
>> views. So far though as best I can make out the reason is they
>> like it because that's what they are used to. Can you shed any
>> more light on this question?
>
> I can give you a reason why I find it more readable:
> the vertical alignment of corresponding opening and closing braces
> makes it easier to see that they form a pair.
I sometimes write controlled statements (of if(), for(), etc), on
the same line as the if(), etc. When I do this I do not use
braces unless they are necessary for some other reason.
When I write a controlled statement on a subsequent line, even if
it is only a single (non-block) statement, I always use braces.
Do you always use braces for controlled statements not on the
same line as the controlling phrase (if(), etc)?
If you do, doesn't the if() or for(), etc, vertically aligned
with the closing brace, stand out to show the range/pairing of
each group? I don't see how putting in an additional line with
just an open brace adds any useful information. (Please note
that I am not saying there isn't any, just that I don't see
how there is.)
> Question to you, as a follower of K&R style:
> You don't see much gain in putting the opening brace on a line by
> itself. What is the benefit of putting the closing brace on a
> line by itself?
First I assume the alternative you want me to consider for this
question is not this
if(...){
something;
} next statement...
but this
if(...){
something; }
(with the understanding that horizontal white space is not part
of the question). Incidentally this latter form is sometimes
called "Lisp style". Some C programmers do use Lisp-style
placement of closing braces (even though I myself do not).
Surely everyone knows this, but for completeness, K&R style is
this
if(...){
something;
}
with the closing brace lined up under the 'i' of 'if' or the 'f'
of 'for', etc.
I think K&R-style closing brace placement is a better choice
than, eg, Lisp-style placement, because studies have found that
defect rates are lowest for the placement of closing braces where
K&R style puts them. (I don't know of any corresponding study
for the placement of open braces.) This result matches my
personal experience, although of course that experience is
evaluated subjectively rather than trying to do some sort of
objective measurement.
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.c
csiph-web