Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > sci.physics > #644481
| From | owl <owl@rooftop.invalid> |
|---|---|
| Newsgroups | comp.os.linux.advocacy, sci.physics |
| Subject | Re: I'm _still_ the best c coder here. |
| Date | 2017-08-05 06:12 +0000 |
| Organization | O.W.L. |
| Message-ID | <zbsg3av90.ar@rooftop.invalid> (permalink) |
| References | (2 earlier) <feae2868-c0a7-4ff5-ae71-0ad427d8028f@googlegroups.com> <om2jt7$ogs$1@news.albasani.net> <Jeff-Relf.Me@Aug.4--1.48pm.Seattle.2017> <pkbzb34a.b933u0@rooftop.invalid> <Jeff-Relf.Me@Aug.4--10.04pm.Seattle.2017> |
Cross-posted to 2 groups.
In comp.os.linux.advocacy Jeff-Relf.Me wrote:
> You ( Owl ) replied ( to me ):
> > > Marek Novotny's c was better than Owl's or Fabian's,
> > > but it wasn't as concise|readable as mine, I think.
> > > Initially, he chose bash, not c.
> >
> > My code is far more "maintainable" than yours.
>
> No one would agree with you, no one.
> not compared to my: http://Jeff-Relf.Me/FizBuz.HTM
>
> > It's trivial to expand [ my FiZBuz ] to use three or four values
> > with no change in complexity for the decision logic,
> > and using an array of function pointers
> > instead of simply pointing printf() to an
> > array of strings opens all kinds of possibilities.
>
> Your shit was 28 lines, and very convolulted/confusing.
LOL! It's not confusing. It does exactly what you are
doing below, only points into an array of function pointers
instead of an array of char pointers.
> Mine is 2 lines, 2^2 states, and easily modified to 2^3 states,
> via: 4*!(x%3) + 2*!(x%5) + !(x%7).
>
> int x = 0 ; char *Say[4] = { "%d\n", "Buz\n", "Fiz\n", "FizBuz\n" };
> while ( x++ < 100 ) printf( Say[ 2*!(x%3) + !(x%5) ], x );
>
And it hard-codes values, is limited to printf, and takes up as much
space as mine when you expand the array to 2^4, not to mention that
all your decision logic is entangled with the result function.
Mine is clean:
void (*f[])(int)={zero,one,two,onetwo,
four,onefour,twofour,onetwofour,
eight,oneeight,twoeight,onetwoeight,
foureight,onefoureight,twofoureight,onetwofoureight};
int i=0,v=0;
for(i=1;i<=MAX;i++)
{
if(i%ONE==0){v+=1;}
if(i%TWO==0){v+=2;}
if(i%FOUR==0){v+=4;}
if(i%EIGHT==0){v+=8;}
f[v](i); /* call the appropriate function */
v=0;
}
Flexible, easy to maintain, decision logic not entangled with
a single function so custom-tailored functions can be created
to handle different cases; can easily be modified to set values
by parsing argv. Think things through, man. Look to the future.
Sometimes trying to be as concise as possible can tie your hands
and force you to end up doing a complete rewrite when you need
added functionality.
Back to sci.physics | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:11 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:47 -0700
Re: 4 lines, 4 states. Snit <usenet@gallopinginsanity.com> - 2017-08-03 22:52 -0700
Re: Mozilla ThunderBird. Snit <usenet@gallopinginsanity.com> - 2017-08-04 10:43 -0700
Re: FizzBuzz is a trick question. Snit <usenet@gallopinginsanity.com> - 2017-08-04 11:47 -0700
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-04 12:51 -0700
Re: I'm the best c coder here. Snit <usenet@gallopinginsanity.com> - 2017-08-04 14:03 -0700
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-04 23:15 +0000
Re: I'm the best c coder here. benj <benj@nobody.net> - 2017-08-04 19:35 -0400
Re: I'm the best c coder here. "F. Russell" <fr@random.info> - 2017-08-05 16:08 +0000
Re: Fabian seldom writes code, much less test it. owl <owl@rooftop.invalid> - 2017-08-05 03:09 +0000
Re: 2 lines, 2^2 states, easily modified to 3^2 states. owl <owl@rooftop.invalid> - 2017-08-05 05:42 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 13:37 +0000
Re: Fabian seldom writes code, much less test it. "F. Russell" <fr@random.info> - 2017-08-05 14:25 +0000
Re: I'm the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 03:22 +0000
Re: I'm _still_ the best c coder here. owl <owl@rooftop.invalid> - 2017-08-05 06:12 +0000
Re: Owl's FizBuzGozKaz branches 5 times more often. owl <owl@rooftop.invalid> - 2017-08-05 15:40 +0000
Re: I'm _still_ the best c coder here. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-05 22:16 +0000
Re: I increment things at the _start_ of a loop. moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 03:24 +0000
Re: I increment things at the _start_ of a loop. Snit <usenet@gallopinginsanity.com> - 2017-08-06 20:35 -0700
Re: "while ( x++ < 100 )" isn't "obscure". moroney@world.std.spaamtrap.com (Michael Moroney) - 2017-08-07 04:59 +0000
Re: I'm the best c coder here. chrisv <chrisv@nospam.invalid> - 2017-08-07 06:59 -0500
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Doomsdrzej <.m@nsn.s> - 2017-08-05 11:52 -0400
Re: Michael Glasser, Steve Carroll, Marek Novotny, Branimir Maksimovic, etc. Snit <usenet@gallopinginsanity.com> - 2017-08-05 09:55 -0700
csiph-web