1 <!DOCTYPE HTML PUBLIC
"-//W3O//DTD W3 HTML 2.0//EN">
2 <!-- This collection of hypertext pages is Copyright 1995, 1996 by Steve Summit. -->
3 <!-- This material may be freely redistributed and used -->
4 <!-- but may not be republished or sold without permission. -->
7 <link rev=
"owner" href=
"mailto:scs@eskimo.com">
8 <link rev=
"made" href=
"mailto:scs@eskimo.com">
9 <title>section
1.5.4: Word Counting
</title>
10 <link href=
"sx4h.html" rev=precedes
>
11 <link href=
"sx4j.html" rel=precedes
>
12 <link href=
"sx4.html" rev=subdocument
>
15 <H2>section
1.5.4: Word Counting
</H2>
19 <blockquote>In a program as tiny as this,
20 it makes little difference,
21 but in larger programs,
22 the increase in clarity is well worth the modest extra effort
23 to write it this way from the beginning.
24 </blockquote>I agree with this.
25 Some people complain that symbolic constants make a program
27 because you always have to look them up to see what they mean.
28 As long as you choose appropriate names for symbolic
29 constants and use them consistently
30 (i.e. even if APPLE and ORANGE happen to have the same value,
31 don't use one when you mean the other),
32 no one will have this complaint about your programs.
34 <p>Note that there's no direct way to simplify
36 <pre> if (c == ' ' || c == '\n' || c == '\t')
37 </pre>In particular, something like
38 <pre> if (c == (' ' || '\n' || '\t'))
39 </pre>would
<em>not
</em> work.
44 <a href=
"sx4h.html" rev=precedes
>prev
</a>
45 <a href=
"sx4j.html" rel=precedes
>next
</a>
46 <a href=
"sx4.html" rev=subdocument
>up
</a>
47 <a href=
"top.html">top
</a>
50 This page by
<a href=
"http://www.eskimo.com/~scs/">Steve Summit
</a>
51 //
<a href=
"copyright.html">Copyright
</a> 1995,
1996
52 //
<a href=
"mailto:scs@eskimo.com">mail feedback
</a>