RE: A question about certain language features

new topic     » goto parent     » topic index » view thread      » older message » newer message

Ed Davis wrote:
> > > 1) Variables can not be initialized when declared, but
> > > rather, must be initialized via an assignment statement.
> > > Based on other languages, this seems like one of those
> > > convenience type issues.  Is there some programming
> > > philosophy that says that an initialization in a declaration
> > > is a 'bad thing'?  What is the 'bad thing'?  I also note
> > > that standard Pascal does not allow variables to be
> > > initialized when they are declared.
> >
> > There is good article by Travis Beaty about this point.
> > Visit please:
> > http://www.RapidEuphoria.com/hotnew.htm
> > There is the link to that article in this html.
> 
> Hmmm.  I read the article, but I still don't understand why:
> 
> function foo()
>   integer a
>   a = someNastyComputation()
>   -- lots of code that massages a snipped
>   return a
> end function
> 
> is ok, whereas:
> 
> function foo()
>   integer a = someNastyComputation()
>   -- lots of code that massages a snipped
>   return a
> end function
> 
> is 'dangerous'? (if it were allowed, which it is not)

???

Correct me if I'm wrong, but hasn't Euphoria supported that since 
version 2.2? (I'm not certain, I haven't made use of it. Just 
preference.)

<snip>

> > > 3) No support for local constants.
> >
> > There *is* full support for local constants in Euphoria.
> > Terms are: global - for a different files scope,
> > local -- just for single file scope, private -- just for
> > current subroutine scope.
> > *Private* constants are not supported, becouse of *all*
> > private variables exist just inside soubroutine.
> > Local constants are very useful for cross-routine use
> > inside the library file. Say, you have global functions in
> > the include file. You can set *local* constants just for
> > those global functions just inside single lib.
> >
> > See and try Local <--> Private <--> Global,
> > thing looks just like to the real life.
> 
> I think we are not talking about the same thing.  I am
> referring to the reference manual, which says, in section
> 2.4.1, under heading "constants":
> 
> "Constants may not be declared inside a subroutine."

You can have local constants. Just do:

   constant MY_CONST = 1

outside of a routine. This limits it to the include file that it's in, 
so it's not global. However, *private* constants, declared and scoped 
only within a routine, are NOT allowed.

I'm not sure why. Wouldn't seem to be any worse than a private variable. 
Although I would think you'd have to have a fairly large routine to use 
a constant in it that wouldn't be used in other routines.

Rod Jackson

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu