Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #72400 > unrolled thread

Program to count words, issues with an if condition within a for loop

Started byAlla _ <modelling.data@gmail.com>
First post2015-10-10 10:28 -0700
Last post2015-10-18 20:44 -0700
Articles 20 on this page of 140 — 23 participants

Back to article view | Back to comp.lang.c


Contents

  Program to count words, issues with an if condition within a for loop Alla _ <modelling.data@gmail.com> - 2015-10-10 10:28 -0700
    Re: Program to count words, issues with an if condition within a for loop Stephen Fisher <sfisher@panix.com> - 2015-10-10 18:53 +0000
      Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-10 22:23 +0200
        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-10 23:13 +0200
      Re: Operating Systems in Teaching Bartc <bc@freeuk.com> - 2015-10-10 22:04 +0100
        Re: Operating Systems in Teaching Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-10 14:12 -0700
          Re: Operating Systems in Teaching Bartc <bc@freeuk.com> - 2015-10-10 22:30 +0100
        Re: Operating Systems in Teaching Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-10 18:25 -0400
        Re: Operating Systems in Teaching Bartc <bc@freeuk.com> - 2015-10-11 15:02 +0100
          Re: Operating Systems in Teaching Bartc <bc@freeuk.com> - 2015-10-11 16:39 +0100
          Re: Operating Systems in Teaching Melzzzzz <mel@zzzzz.com> - 2015-10-11 17:50 +0200
          Re: Operating Systems in Teaching "Osmium" <r124c4u102@comcast.net> - 2015-10-11 11:29 -0500
            Re: Operating Systems in Teaching "Osmium" <r124c4u102@comcast.net> - 2015-10-11 11:48 -0500
            Re: Operating Systems in Teaching Bartc <bc@freeuk.com> - 2015-10-11 18:18 +0100
              Re: Operating Systems in Teaching "Osmium" <r124c4u102@comcast.net> - 2015-10-11 12:46 -0500
                Re: Operating Systems in Teaching Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-10-11 13:57 -0400
    Re: Program to count words, issues with an if condition within a for loop Ian Collins <ian-news@hotmail.com> - 2015-10-11 10:21 +1300
      Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-10 14:55 -0700
        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 00:35 +0200
        Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 00:01 +0100
          Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-10 16:21 -0700
            Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 01:24 +0100
              Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-10 17:56 -0700
                Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 03:17 +0200
                  Re: Program to count words, issues with an if condition within a   for loop Ian Collins <ian-news@hotmail.com> - 2015-10-11 14:43 +1300
                  Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-11 00:19 -0700
                    Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 11:02 +0100
                      Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-11 03:47 -0700
                        Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 16:05 +0100
                        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 17:38 +0200
                          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 18:49 +0200
                            Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-11 12:37 -0700
                              Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 21:56 +0200
                                Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-11 13:34 -0700
                                  Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-12 10:11 +0200
                              Re: Program to count words, issues with an if condition within a for loop Geoff <geoff@invalid.invalid> - 2015-10-11 12:59 -0700
                        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 19:15 +0200
                    Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 12:48 +0200
                      Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-11 03:59 -0700
                        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 13:30 +0200
                          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 14:19 +0200
                            Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 14:48 +0200
                              Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-11 12:20 -0700
                        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 13:49 +0200
                          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 13:55 +0200
            Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 02:40 +0200
        Re: Program to count words, issues with an if condition within a for loop Ian Collins <ian-news@hotmail.com> - 2015-10-11 14:40 +1300
    Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-10 22:29 +0100
      Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 00:22 +0200
        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 00:57 +0200
        Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 00:46 +0100
          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 02:23 +0200
            Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 01:28 +0100
              Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 04:21 +0200
                Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 04:32 +0200
                Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-11 11:06 +0100
            Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-11 02:55 +0200
            Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-15 10:36 -0700
              Re: Program to count words, issues with an if condition within a for loop Geoff <geoff@invalid.invalid> - 2015-10-15 14:37 -0700
      Re: Program to count words, issues with an if condition within a for loop raltbos@xs4all.nl (Richard Bos) - 2015-10-11 10:15 +0000
        Re: Program to count words, issues with an if condition within a for loop Rosario19 <Ros@invalid.invalid> - 2015-10-12 10:37 +0200
          Re: Program to count words, issues with an if condition within a for loop Rosario19 <Ros@invalid.invalid> - 2015-10-12 11:08 +0200
            Re: Program to count words, issues with an if condition within a for loop Rosario19 <Ros@invalid.invalid> - 2015-10-14 16:27 +0200
              Re: Program to count words, issues with an if condition within a for loop Tonton Th <tTh@nowhere.invalid> - 2015-10-14 14:28 +0000
              Re: Program to count words, issues with an if condition within a for loop Rosario19 <Ros@invalid.invalid> - 2015-10-14 16:36 +0200
                Re: Program to count words, issues with an if condition within a for loop Rosario19 <Ros@invalid.invalid> - 2015-10-14 16:40 +0200
                Re: Program to count words, issues with an if condition within a for loop Rosario19 <Ros@invalid.invalid> - 2015-10-14 16:49 +0200
        Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-15 14:09 -0700
          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-16 12:49 +0200
            Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-19 14:28 -0700
              Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-20 02:03 +0200
                Re: Program to count words, issues with an if condition within a   for loop Ian Collins <ian-news@hotmail.com> - 2015-10-20 13:13 +1300
                Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-19 20:07 -0700
                  Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-20 14:30 +0200
                    Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-20 15:08 +0200
                Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-24 12:18 -0700
              Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-20 03:03 +0200
                Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-24 12:21 -0700
                  Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-25 15:16 +0100
                    Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-27 22:29 -0700
    Re: Program to count words, issues with an if condition within a for loop raltbos@xs4all.nl (Richard Bos) - 2015-10-11 10:26 +0000
      Re: Program to count words, issues with an if condition within a for loop Keith Thompson <kst-u@mib.org> - 2015-10-11 14:09 -0700
        Re: Program to count words, issues with an if condition within a for loop raltbos@xs4all.nl (Richard Bos) - 2015-10-14 11:36 +0000
          Re: Program to count words, issues with an if condition within a for loop Keith Thompson <kst-u@mib.org> - 2015-10-14 10:23 -0700
            Re: Program to count words, issues with an if condition within a for loop raltbos@xs4all.nl (Richard Bos) - 2015-10-20 16:06 +0000
      Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-12 00:19 +0200
        Re: Program to count words, issues with an if condition within a for loop Keith Thompson <kst-u@mib.org> - 2015-10-11 17:53 -0700
          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-12 04:15 +0200
    Re: Program to count words, issues with an if condition within a for loop Alla _ <modelling.data@gmail.com> - 2015-10-13 08:44 -0700
      Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-14 07:27 +0200
        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-14 08:53 +0200
          Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-14 11:13 +0100
            Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-14 12:35 +0200
            Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-14 13:08 +0100
              Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-14 18:11 +0200
      Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-16 04:58 -0700
        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-16 15:07 +0200
          Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-16 23:50 +0200
            Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-17 00:06 +0200
              Re: Program to count words, issues with an if condition within a for loop Keith Thompson <kst-u@mib.org> - 2015-10-16 15:30 -0700
          Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-19 13:45 -0700
            Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-20 02:40 +0200
              Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-24 12:47 -0700
                Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-25 15:36 +0100
                  Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-27 22:37 -0700
                Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-25 15:52 +0100
                  Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-25 19:10 +0100
                    Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-25 19:17 +0100
                    Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-27 23:05 -0700
                      Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-28 03:59 -0700
                        Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-29 14:04 +0100
                      Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-29 01:07 +0100
                        Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-30 08:31 -0700
                  Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-27 22:48 -0700
            Re: Program to count words, issues with an if condition within a for loop Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-20 08:55 +0000
              Re: Program to count words, issues with an if condition within a for loop regis <regis.barbanchon@free.fr> - 2015-10-20 13:52 +0200
              Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-24 14:04 -0700
                Re: Program to count words, issues with an if condition within a for loop Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-25 06:44 +0000
                  Re: Program to count words, issues with an if condition within a for loop raltbos@xs4all.nl (Richard Bos) - 2015-10-25 09:09 +0000
                    Re: Program to count words, issues with an if condition within a for loop Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-10-25 10:12 +0000
                      Re: Program to count words, issues with an if condition within a for loop asetofsymbols@gmail.com - 2015-10-25 03:26 -0700
                        Re: Program to count words, issues with an if condition within a for loop Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-10-25 06:38 -0700
                          Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-25 15:23 +0000
                          Re: Program to count words, issues with an if condition within a for loop supercat@casperkitty.com - 2015-10-25 10:54 -0700
                            Re: Program to count words, issues with an if condition within a for loop Keith Thompson <kst-u@mib.org> - 2015-10-25 12:21 -0700
                              Re: Program to count words, issues with an if condition within a for loop supercat@casperkitty.com - 2015-10-25 14:16 -0700
                                Re: Program to count words, issues with an if condition within a for loop Keith Thompson <kst-u@mib.org> - 2015-10-25 14:52 -0700
                            Re: Program to count words, issues with an if condition within a for loop Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-26 00:58 +0000
                              Re: Program to count words, issues with an if condition within a for loop Bartc <bc@freeuk.com> - 2015-10-26 11:50 +0000
                          Re: Program to count words, issues with an if condition within a for loop raltbos@xs4all.nl (Richard Bos) - 2015-11-10 15:17 +0000
                            Re: Program to count words, issues with an if condition within a for loop Les Cargill <lcargill99@comcast.com> - 2015-11-10 19:27 -0600
                              Re: Program to count words, issues with an if condition within a for loop Jorgen Grahn <grahn+nntp@snipabacken.se> - 2015-11-11 07:39 +0000
                                Re: Program to count words, issues with an if condition within a for loop Les Cargill <lcargill99@comcast.com> - 2015-11-11 08:22 -0600
                            Re: Program to count words, issues with an if condition within a for loop Robert Wessel <robertwessel2@yahoo.com> - 2015-11-11 00:37 -0600
                  Re: Program to count words, issues with an if condition within a for loop Tim Rentsch <txr@alumni.caltech.edu> - 2015-10-28 08:52 -0700
    Re: Program to count words, issues with an if condition within a for loop Barry Schwarz <schwarzb@dqel.com> - 2015-10-18 12:31 -0700
      Re: Program to count words, issues with an if condition within a for loop asetofsymbols@gmail.com - 2015-10-18 15:28 -0700
        Re: Program to count words, issues with an if condition within a for loop Ian Collins <ian-news@hotmail.com> - 2015-10-19 11:40 +1300
          Re: Program to count words, issues with an if condition within a for loop asetofsymbols@gmail.com - 2015-10-18 20:41 -0700
          Re: Program to count words, issues with an if condition within a for loop asetofsymbols@gmail.com - 2015-10-18 20:44 -0700

Page 3 of 7 — ← Prev page 1 2 [3] 4 5 6 7  Next page →


#72471

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 14:19 +0200
Message-ID<561a53e0$0$3326$426a74cc@news.free.fr>
In reply to#72467
On 10/11/15 13:30, regis wrote:
>
> double
> Point2D_angleFromToAroundOrigin (Point2D start, Point2D end);

Also if you feel that additional info about the nature of the result
(unsigned angle, ccw angle, cw angle, shortest of cw and ccw angles),
should be revealed, then feel free to fix the naming again
to make  these meaningful distinctions appear. For example:

double
Point2D_ccwAngleFromToAroundOrigin (Point2D start, Point2D end);

double
Point2D_cwAngleFromToAroundOrigin (Point2D start, Point2D end);

double
Point2D_shortestAngleFromToAroundOrigin (Point2D start, Point2D end);

double
Point2D_unsignedAngleBetweenAroundOrigin (Point2D pt1, Point2D pt2);

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72472

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 14:48 +0200
Message-ID<561a5a8f$0$3301$426a74cc@news.free.fr>
In reply to#72471
On 10/11/15 14:19, regis wrote:
> On 10/11/15 13:30, regis wrote:
>>
>> double
>> Point2D_angleFromToAroundOrigin (Point2D start, Point2D end);
>
> Also if you feel that additional info about the nature of the result
> (unsigned angle, ccw angle, cw angle, shortest of cw and ccw angles),
> should be revealed, then feel free to fix the naming again
> to make  these meaningful distinctions appear. For example:
>
> double
> Point2D_ccwAngleFromToAroundOrigin (Point2D start, Point2D end);
>
> double
> Point2D_cwAngleFromToAroundOrigin (Point2D start, Point2D end);
>
> double
> Point2D_shortestAngleFromToAroundOrigin (Point2D start, Point2D end);
>
> double
> Point2D_unsignedAngleBetweenAroundOrigin (Point2D pt1, Point2D pt2);


On a sidenote about naming, function goals, and computation of angles,
the atan2() function is <math.h> is a total design failure.

Robert C Martin write in "Clean Code", more or less that:
0) a function should have only one goal
1) its name should reveal this goal
2) its body should do it all
3) its body should do it only
4) its body should do it well

Clearly, the goal of atan2() is to compute the angle
from x-axis to point (x,y). The name fails to reveal this goal.
Instead it reveals how it's being done by the implementation:
by the use of atan().

It even fails further by swapping x and y arguments of atan2():
you have to use atan2(y,x) instead of the expected order atan2(x,y).
Again, this is because they reflected the mean instead of the goal:
the implementation using atan(y/x).

Finally, it fails to reveal that the returned angle is the shortest one
in the range -pi..+pi instead of the natural ccw 0..2*pi.

So we have to cope with:
   double atan2 (double y, double x);
instead of, say:
   double shortest_angle_from_x_axis (double x, double y);
   double ccw_angle_from_x_axis (double x, double y);

-- 
regis











[toc] | [prev] | [next] | [standalone]


#72505

FromMalcolm McLean <malcolm.mclean5@btinternet.com>
Date2015-10-11 12:20 -0700
Message-ID<2ec24ae6-438b-479f-a0c9-4fbd6b0984e7@googlegroups.com>
In reply to#72472
On Sunday, October 11, 2015 at 1:48:27 PM UTC+1, regis wrote:
>
> On a sidenote about naming, function goals, and computation of angles,
> the atan2() function is <math.h> is a total design failure.
> 
> Robert C Martin write in "Clean Code", more or less that:
> 0) a function should have only one goal
> 1) its name should reveal this goal
> 2) its body should do it all
> 3) its body should do it only
> 4) its body should do it well
> 
> Clearly, the goal of atan2() is to compute the angle
> from x-axis to point (x,y). The name fails to reveal this goal.
> Instead it reveals how it's being done by the implementation:
> by the use of atan().
> 
> It even fails further by swapping x and y arguments of atan2():
> you have to use atan2(y,x) instead of the expected order atan2(x,y).
> Again, this is because they reflected the mean instead of the goal:
> the implementation using atan(y/x).
> 
> Finally, it fails to reveal that the returned angle is the shortest one
> in the range -pi..+pi instead of the natural ccw 0..2*pi.
> 
> So we have to cope with:
>    double atan2 (double y, double x);
> instead of, say:
>    double shortest_angle_from_x_axis (double x, double y);
>    double ccw_angle_from_x_axis (double x, double y);
> 
angleBetween() is effectively atan2() in disguise, and yes, that
is exactly the problem. atan2() is acceptable because it's a standard
library function, you pretty soon learn the quirks. 
But as your functions move away from the basic mathematical
repertoire and into more ad hoc, one-off functions, you get more
and more atan2s, until it becomes almost the norm. Every function
has to be checked to determine if it's doing what it says.

[toc] | [prev] | [next] | [standalone]


#72469

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 13:49 +0200
Message-ID<561a4cc6$0$3293$426a74cc@news.free.fr>
In reply to#72466
On 10/11/15 12:59, Malcolm McLean wrote:
> It's hard to enforce a convention on something as nebulous as naming styles.
> In reality the geometry code is likely to be written by one person, the
> code to import and manage the spaceship meshes, by another, and the
> function that applies the transform to move the objects about by a third.

Problem is, all the Point2Dand Matrix2D were probably written
by the same guy or team here. So the inconsistency is internal here.

How can mtx_mul() folow rotationmatrix() and anglebetween() here ?
How can a snake_case abbreviation follow th use of full names
with no word seperators ? It cannot be justified.

Also, why rotationmatrix() feels no problem to return the matrix,
but mtx_mul() by the same author feels the transformed point
should not be returned but passed as an ouput arg instead?
It cannot be justified in the same design.

Why all these preventions about use of pointers to struct for arguments
of anglebetween(), if the first lines of code are bullet.heading
and spaceship.heading being copied into a and b to begin with ?

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72470

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 13:55 +0200
Message-ID<561a4e3a$0$3351$426a74cc@news.free.fr>
In reply to#72469
On 10/11/15 13:49, regis wrote:

> Problem is, all the Point2Dand Matrix2D were probably written
> by the same guy or team here. So the inconsistency is internal here.
>
> How can mtx_mul() folow rotationmatrix() and anglebetween() here ?
> How can a snake_case abbreviation follow th use of full names
> with no word seperators ? It cannot be justified.
>
> Also, why rotationmatrix() feels no problem to return the matrix,
> but mtx_mul() by the same author feels the transformed point
> should not be returned but passed as an ouput arg instead?
> It cannot be justified in the same design.


Also, the guy who wrote mtx_mul() to apply  a matrix transform
to a point probably also wrote a function that really multiplies
2 matrices somewhere else... I wonder how he named it after his
misnomer of mtx_mul() since now this name is not available ;o))

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72442

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 02:40 +0200
Message-ID<5619aff5$0$3171$426a74cc@news.free.fr>
In reply to#72434
On 10/11/15 01:21, Malcolm McLean wrote:

> void closeparens(char *str)
> {
>   int Nopen = 0;
>   int i;
>
>   for(i=0;str[i];i++)
>   {
>     if(str[i] == '(')
>       Nopen++;
>     else if(str[i] == ')')
>       Nopen--;
>     assert(Nopen >= 0);
>   }
>   while(Nopen--)
>     str[i++] = ')';
>   str[i] = 0;
> }

Your i is at the right scope since you use it outside the loop.
My concern is elsewhere with your code:

When there are two conceptual loops in a functions,
it's usually that they're doing the tasks of other functions.
Here I would at least extract the for(;;) loop to its own function
and probably the  while() loop too. Hence:

void close_parens (char string[])
{
   int length, count= count_open_parens (string, & length);
   fill_with_char (& string[length], count, ')' );
}

My count_open_parens() prolly still does too much work
as it tries to return both count and length in a single pass.

int count_open_parens (char const string[], int * length)
{
   int k, count= 0;
   for (k= 0; string[k] != '\0'; k++) {
     if      (string[k] == '(' ) count++;
     else if (string[k] == ')' ) count--;
     assert (count >= 0);
   }
   * length= k;
   return count;
}

void fill_with_char (char string[], int count, char character)
{
   int k;
   for (k= 0; k < count; k++) {
     string[k]= character;
   }
   string[k]= '\0';
}

int main (void)
{
   char text[]= "(a+(b*(c+d)-e\0\0\0\0\0\0\0";
   close_parens (text);
   printf ("%s\n", text);
   return 0;
}

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72448

FromIan Collins <ian-news@hotmail.com>
Date2015-10-11 14:40 +1300
Message-ID<d7tsvmFj978U2@mid.individual.net>
In reply to#72428
Malcolm McLean wrote:
> On Saturday, October 10, 2015 at 10:21:51 PM UTC+1, Ian Collins wrote:
>>
>> A small point of style:  you are using C99, so you can save clutter by
>> restricting the loop counter scope to the loop:
>>
>>         for (int i = 0; string[i] != '\0'; i++)
>>
> I find I use the final value of the index counter frequently enough
> to mean i doesn't have enough scope, and it's better if all
> the loops look the same.

As others have said, because there are cases where the counter is used 
later and cases where it is not is ample reason for the two forms not to 
look the same.  This example wasn't using i anywhere other than in the loop.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#72425

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-10 22:29 +0100
Message-ID<87twpyh0oc.fsf@bsb.me.uk>
In reply to#72400
Alla _ <modelling.data@gmail.com> writes:
<snip>
> Here is the program, and below it is my question (or rather
> questions).
>
> // Count words and determine if a character is alphabetic
>
> #include <stdio.h>
> #include <stdbool.h>
<snip>
> // Function to cound the number of words in a string
> int count_words (const char string[])
> {
>     int i; /** used to sequence through each character
>             in the string **/
>
>     int word_count = 0;
>
>     bool look_for_word = true; 
>
> /** used as a flag to indicate whether 
>     you are currently in the process of looking for the start of a 
>     new word; at the beginning of execution you obviously are looking 
>     for the start of a new word, so this flag is set to true **/
>     
>     for (i = 0; string[i] != '\0'; i++)
>         
>         if (alphabetic (string [i]))
>         {
>             if (look_for_word)
>             {
>                 word_count++;
>                 look_for_word = false;
>             }
>         }
>         else
>             look_for_word = true;
>     
>     return word_count;
> }
<snip>
>      For example: let's take the phrase 'app new'
>      
>      for (i = 0; string[i] != '\0'; i++)
>         if (alphabetic (string [i]))
>         {
>             if (look_for_word)
>             {
>                 word_count++;
>                 look_for_word = false;
>             }
>         }

Take care: you've cut of a key part of the loop.  There is an else part
that says "else look_for_word = true;".

>      The above part should, if I understand it correctly (well, I don't! :)),
>      do the following:
>      
>      1) before the for loop starts the look_for_word is set to true;
>      
>      2) then i = 0 is 'a' is tested, and it is alphabatic, thus the
>      program enters the outer if condition;
>      
>      3) as soon as the character 'a' is discerned as an alphabetical one,
>      the inner if condition starts; I don't understand the meaning of
>      this condition: does (look_for_word) have no value as a condition, 
>      and acts only as a "signal" that this flag will get a value
>      later?

Many people learning programming are often confused by true/false
variables.  It sometimes helps to imagine if (look_for_word) as if it
were written if (look_for_word == true).

>      the value true has been initially assigned to this flag, and 
>      has not been changed before this inner if condition; hence it's value 
>      is still true when the program enters this inner if condition;
>      confusing.

Hmmm... why is that confusing?  Yes, it starts true and is true here
when we see the first 'a' in your example string.  That's exactly what
should happen.  The variable "look_for_word" is supposed to mean that
the program is looking for the start of a word and has not yet found it.

>      4) as the program detected the character 'a' as an alphabatical one,
>      word_count++ means that the word_count variable's value is not incremented
>      by one and has a value of 1 and look_for_word is set to false, because we
>      are inside the word now.

Yup.
   
>      5) the program now moves to the second character i = 1 which is 'p'; the 
>      test shows that it is the alphabatical one.
>      
>      6) when the program starts working with 'p' character, the inner 
>      if  condition (look_for_word) is false, because it was set to false 
>      in the previous round.

Yup.
      
>      7) given word_count is within the for loop, it should be incremented 
>      with  each alphabatical character,

No, it should be incremented only when the program executes
word_count++.  That should not happen for every alphabetic character.
In fact the flag variable is used to make sure that word_count++ happens
only once for every run of consecutive alphabetic characters.

>      but not with each word, and thus, 
>      when the program is done working with 'p', word_cound should be equal 
>      to 2. I know that the code works as it should, but I don't see
>      how.

This puzzles me.  word_count should and will be 1 after processing the 'p'.

>      And so on, until the code reaches a blank space between app and new; 
>      the count is terminated, and starts when the next alphabatical character
>      is found.
>      
>      Here is the table they use for demonstration in the book. I don't see how 
>      word_count gets these values; I added my erroneous numbers to show how I 
>      see that part of the code.
>          
>      i    string[i]  word_count  look_for_word       my word_count
>                         0         true                    0
>      0        'a'       1         false                   1
>      1        'p'       1         false                   2
>      2        'p'       1         false                   3

In those last three cases what code could possibly change word_count?
When look_for_word is false, the test if (look_for_word) fails and the
increment is not done.

>      3        ' '       1         true                    nothing
>      4        'n'       2         false                   4
>      5        'e'       2         false                   5
>      6        'w'       2         false                   6
>      7        '\0'      2         true                    nothing
>      **/

There are, to my mind, much clearer ways to write this code.  For
example, you can count a word at the trailing boundary: when the
character being looked at is alphabetic but the next character is not
alphabetic.  That can be directly expressed in C:

  alphabetic(string[i]) && !alphabetic(string[i+1])

This expression has an integer value because, in C, false is 0 and true
is 1 (by this I mean the names defined in stdbool.h that you are
using).  We can chart this value at every point in an example string:

i                                                 0 1 2 3 4 5 6 7
string[i]                                         a p p   n e w \0
alphabetic(string[i])                             1 1 1 0 1 1 1 0
!alphabetic(string[i+1])                          0 0 1 0 0 0 1 ?
alphabetic(string[i]) && !alphabetic(string[i+1]) 0 0 1 0 0 0 1 0

The ? indicates that we can't ask about string[i+1] once i has become
the index of the terminating null, but we don't need to worry about that
because, as I think you can see form this chart, the word count is just
the sum of this expression over all the non-null characters:

  int word_count = 0;
  for (int i = 0; string[i]; i++)
     word_count += alphabetic(string[i]) && !alphabetic(string[i+1]);
  return word_count;

Now about 99% of people here will consider this to be the most appalling
code!  I won't defend it now, but it really is worth understanding how
it works and why, even if you decide you never want to write code like
this again.

-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#72429

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 00:22 +0200
Message-ID<56198fa3$0$3034$426a34cc@news.free.fr>
In reply to#72425
On 10/10/15 23:29, Ben Bacarisse wrote:

> Many people learning programming are often confused by true/false
> variables.  It sometimes helps to imagine if (look_for_word) as if it
> were written if (look_for_word == true).

Correct this to: Many people teaching programming...

This is because they are mostly math teacher
disguised as computer science teachers.

Therefore, they see the computation part
but fail to see the language part.

They fail to see if(...) and while(...)
as language constructions to allow a sentence with a verb
to continue here, that is: if (something_holds) ...

if (string_contains_substring (name, "lol")) ...
if (string_starts_with_char (name, 'B')) ...
if (string_matches_regex (name, "[A-Za-z]+")) ...

Therefore, math teachers teach them how they understand them,
that is as: if (equation) and hence as if some comparison operator
was mandatory in them, that is:
if (... == ...)
if (... != ...)
if (... <= ...)
etc.

They are the ones to blame before blaming the beginners.
Basically, math teachers teaching programming fail
to acknowledge the importance (if not the existence)
of *verbs* in *imperative* languages.

In particular, they fail at using verbs for their predicates,
E.g, they write:
bool even (int n) { return n % 2 == 0; }

... instead of:
bool int_is_even (int n) { return n % 2 == 0; }

This is indeed this failure that in turn makes them write:
   if (even (n) == true) ...
instead of:
   if (integer_is_even (n)) ...

They also fail to write verbs for their procedure names,
and therefore their procedure name are sometimes not even connected
to the goal of the call but to the circumstance of the call. Eg:

if (c == EOF) end_of_file (data); // err... what happens here ?

-- 
regis











[toc] | [prev] | [next] | [standalone]


#72432

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 00:57 +0200
Message-ID<561997ee$0$4563$426a74cc@news.free.fr>
In reply to#72429
> In particular, they fail at using verbs for their predicates,
> E.g, they write:
> bool even (int n) { return n % 2 == 0; }
>
> ... instead of:
> bool int_is_even (int n) { return n % 2 == 0; }
>
> This is indeed this failure that in turn makes them write:
>    if (even (n) == true) ...
> instead of:
>    if (integer_is_even (n)) ...
>
> They also fail to write verbs for their procedure names,
> and therefore their procedure name are sometimes not even connected
> to the goal of the call but to the circumstance of the call. Eg:
>
> if (c == EOF) end_of_file (data); // err... what happens here ?


Oh, and for those writing in french, it's even worse.
When they manage to find their way to a verb for procedure names,
they fail at using the right mode:
They use indicative mode, the one reserved for predicates.

That is, instead of the correct:
   afficher_matrice (m); // print_matrix (m);
they either simply use no verb:
   affichage_de_matrice (m); // printing_of_matrix (m);
or they fail at using the right mode:
   affiche_matrice (m); // prints_matrix (m);

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72435

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-11 00:46 +0100
Message-ID<87io6eguc5.fsf@bsb.me.uk>
In reply to#72429
regis <regis.barbanchon@free.fr> writes:

> On 10/10/15 23:29, Ben Bacarisse wrote:
>
>> Many people learning programming are often confused by true/false
>> variables.  It sometimes helps to imagine if (look_for_word) as if it
>> were written if (look_for_word == true).
>
> Correct this to: Many people teaching programming...

Really?  That's not been my experience.

<snip>
> They are the ones to blame before blaming the beginners.

Yes, that is almost always true.  If it sounded like I was blaming Alla_
for anything, I'm sorry about that.  Obviously the text and the course
did not succeed in explaining the example program.

> Basically, math teachers teaching programming fail
> to acknowledge the importance (if not the existence)
> of *verbs* in *imperative* languages.
>
> In particular, they fail at using verbs for their predicates,
> E.g, they write:
> bool even (int n) { return n % 2 == 0; }
>
> ... instead of:
> bool int_is_even (int n) { return n % 2 == 0; }

Specifically auxiliary verbs.  Some others also work but I wouldn't say
that there's a hard and fast rule about verbs in general.  For example,
in this case the teacher did use a verb, but not in my opinion the best
part of speech, and not the best verb either.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#72438

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 02:23 +0200
Message-ID<5619abf1$0$3166$426a74cc@news.free.fr>
In reply to#72435
On 10/11/15 01:46, Ben Bacarisse wrote:
>> >In particular, they fail at using verbs for their predicates,
>> >E.g, they write:
>> >bool even (int n) { return n % 2 == 0; }
>> >
>> >... instead of:
>> >bool int_is_even (int n) { return n % 2 == 0; }
> Specifically auxiliary verbs.  Some others also work but I wouldn't say
> that there's a hard and fast rule about verbs in general.  For example,
> in this case the teacher did use a verb, but not in my opinion the best
> part of speech, and not the best verb either.

Nope, here, he used the adjective "even" without "is".

Many of my colleagues use e.g. "full fridge"
interchangeably to mean either:
"fill this fridge",
"the fridge is full", or
"a full fridge".

That is, they name functions with side effects (procedures)
the same way they name predicates
and other functions without side effect.

And it's a mess.

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72440

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-11 01:28 +0100
Message-ID<877fmugsf4.fsf@bsb.me.uk>
In reply to#72438
regis <regis.barbanchon@free.fr> writes:

> On 10/11/15 01:46, Ben Bacarisse wrote:
>>> >In particular, they fail at using verbs for their predicates,
>>> >E.g, they write:
>>> >bool even (int n) { return n % 2 == 0; }
>>> >
>>> >... instead of:
>>> >bool int_is_even (int n) { return n % 2 == 0; }
>> Specifically auxiliary verbs.  Some others also work but I wouldn't say
>> that there's a hard and fast rule about verbs in general.  For example,
>> in this case the teacher did use a verb, but not in my opinion the best
>> part of speech, and not the best verb either.
>
> Nope, here, he used the adjective "even" without "is".

