RE: Hello

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

Greetings, Xanax. I hope Rob doesn't mind if I copy his excellent 
explanation as to why "integer var = val" isn't permitted in Euphoria.

Also, don't hesitate to use the "mailing list search" on the Euphoria 
website, as answers to this and many other questions can be found that 
way (that's how I found this).

Cheerios,
   Gabriel


From: Robert Craig <rds at RapidEuphoria.com>
Subject: Re: A question about certain language features

Ed Davis writes:
> 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'? 

It's not a "bad thing". In fact it seems like an obvious bit of
convenience that couldn't possibly cause any harm.
Since a lot of people have asked lately, here is my
(very subjective) opinion on the matter. I've also
included your question about private constant declarations.

Suppose we allow:

#1.  variable inits:  integer x = 99

and if you allow #1, it would be even stranger (than it is now)
not to allow:

#2.  constants declared inside a routine for use within that routine 
only

So now you've got routines that start off with an arbitrary mixture
of variable and constant declarations, some of the variables
are assigned an initial value, some aren't. The only visual difference
between a constant declaration and a variable declaration, is
that people have to remind themselves that "constant" is not a type,
it's something totally different. e.g.

function aaa(integer z)
object d, e, f
constant a = 99 * foo()
integer b = 99 + bar() * 7, h, i, g = 777
atom c
g += 1
h = g
etc.

Now whenever you examine a routine, instead of quickly skipping
over the declarations, you will have to carefully
wade through all the declarations, some containing
function calls and complicated expressions, to figure out 
which code is going to be executed. 

Simply stated, you've got executable code hidden amongst the
declarations, and constant declarations now look no different from 
variable declarations. Things used to be neatly separated and
you could visually skip the declarations when mentally tracing
execution. Now things are jumbled together. 

I once spent hours debugging something in another language,
simply because the author of the code had hidden a variable
declaration with initialization in amongst 20 or so other declarations.
I just couldn't "see" that the subroutine did not really "start" where 
I thought it did. It actually started in the middle of the declarations
somewhere.

I like it better the way it is. You could argue that I don't have to use 

variable inits if I don't want to. You could argue that I don't have
to use goto if I don't want to. A language does not exist just
to serve the isolated programmer. It exists to serve a community
of programmers. In situations where it really doesn't matter 
how something is written, I think there are advantages to 
reducing the number of choices.

[...]

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu