Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: Which code style do you prefer the most? Date: Sun, 09 Mar 2025 11:41:23 -0700 Organization: A noiseless patient Spider Lines: 55 Message-ID: <867c4yujvw.fsf@linuxsc.com> References: <20250304175602.c9fe683d678d3a2ed101a4ac@g{oogle}mail.com> <20250304101022.154@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Sun, 09 Mar 2025 19:41:24 +0100 (CET) Injection-Info: dont-email.me; posting-host="4ff405040ba6608b59b6d53fd95025b0"; logging-data="924565"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192cVtdTSGdSJ6o8p3KP/Tz9ENUmCYGe30=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:ULT+q0O8lu15RAviJG/UBbyspf8= sha1:rd1f5v3X6A1R5JuBUhah0hzZ71g= Bytes: 2581 Richard Harnden writes: > On 04/03/2025 18:14, Kaz Kylheku wrote: > >> On 2025-03-04, bart wrote: >> >>> The style I use for generated code is like this: >>> >>> if (cond) { >>> stmt1; >>> } >>> else { >>> stmt2; >>> } >> >> I've been known to do this: >> >> if (case_ineligible_for_switch) { >> // ... >> } else switch (state_variable) { >> // ... >> } >> >> or >> >> if (case_not_requiring_loop) { >> // ... >> } else for (;;) { >> // ... >> } >> >> and I might even have historically perpetrated something like: >> >> if (case_not_requiring_loop) { >> // ... >> } else if (case_requiring_loop) for (;;) { >> // ... >> } else { >> // ... >> } > > I like the brace on its own line. It visually separates the > condidition from the statement. If someone wants visual separation, that can be done just as well or better with a blank line. > How do people format long and complex conditions, given that > you're trying not to a much over 80 columns? In almost all cases, revise the code so that conditions in if(), while(), etc, result in a line not over 80 columns. There are various ways of doing this, such as factoring the condition into a function, introducing auxiliary variables for sub-conditions, and so forth.