"for" loops (was Re: C++ vs. Modula

Scott Bigham sbigham at dukeac.UUCP
Fri Feb 3 05:52:16 AEST 1989


In article <7800002 at gistdev> flint at gistdev.UUCP writes:
>
>I've always felt that it should be the job of programming languages to let
>me say what I want to do concisely, and then they should do it the way I
>want.

What you want, it seems, is a programming language that can read your mind.

>       Therefore, there is no reason I can see that the language should not
>let you have an increment of .1, since it is quite clear exactly what I
>want it to do in this case: 

Obvious to you.  How do you explain it to the compiler?

>			     the compiler ought to be able to see (easily)
>that it needs to set up a dummy integer counter to actually control the
>loop, and divide by 10 at the top of the loop for you to give you the index
>you use.

That's not at all obvious, and in many cases it's not even possible.  How do
you resolve this loop?

 for (i=0.0;i<100.0;i+=PI);

In the general case, such optimizations as you describe would require lots of
convolutions and aren't useful often enough to be worth it.  If you really
want the compiler to use an integer, tell it to.

>	   By doing so, it allows experienced people to do less typing, and
>protects beginners from their ignorance- you win both ways.

Not necessarily what we want to do.  If you shelter beginners from their
mistakes, they can't learn from them.

Remember: for every situation in which the compiler does exactly what you 
want, there are at least ten people who think the compiler should do it
differently.

>Flint Pellett, Global Information Systems Technology, Inc.
>1800 Woodfield Drive, Savoy, IL  61874     (217) 352-1165
>INTERNET: flint%gistdev at uxc.cso.uiuc.edu
>UUCP:     {uunet,pur-ee,convex}!uiucuxc!gistdev!flint

						sbigham
-- 
Scott Bigham                         "The opinions expressed above are
Internet sbigham at dukeac.ac.duke.edu   (c) 1989 Hacker Ltd. and cannot be
USENET   sbigham at dukeac.UUCP          copied or distributed without a
...!mcnc!ecsgate!dukeac!sbigham       Darn Good Reason."



More information about the Comp.lang.c mailing list