Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #164136
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: A question about style |
| Date | 2021-12-30 16:22 -0800 |
| Organization | None to speak of |
| Message-ID | <87bl0x39o2.fsf@nosuchdomain.example.com> (permalink) |
| References | <sqjivq$get$1@oguzismail.eternal-september.org> <style-20211230175438@ram.dialup.fu-berlin.de> <returns-20211230225942@ram.dialup.fu-berlin.de> <refactoring-20211231001627@ram.dialup.fu-berlin.de> |
ram@zedat.fu-berlin.de (Stefan Ram) writes:
> ram@zedat.fu-berlin.de (Stefan Ram) writes:
>>"Split it into meaningful functions with meaningful
>>names, and if that is not possible, reorganize the
>>code so that it becomes possible!".
>
> So, for example:
>
> int f( void )
> {
> if( rand() < 1 )
> { if( rand() < 2 )return 0;
> /* else fall through to continuation */ }
> else
> { if( rand() < 3 )return 0;
> /* else fall through to continuation */ }
>
> /* continuation */
> puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }
>
> would become:
>
> int f( void )
> { if( rand() < 1 )
> { if( rand() < 2 )return 0;
> else
> { puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }}
> else
> { if( rand() < 3 )return 0;
> else
> { puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }}}
>
> . Now, we have code duplication, but then the next step is:
>
> inline int continuation( void )
> { puts( "A" );
> puts( "B" );
> puts( "C" );
> return 1; }
>
> int f( void )
> { if( rand() < 1 )
> { return rand() < 2? 0: continuation();
> else
> { return rand() < 3? 0: continuation(); }}
You have an unmatched curly brace on that last function definition.
Your unconventional layout makes that very difficult to see.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
A question about style Oğuz <oguzismailuysal@gmail.com> - 2021-12-30 09:18 +0300
Re: A question about style Öö Tiib <ootiib@hot.ee> - 2021-12-30 04:42 -0800
Re: A question about style Öö Tiib <ootiib@hot.ee> - 2021-12-30 04:47 -0800
Re: A question about style James rock <jamesroack12@gmail.com> - 2021-12-30 15:40 +0000
Re: A question about style Oğuz <oguzismailuysal@gmail.com> - 2021-12-30 19:24 +0300
Re: A question about style Manfred <noname@add.invalid> - 2021-12-30 18:34 +0100
Re: A question about style Bart <bc@freeuk.com> - 2021-12-30 18:14 +0000
Re: A question about style Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-30 19:43 +0100
Re: A question about style Meredith Montgomery <mmontgomery@levado.to> - 2021-12-30 16:56 -0300
Re: A question about style Paul N <gw7rib@aol.com> - 2021-12-30 12:15 -0800
Re: A question about style Oğuz <oguzismailuysal@gmail.com> - 2021-12-31 09:05 +0300
Re: A question about style Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-12-30 14:01 -0800
Re: A question about style Oğuz <oguzismailuysal@gmail.com> - 2021-12-31 09:11 +0300
Re: A question about style Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-12-30 16:22 -0800
Re: A question about style Jens Schweikhardt <usenet@schweikhardt.net> - 2022-01-02 13:28 +0000
csiph-web