[M3devel] introducing VAR in more places?
hendrik at topoi.pooq.com
hendrik at topoi.pooq.com
Tue Feb 12 14:52:05 CET 2008
On Tue, Feb 12, 2008 at 05:41:31AM -0800, Mika Nystrom wrote:
> hendrik at topoi.pooq.com writes:
> >On Mon, Feb 11, 2008 at 10:17:13PM -0600, Rodney M. Bates wrote:
> >> I don't think this is what Tony meant. In C++, an opening brace
> >> starts a block, but every local declaration in that block has its own
> >> unique scope that only starts at that declaration and goes to the end
> >> of the block. This is particularly messy because the local declarations
> >> of a block need not all precede all the statements,
> >
> >That is, in my opinion, one of the few things that C and C++ did right,
> >well, almost right. It permits a coding style in which every
> >variable declaration is initialised, and is declared if and only if it
>
> You can do all kinds of fun stuff with C's declarations/initializations.
>
> switch (a) {
> int x=7;
> case 0:
> use(x); /* oops */
> ...
> }
>
> goto somewherefun;
>
> {
> int y=7;
>
> somewherefun:
> use(y); /* oops again */
> }
That's more a problem with C's control structures. Each case should be
a block of its own. The bits outside any case shouldn't be there.
etc., etc.
>
>
> >has a value. Now that's a useful property. It fails for recursion,
> >so there are limits in how far it can apply. And when coding like this,
> >you want the simplest syntax to define a constant identifier -- one
> >whose value cannot be rebound except by reexecuting the entire block.
> >Making something that can change should require more effort -- like
> >adding a keyword "var" or some such.
>
> Sounds to me like you're talking about Modula-3's WITH!
Close, except for syntax. If you use WITH in the stype I'm
advocating you end up with extremely deep syntactic nesting, and you
indent off the side of the page. Also, the whole WITH syntax is quite
heavy.
-- hendrik
More information about the M3devel
mailing list