I meant in the case you seemed to be cross about: look_for_word.  Were
you not suggesting that it was a bad choice?  I might have misunderstood
that whole part of your post.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#72450

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 04:21 +0200
Message-ID<5619c7a9$0$3864$426a74cc@news.free.fr>
In reply to#72440
On 10/11/15 02:28, Ben Bacarisse wrote:
> I meant in the case you seemed to be cross about: look_for_word.  Were
> you not suggesting that it was a bad choice?

Nope.

> I might have misunderstood that whole part of your post.

I wrote that look_for_word has an implicit verb conjugated
using indicative mode, present tense: must_.
That is, it should be understood as must_look_for_word.

Boolean variables have relaxed naming conventions in comparison
to predicate functions where the verb is mandatory in order
to distinguish to from other kind of functions.

For example:

fillFridge() is a procedure called
*in order to* fill the fridge.

fullFridge() is a function called
*in order to get* a full fridge.

fridgeIsFull() is a predicate called
*in order to test if* the fridge is full.

fridgeFull() is not a function in imperative languages.
That is, it is not related to the goal of the call
like the 3 others  (with a *in order to...* relation to the name).
It's related to the circumstance of its call
and it's not designed for being called directly.
It's a callback/handler that is called back
*whenever we have*/*in the event of* a fridge full.

However, for Boolean variables it's not a problem to have:
   bool fridge_full= fridgeIsFull (f);
   bool full= fridgeIsFull (f);
instead of:
   bool fridge_is_full= fridgeIsFull (f);
   bool is_full= fridgeIsFull (f);

But we have to know that the verb is still implicitly there.

-- 
regis









[toc] | [prev] | [next] | [standalone]


#72452

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 04:32 +0200
Message-ID<5619ca23$0$4575$426a34cc@news.free.fr>
In reply to#72450
On 10/11/15 04:21, regis wrote:
>
> Boolean variables have relaxed naming conventions in comparison
> to predicate functions where the verb is mandatory in order
> to distinguish to from other kind of functions.
>
> For example:
>
> fillFridge() is a procedure called
> *in order to* fill the fridge.
>
> fullFridge() is a function called
> *in order to get* a full fridge.
>
> fridgeIsFull() is a predicate called
> *in order to test if* the fridge is full.
>
> fridgeFull() is not a function in imperative languages.
> That is, it is not related to the goal of the call
> like the 3 others  (with a *in order to...* relation to the name).
> It's related to the circumstance of its call
> and it's not designed for being called directly.
> It's a callback/handler that is called back
> *whenever we have*/*in the event of* a fridge full.
>
> However, for Boolean variables it's not a problem to have:
>    bool fridge_full= fridgeIsFull (f);
>    bool full= fridgeIsFull (f);
> instead of:
>    bool fridge_is_full= fridgeIsFull (f);
>    bool is_full= fridgeIsFull (f);
>
> But we have to know that the verb is still implicitly there.


which means, even in absence of the verb,  you still have to write
   if (fridge_full) { ... }
   if ( ! fridge_full) { ... }
as if the verb was here, that is as if we had:
   if (fridge_is_full) { ... }
   if ( ! fridge_is_full) { ... }

and *never*:
   if (fridge_full == true) { ... }
   if (fridge_full == false) { ... }
that is, adding == or != to provide the missing verb.

That was my point.

-- 
regis



[toc] | [prev] | [next] | [standalone]


#72459

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2015-10-11 11:06 +0100
Message-ID<87r3l1g1mo.fsf@bsb.me.uk>
In reply to#72450
regis <regis.barbanchon@free.fr> writes:

> On 10/11/15 02:28, Ben Bacarisse wrote:
>> I meant in the case you seemed to be cross about: look_for_word.  Were
>> you not suggesting that it was a bad choice?
>
> Nope.
>
>> I might have misunderstood that whole part of your post.
>
> I wrote that look_for_word has an implicit verb conjugated
> using indicative mode, present tense: must_.
> That is, it should be understood as must_look_for_word.

Then we are in agreement about that part (except I read it as
"looking_for_a_word").

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#72444

Fromregis <regis.barbanchon@free.fr>
Date2015-10-11 02:55 +0200
Message-ID<5619b37e$0$3077$426a74cc@news.free.fr>
In reply to#72438
On 10/11/15 02:30, Stefan Ram wrote:
>        »Procedure names should reflect what they do;
>        function names should reflect what they return.«
>
>      Rob Pike
>
>        »Besides a mathematical inclination, an exceptionally
>        good mastery of one's native tongue is the most vital
>        asset of a competent programmer.«
>
>      Edsgar Dijkstra
>
>        »While sloppy writing does not invariably mean sloppy
>        thinking, we've generally found the correlation to be
>        strong -- and we have no use for sloppy thinkers.
>        If you can't yet write competently, learn to.«
>
>      Eric Raymond
>
>        »I've found that some of the best [Software ]developers
>        of all are English majors. They'll often graduate with
>        no programming experience at all, and certainly without
>        a clue about the difference between DRAM and EPROM.
>
>        But they can write. That's the art of conveying
>        information concisely and clearly. Software development
>        and writing are both the art of knowing what you're going
>        to do, and then lucidly expressing your ideas.«
>
>      Paul Potts

+1,000,000 ;o)

I would add an additional case about predicates in the first quote.

-- 
regis

[toc] | [prev] | [next] | [standalone]


#72964

FromTim Rentsch <txr@alumni.caltech.edu>
Date2015-10-15 10:36 -0700
Message-ID<kfnpp0gjao9.fsf@x-alumni2.alumni.caltech.edu>
In reply to#72438
ram@zedat.fu-berlin.de (Stefan Ram) writes:

> regis <regis.barbanchon@free.fr> writes:
>> That is, they name functions with side effects (procedures)
>> the same way they name predicates
>> and other functions without side effect.
>
>       >>Procedure names should reflect what they do;
>       function names should reflect what they return.<<
>
>     Rob Pike
>
>       >>Besides a mathematical inclination, an exceptionally
>       good mastery of one's native tongue is the most vital
>       asset of a competent programmer.<<
>
>     Edsgar Dijkstra
>
>       >>While sloppy writing does not invariably mean sloppy
>       thinking, we've generally found the correlation to be
>       strong -- and we have no use for sloppy thinkers.
>       If you can't yet write competently, learn to.<<
>
>     Eric Raymond
>
>       >>I've found that some of the best [Software ]developers
>       of all are English majors.  They'll often graduate with
>       no programming experience at all, and certainly without
>       a clue about the difference between DRAM and EPROM.
>
>       But they can write.  That's the art of conveying
>       information concisely and clearly.  Software development
>       and writing are both the art of knowing what you're going
>       to do, and then lucidly expressing your ideas.<<
>
>     Paul Potts 

I believe the last quote is misattributed.  Doing a web
search shows that this appears to have been written by
Jack Ganssle (whoever that is, I hadn't heard of him
before doing the search).

[toc] | [prev] | [next] | [standalone]


#72994

FromGeoff <geoff@invalid.invalid>
Date2015-10-15 14:37 -0700
Message-ID<ld602bpb9soc2qb04oahv5g77fhuhb037t@4ax.com>
In reply to#72964
On Thu, 15 Oct 2015 10:36:54 -0700, Tim Rentsch
<txr@alumni.caltech.edu> wrote:

>ram@zedat.fu-berlin.de (Stefan Ram) writes:
>
>> regis <regis.barbanchon@free.fr> writes:
>>> That is, they name functions with side effects (procedures)
>>> the same way they name predicates
>>> and other functions without side effect.
>>
>>       >>Procedure names should reflect what they do;
>>       function names should reflect what they return.<<
>>
>>     Rob Pike
>>
>>       >>Besides a mathematical inclination, an exceptionally
>>       good mastery of one's native tongue is the most vital
>>       asset of a competent programmer.<<
>>
>>     Edsgar Dijkstra
>>
>>       >>While sloppy writing does not invariably mean sloppy
>>       thinking, we've generally found the correlation to be
>>       strong -- and we have no use for sloppy thinkers.
>>       If you can't yet write competently, learn to.<<
>>
>>     Eric Raymond
>>
>>       >>I've found that some of the best [Software ]developers
>>       of all are English majors.  They'll often graduate with
>>       no programming experience at all, and certainly without
>>       a clue about the difference between DRAM and EPROM.
>>
>>       But they can write.  That's the art of conveying
>>       information concisely and clearly.  Software development
>>       and writing are both the art of knowing what you're going
>>       to do, and then lucidly expressing your ideas.<<
>>
>>     Paul Potts 
>
>I believe the last quote is misattributed.  Doing a web
>search shows that this appears to have been written by
>Jack Ganssle (whoever that is, I hadn't heard of him
>before doing the search).

Boy, there's a blast from the past. I remember reading his articles in
Embedded Systems many years ago. I think I used his ICE for the Z180
back in '92. Softaid, Inc. was his company, IIRC. 

[toc] | [prev] | [next] | [standalone]


#72461

Fromraltbos@xs4all.nl (Richard Bos)
Date2015-10-11 10:15 +0000
Message-ID<561a3610.4445765@news.xs4all.nl>
In reply to#72425
Ben Bacarisse <ben.usenet@bsb.me.uk> wrote:

>   int word_count = 0;
>   for (int i = 0; string[i]; i++)
>      word_count += alphabetic(string[i]) && !alphabetic(string[i+1]);
>   return word_count;
> 
> Now about 99% of people here will consider this to be the most appalling
> code!

Not at all, I've seen much worse. This is only slightly appalling, and
can easily be fixed like this:

  int word_count = 0;

  for (int i = 0; string[i]; i++)
    if (alphabetic(string[i]) && !alphabetic(string[i+1])
      word_count++;

  return word_count;

Add braces as you prefer (I might add them for the for loop, though in
this case I probably wouldn't - for that, though, I'd _insist_ on the
extra blank lines), and you have the perfect counter.

Richard

[toc] | [prev] | [next] | [standalone]


Page 3 of 7 — ← Prev page 1 2 [3] 4 5 6 7  Next page →

Back to top | Article view | comp.lang.c


csiph-web