1. Global = root of all evil

Hi all,

Global vars, funcs, procs, etc.. root of all evil??
 
more so in C but in Euphoria as well..

Any takers??

personally I'm making sure my habits of using global's
extinct..for the most part..
 
Euman

new topic     » topic index » view message » categorize

2. Re: Global = root of all evil

Euman wrote:
> 
> Hi all,
> 
> Global vars, funcs, procs, etc.. root of all evil??
>  
> more so in C but in Euphoria as well..
> 
> Any takers??
> 
> personally I'm making sure my habits of using global's
> extinct..for the most part..

Agreed. The more global items you have the more dependancies you create between
files. And the more dependancies the harder it is to change things without
upsetting something (or someone) else.

A good rule of thumb (and this has been around since the 1970s) is eliminate
every instance of module coupling, except where you absolutely must have for
performance reasons (and that is almost never).

This doesn't really apply to global constants though.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

3. Re: Global = root of all evil

Euman wrote:
> 
> Hi all,
> 
> Global vars, funcs, procs, etc.. root of all evil??
>  
> more so in C but in Euphoria as well..
> 
> Any takers??
> 
> personally I'm making sure my habits of using global's
> extinct..for the most part..

Greetings Euman

I agree about global vars, good containment dictates that you access or modify
data in an include module via a routine... but it would be a bit hard to utilise
the include system without global routines??? smile

I have seen suggestions for enforcing the name scoping of global functions, eg

include english.e as en
include francais.e as fr

-- scenario: _must_ use name scope to access functions
if language = ENGLISH then
    en:greet()
elsif language = FRANCAIS then
    fr:greet()
else
    greet() -- default
end if


... where you would be forced to use name space qualifiers.

I like Perl's system where the folders and include file name make up the fully
qualified package name, you can even export vars without risk of a conflict since
they are fully qualified.

Gary

new topic     » goto parent     » topic index » view message » categorize

4. Re: Global = root of all evil

On Wed, 01 Nov 2006 17:53:37 -0500, Euman <Euman at triad.rr.com> wrote:

>Hi all,
>
>Global vars, funcs, procs, etc.. root of all evil??
> 
>more so in C but in Euphoria as well..
>
>Any takers??
>
>personally I'm making sure my habits of using global's
>extinct..for the most part..

It is not a bad idea to perform a global search for "global" as part
of source code cleanup. Global constants and routines are a bit of a
necessity. If your results are something like:
eaclip.ew:17 global function copyTextToClipboard(sequence lines)
eaclip.ew:66 global function getTextFromClipboard()
eaclip.ew:116 global function isClip()

Then you can be pretty sure it will not cause you much grief, even:
global integer cbX, cbY
global procedure ctrlBracket(integer direction)
--
-- process ctrl [ and ctrl ].
-- jump to matching [end] procedure/function/type/for/while;
-- cycle fwd/back through if/{elsif}/else/endif;
-- jump to matching [,], (,), {,}.
--
-- direction is -1 for backward, +1 for normal forward, or 
-- 0 for forward skipping elsif/else. (fold handling)
--
-- Result in cbX, cbY
    cbX=CursorX
    cbY=CursorY

is not too bad, as cbX, cbY are only meaningful after a call to
ctrlBracket, and hence it does not matter if you overwrite them in
some other random place, whereas:
easynld.e:9 global sequence Extensions,     -- eg {"e","ex","exw"}
easynld.e:12 global integer newSyntax        -- ExtensionNo, or 1=none
easynld.e:15 global sequence SynNames,       -- eg "Euphoria"
easynld.e:30 global integer MAXnColours
easynld.e:56 global sequence wordChar    -- set by easynld.e
easynld.e:59 global sequence standardColourNames,standardColours
easynld.e:96 global sequence comment -- eg "--"  -- set by changeTo()
easynld.e:97 global sequence blockComment        -- ""
easynld.e:98 global sequence ColourTab           -- ""
easynld.e:99 global sequence StyleTab            -- ""
easynld.e:103 global sequence charMap     -- set by changeTo()
easynld.e:105 global sequence urlChar     -- all are TokenChar
easynld.e:706 global procedure initSyn()
easynld.e:773 global sequence sampleBrush,
easynld.e:782 global atom backBrush
easynld.e:784 global atom wwrapPen
easynld.e:786 global function reBrush(sequence cnew, sequence cold)
}}}
<eucode>
Then it is immediately obvious there is much more scope for trashing
something vital elsewhere and maybe you should rethink that code.
The routine interfaces can also be far harder, as you may be expected
to set a global variable correctly before calling (actually also true
of CtrlBracket above).

Ensuring that any global variables you need have well-thought-out
names that are unlikely to be accidentally re-used elsewhere is one
way of reducing the risks.

One half-baked idea I have is 'global-constant-local-variable's, ie
you can legally modify them within the source they are defined, but
get compiler errors if attempting to modify them anywhere else.
Not exactly sure how to specify that though, how does:
}}}
<eucode> 
global constant udt myTable, myList

(where udt could be integer, boolean, seq8 etc) sound? It would not be
legacy compatible though, currently the "global constant udt" part 
would define a new variable even if a valid [global] type udt exists, 
and any similar legacy code would cause a compile error when run on a
newer version of Eu. A more compatible idea is:
glocal udt myTable,myList

which gets my vote, but "glocal" is admittedly a bit odd. Of course
you can stick with the local var + global get()[/set()] method.

One last thing I will say is that forward routine references can cause
headaches enough, imo allowing forward references to [global]
constants and variables would really damage the elegance of the
language (and probably treble compile times). I assume you had an
"episode" which triggered this thread, care to share?

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

5. Re: Global = root of all evil

On Wed, 01 Nov 2006 20:38:35 -0800, ags <guest at RapidEuphoria.com>
wrote:

>}}}
<eucode>
>else
>    greet() -- default
></eucode>
{{{

IMO, you really don't want to do that. If there is more than one 
routine named "greet()", you must be specific. Having a 'default' 
version of greet() (presumably the one from the include w/o "as") 
which the compiler just assumes you mean if you forget a qualifier 
could be /really/ annoying. 

>
>... where you would be forced to use name space qualifiers.
was the above a typo then?

Regards,
Pete
PS eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,
obviously in real code that missing 'fr:' could be real hard to spot
and/or lead to a very subtle and very hard to reproduce bug.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Global = root of all evil

Pete Lomax wrote:
> 
> On Wed, 01 Nov 2006 20:38:35 -0800, ags <guest at RapidEuphoria.com>
> wrote:
> 
> >}}}
<eucode>
> >else
> >    greet() -- default
> ></eucode>
{{{

> IMO, you really don't want to do that. If there is more than one 
> routine named "greet()", you must be specific. Having a 'default' 
> version of greet() (presumably the one from the include w/o "as") 
> which the compiler just assumes you mean if you forget a qualifier 
> could be /really/ annoying. 

Yep, a hasty example, lacking proper documentation smile  The above greet() would
actually be in the source file, not the include file.

> PS eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,
> obviously in real code that missing 'fr:' could be real hard to spot
> and/or lead to a very subtle and very hard to reproduce bug.

I think the error message would be something like 'call to undefined function
y()', ie any routine without a namespace is assumed to be in the 'main' source
file, as you would expect.  I wrote something on the wiki a while ago suggesting
a 'without globals' that would not search for y() (without a qualifier) in any
include files, but that might get confusing.

Having said all that, I don't think I'd actually like to see these things
implemented in Euphoria smile  I think Euman's approach is probably better, just
get include/library/wrapper makers to stop making things global "because it's
easy".  It's akin to making every variable of type 'object'... keep data local
and use exported methods to inspect or modify it.

(goes off to look at own code ;)

Gary

new topic     » goto parent     » topic index » view message » categorize

7. Re: Global = root of all evil

Hi there,

I realized these kinds of problems long ago, that's why i came up
with WinClass.  You have to call global functions somehow, and using
a class sort of methodology seems to be a good idea, as many things
have common names yet have to be catagorized separately.
If anyone has a better idea i would sure like to hear it smile

Example:

You have two button objects, ButtonTypeA and ButtonTypeB.
There are some similarities between the two but many differences too,
which makes using a flag based system a little difficult, both for you
AND the person that is going to create these objects.  A good
solution seems to be:

  constant Button1=BTypeA:Create(params)
  constant Button2=BTypeB:Create(params)

The values for params are kept in the file with the code for that
button type and are documented carefully:

  Create(
    integer style, --style=1 for raised, 0 for recessed
    sequence name, --button text, name="MyButton" for example
    atom color     --face color, color=#808000 for example
    )

  Create(
    integer style,  --style=1 for raised, 0 for recessed
    sequence name,  --button text, name="MyButton" for example
    atom facecolor, --face color, color=#808000 for example
    atom textcolor  --textcolor=#FFFFFF for example
    )

As soon as the user looks at the file they have a very good idea
how to create that object.
Also, because of the coding format it makes it fast to add features
to an existing 'class'.  The underlying format is pretty much the
language itself, so there are less ideals to have to push on the
programmer...

  Create(
    integer style,  --style=1 for raised, 0 for recessed
    sequence name,  --button text, name="MyButton" for example
    atom facecolor, --face color, color=#808000 for example
    atom textcolor, --textcolor=#FFFFFF for example
    integer advancedstyle  --advancedstyle=PUSHON_PUSHOFF or PUSHBUTTON
    )

Once the ability to actually include an include file a second (or more)
time(s) gets into the language it will be even easier to create a class
and then create objects of that class...as you can now do with C++.





Take care,
Al

E boa sorte com sua programacao Euphoria!


My bumper sticker: "I brake for LED's"

 From "Black Knight":
"I can live with losing the good fight,
 but i can not live without fighting it".
"Well on second thought, maybe not."

new topic     » goto parent     » topic index » view message » categorize

8. Re: Global = root of all evil

Global use in Euphoria is necessary because the name-space implementation
is limited.

I would suggest that all of you users that have been demanding that
Euphoria become open source get to work and rewrite Euphoria's
name-spaces just the way that you have been harping at Rob to fix
it.

That does not mean to say to Rob this is how to do it but to come up
with code that works the way that you said it should.
   
Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

9. Re: Global = root of all evil

I've only written small programs, but I've never had a problem with globals.
Probably because I almost never use them. Good programming practice says, "Thou
shalt not pollute the Global Namespace unnecessarily."

I feel less strongly about pros and cons of globals than I do about, say, goto.

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
"Premature optimization is the root of all evil in programming."
--C.A.R. Hoare
j.

new topic     » goto parent     » topic index » view message » categorize

10. Re: Global = root of all evil

Daryl Border already oposted code in the Archive to have the inclde
system behave in a more functional way; it modifies only the front end,
so let's  start with this.
My own preference is for full modularity, with a client list for each
symbol that needs be visible outside its definition file, like in
Eiffel.


CChris

On Thu, 02 Nov 2006 08:30:21 -0800, EUforum at topica.com said:
> Subject: Re: Global = root of all evil
> 
> 
> posted by: Bernie Ryan <xotron at bluefrog.com>
> 
> 
> Global use in Euphoria is necessary because the name-space implementation
> is limited.
> 
> I would suggest that all of you users that have been demanding that
> Euphoria become open source get to work and rewrite Euphoria's
> name-spaces just the way that you have been harping at Rob to fix
> it.
> 
> That does not mean to say to Rob this is how to do it but to come up
> with code that works the way that you said it should.
>    
> Bernie
> 
> My files in archive:
> WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 
> 
> Can be downloaded here:
>
> http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
> 
> 
> ------------------------------

-- 
  
  cchris005 at fastmail.fm

-- 
http://www.fastmail.fm - Access your email from home and the web

new topic     » goto parent     » topic index » view message » categorize

11. Re: Global = root of all evil

> 
> 
> Hi all,
> 
> Global vars, funcs, procs, etc.. root of all evil??
> 
> more so in C but in Euphoria as well..
> 
> Any takers??
> 
> personally I'm making sure my habits of using global's
> extinct..for the most part..

A huge global in a pass-by-reference system will run faster and use 
less memory than passing it in function/procedure call. It's obvious 
in heavy recursion and database munging.

Kat

new topic     » goto parent     » topic index » view message » categorize

12. Re: Global = root of all evil

Al Getz wrote:
> 
> Hi there,
> 
> I realized these kinds of problems long ago, that's why i came up
> with WinClass.  You have to call global functions somehow, and using
> a class sort of methodology seems to be a good idea, as many things
> have common names yet have to be catagorized separately.
> If anyone has a better idea i would sure like to hear it smile
> 
> Example:
> 
> You have two button objects, ButtonTypeA and ButtonTypeB.
> There are some similarities between the two but many differences too,
> which makes using a flag based system a little difficult, both for you
> AND the person that is going to create these objects.  A good
> solution seems to be:
> 
>   constant Button1=BTypeA:Create(params)
>   constant Button2=BTypeB:Create(params)
> 
> The values for params are kept in the file with the code for that
> button type and are documented carefully:
> 
>   Create(
>     integer style, --style=1 for raised, 0 for recessed
>     sequence name, --button text, name="MyButton" for example
>     atom color     --face color, color=#808000 for example
>     )
> 
>   Create(
>     integer style,  --style=1 for raised, 0 for recessed
>     sequence name,  --button text, name="MyButton" for example
>     atom facecolor, --face color, color=#808000 for example
>     atom textcolor  --textcolor=#FFFFFF for example
>     )
> 
> As soon as the user looks at the file they have a very good idea
> how to create that object.
> Also, because of the coding format it makes it fast to add features
> to an existing 'class'.  The underlying format is pretty much the
> language itself, so there are less ideals to have to push on the
> programmer...
> 
>   Create(
>     integer style,  --style=1 for raised, 0 for recessed
>     sequence name,  --button text, name="MyButton" for example
>     atom facecolor, --face color, color=#808000 for example
>     atom textcolor, --textcolor=#FFFFFF for example
>     integer advancedstyle  --advancedstyle=PUSHON_PUSHOFF or PUSHBUTTON
>     )
> 
> Once the ability to actually include an include file a second (or more)
> time(s) gets into the language it will be even easier to create a class
> and then create objects of that class...as you can now do with C++.

All I have to say Al, is that this is Object Oriented Programming, and this is
what I love about Ruby, with it's ease of use for Specifications of Class
Objects.  You can have the same Function on 2 different classes, same exact name,
but does two entirely different things.  If something like this was to occur,
there would be no need to worry about polluting the Global Namespace, no need to
worry about "fixing" the namespace problem with Euphoria itself.

And as much as people here have been harping about the idea, that "Oh well, if
you incorperate Object Oriented Programming into Euphoria, then your going to
have to use it."  I only have one thing to say.  If I want to use Procedual type
programming in Ruby, it's perfectly legal to do so.  I don't have to use the
Object Oriented programming styles of Ruby, but I choose to do so, cause that
saves 100 times effort on creating libraries, with conflicting namespaces. 
Something, I'm sure Euphoria could benifit from.

Mario Steele
http://enchantedblade.trilake.net
Attaining World Dominiation, one byte at a time...

new topic     » goto parent     » topic index » view message » categorize

13. Re: Global = root of all evil

Kat wrote:
> 
> > 
> > Hi all,
> > 
> > Global vars, funcs, procs, etc.. root of all evil??
> > 
> > more so in C but in Euphoria as well..
> > 
> > Any takers??
> > 
> > personally I'm making sure my habits of using global's
> > extinct..for the most part..
> 
> A huge global in a pass-by-reference system will run faster and use 
> less memory than passing it in function/procedure call. It's obvious 
> in heavy recursion and database munging.

Actually, I'd think pass-by-reference might make it easier to get rid
of globals.  I've got pbr working with ooeu and the c-backend.  The 
following code shows a 3x improvement by using pass by reference:

procedure pbr( sequence * s )
	s[1] = 3
	s[2] = 2
	s[$] = 5
end procedure

atom t
sequence s
s = repeat( 0, 100000 )

t = time()
for i = 1 to 100 do
	s = repeat( 0, 100000 )
	s = no_pbr(s)	
end for

printf( 1, "\nNon-pass-by-reference large sequence benchmark time: %g\n", time()
- t)
s = repeat( 0, 100000 )
t = time()
for i = 1 to 100 do
	s = repeat( 0, 100000 )
	pbr(s)	
end for
printf( 1, "Pass-by-reference large sequence benchmark time:     %g\n", time() -
t)


Matt

new topic     » goto parent     » topic index » view message » categorize

14. Re: Global = root of all evil

On Thu, 02 Nov 2006 06:41:32 -0800, ags <guest at RapidEuphoria.com>
wrote:

>I think the error message would be something like 'call to undefined 
>function y()', ie any routine without a namespace is assumed to be in 
>the 'main' source file, as you would expect.
My apologies, I thought I was talking to someone who had a clue.
<cue flame war; trust me I'll dig my heels in to get my point across
and am unlikely to pull many punches...>

DUHH! we're talking about MULTIPLE y()! The WHOLE point was that it
should NOT */ASSUME/* a specific y(): How, in god's shit, does:
"eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,"
NOT make that clear? Did in any bizzarre sense you imagine there was
NO included fr:y() or something?

Did in any bizzarre sense you imagine that I felt it would be /RIGHT/
to /ASSUME/ the local y()?

I can tell this is going to be a serious challenge if I still have not
made this point crystal clear... Onwards, anyway:

>>presumably the one from the include w/o "as"
>The above greet() would be in the source file, not the include file.
Ugh, this is the horrid bit squared. While I am aware that this needs
some very careful thought, particularly allowing existing libs to work
as-is, I firmly believe that eg:
include win32lib.ew
function create()

/SHOULD/ trigger an error (because it is a redefinition of a direct
include). Otoh, two sub/third-party-"components" both defining eg
abs() should not be a problem (and each use "their own").

I'm not sure how many 'old hands' would agree with me.

btw, no disrespect intended, of the undue variety anyway,
Pete
PS I am want to be very aggressive on these points; don't bother
taking it /too/ personally, instead try make me look stupid using
logic blink.
PPS Also I would be quite keen to discuss this amicably, and would
try, but kind of accept it is not really my style blink I'll try tho.

new topic     » goto parent     » topic index » view message » categorize

15. Re: Global = root of all evil

Pete Lomax wrote:

> PS eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,
> obviously in real code that missing 'fr:' could be real hard to spot
> and/or lead to a very subtle and very hard to reproduce bug.

If we had the situation where every name collision had to be disambiguated using
namespace ids, and if one wanted to refer to a 'y()' routine that was local to
the current file, how would one indicate that? I mean, is it possible that the
current file can have a predefined namespace identifier ... ?

   fr:f( fr:x(), this:y(), fr:z() )


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

16. Re: Global = root of all evil

On Fri, 03 Nov 2006 18:15:55 -0800, Derek Parnell
<guest at RapidEuphoria.com> wrote:

>Pete Lomax wrote:
>
>> PS eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,
>> obviously in real code that missing 'fr:' could be real hard to spot
>> and/or lead to a very subtle and very hard to reproduce bug.
>
>If we had the situation where every name collision had to be 
>disambiguated using namespace ids, and if one wanted to refer to a 
>'y()' routine that was local to the current file, how would one 
>indicate that? I mean, is it possible that the current file can have a 
>predefined namespace identifier ... ?
>
>   fr:f( fr:x(), this:y(), fr:z() )

Easy, in main.e:
include main.e as this


Regards,
Pete
PS:Forcing errors on local y() adds compile overhead, in checking for 
global-namespace-qualified-clashes, but then again the purist in me 
believes you should NEVER use namespaces unless faced with an 
otherwise unavoidable third-party clash.

new topic     » goto parent     » topic index » view message » categorize

17. Re: Global = root of all evil

Pete Lomax wrote:
> 
> On Fri, 03 Nov 2006 18:15:55 -0800, Derek Parnell
> <guest at RapidEuphoria.com> wrote:
> 
> >Pete Lomax wrote:
> >
> >> PS eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,
> >> obviously in real code that missing 'fr:' could be real hard to spot
> >> and/or lead to a very subtle and very hard to reproduce bug.
> >
> >If we had the situation where every name collision had to be 
> >disambiguated using namespace ids, and if one wanted to refer to a 
> >'y()' routine that was local to the current file, how would one 
> >indicate that? I mean, is it possible that the current file can have a 
> >predefined namespace identifier ... ?
> >
> >   fr:f( fr:x(), this:y(), fr:z() )
> 
> Easy, in main.e:
> }}}
<eucode>
>  include main.e as this
> </eucode>
{{{


Just to clarify, are you saying that for code to ensure that references to
identifiers in its own file are unambiguous, that a file must include itself with
a namespace id and use that namespace in the references.

This sounds a bit redundant to me as one would always like references to local
indentifiers to be unambiguous and so then one must always use the self-include
technique. Would it not be more straight forward to have the rule that unadorned
references are indending to reference local identifiers and if the local
identifier clashes with an included global, the local has precedence. I suppose
you can have a new 'warning' that alerted to you to such occlusions.

> Regards,
> Pete
> PS:Forcing errors on local y() adds compile overhead, in checking for 
> global-namespace-qualified-clashes, but then again the purist in me 
> believes you should NEVER use namespaces unless faced with an 
> otherwise unavoidable third-party clash.

What are you thoughts regarding the idea of using namespaces to prevent
potential clashes?

And what about using them as a form of documentation for code readers?

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

18. Re: Global = root of all evil

> Subject: Re: Global = root of all evil
>
>
>
>
> On Thu, 02 Nov 2006 06:41:32 -0800, ags <guest at RapidEuphoria.com>
> wrote:
>
> >I think the error message would be something like 'call to undefined
> >function y()', ie any routine without a namespace is assumed to be in=

> >the 'main' source file, as you would expect.
> My apologies, I thought I was talking to someone who had a clue.
> <cue flame war; trust me I'll dig my heels in to get my point across
> and am unlikely to pull many punches...>
>
> DUHH! we're talking about MULTIPLE y()! The WHOLE point was that it
> should NOT */ASSUME/* a specific y(): How, in god's shit, does:
> "eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,"
> NOT make that clear? Did in any bizzarre sense you imagine there was
> NO included fr:y() or something?
>
> Did in any bizzarre sense you imagine that I felt it would be /RIGHT/
> to /ASSUME/ the local y()?
>

Obviously it is right.
When you call a global from your own code, you may or may not expect it
to be redefined. Eu should allow you, the coder, to decide. I'd advocate
the following extra keyzords
1/ generic: this would replace "global" zhen the coder allows
redefinition of the symbol he created.
2/ restricted: this symbol is not to be seen outside the current file
and the files it includes;
3/ undefine: this is a request for the given outside symbol not to get
in the way inside the current filem and any zhich would include it.

At any rate, if the intention of the coder is obvious, he must be able
to state it in a way obvious to readers of the code, /without
restricting/ much what he's able to code. The latter is perhaps why Eu
is so little known after 13 years of being around.

</snip>

> I firmly believe that eg:
> }}}
<eucode>
> include win32lib.ew
> function create()
> </eucode>
{{{

> /SHOULD/ trigger an error (because it is a redefinition of a direct
> include). Otoh, two sub/third-party-"components" both defining eg
> abs() should not be a problem (and each use "their own").
>

One should be able to define any local symbol without getting any error,
except when redefining inside the same file. And yet, using namespace
blocks (your idea a while ago_ should allow to override this. So, I'd
say a flat no to any error here. Optionally a zrning, asuming it could
be of any use.

CChris
--
=20=20
  cchris005 at fastmail.fm

--
http://www.fastmail.fm - Same, same, but different=85

new topic     » goto parent     » topic index » view message » categorize

19. Re: Global = root of all evil

On Sat, 04 Nov 2006 08:49:53 -0800, chris cuvier
<cchris005 at fastmail.fm> wrote:

>> Did in any bizzarre sense you imagine that I felt it would be /RIGHT/
>> to /ASSUME/ the local y()?
Ooops.
>
>Obviously it is right.
Er..
>When you call a global from your own code, you may or may not expect it
>to be redefined.
Now you lost me. Did you mean local?
> Eu should allow you, the coder, to decide.
Well, yes, the point was more to /force/ you to be specific.
>I'd advocate the following extra keyzords
>1/ generic: this would replace "global" zhen the coder allows
>redefinition of the symbol he created.
No idea what you mean by that. Example please.
>2/ restricted: this symbol is not to be seen outside the current file
>and the files it includes;
I think Java uses "package". I agree this scope would add value.
>3/ undefine: this is a request for the given outside symbol not to get
>in the way inside the current filem and any zhich would include it.
Ugh/Erm, why is this needed if 2/ exists?

>One should be able to define any local symbol without getting any error,
Yep, I'm about to fold to DP on that devils advocate thing...

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

20. Re: Global = root of all evil

On Sat, 04 Nov 2006 05:27:32 -0800, Derek Parnell
<guest at RapidEuphoria.com> wrote:

>> >Pete Lomax wrote:
>> >> PS eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,
>> >   fr:f( fr:x(), this:y(), fr:z() )

>Just to clarify, are you saying that for code to ensure that 
>references to identifiers in its own file are unambiguous, that a file 
>must include itself with a namespace id and use that namespace in the 
>references. 
Correct, if there is a clash.
This is/was an "aggressive" response to "Global = root of all evil".

<snip>
>one would always like local indentifiers to be unambiguous
<snip>
Agreed. It dawns on me that playing devils advocate just failed blink
Where I really fell down on this thread is the argument that "globals
are the root of all evil" vs "too painful to enforce them properly".
I'll back down now, if that's ok, in truth I'm fairly happy with the
way things are.

I guess I was trying to say something along the lines of "you can't
really fix these things", but the moment's passed.

>What are you thoughts regarding the idea of using namespaces to prevent
>potential clashes?
>
>And what about using them as a form of documentation for code readers?
Yep, you win, sound uses both! blink)

Regards,
Pete

PS: I believe I owe an apology here, particularly to ags. It was a
complete over-reaction, no offense meant. Sorry if any taken.

new topic     » goto parent     » topic index » view message » categorize

21. Re: Global = root of all evil

> Subject: Re: Global = root of all evil
> 
> 
> On Sat, 04 Nov 2006 08:49:53 -0800, chris cuvier
> <cchris005 at fastmail.fm> wrote:
> 
> >> Did in any bizzarre sense you imagine that I felt it would be /RIGHT/
> >> to /ASSUME/ the local y()?
> Ooops.
> >
> >Obviously it is right.
> Er..
> >When you call a global from your own code, you may or may not expect it
> >to be redefined.
> Now you lost me. Did you mean local?

No. Local symbols have meaning in their definition file only, hence can
override anything anywhere. The actual problems - which have made me
shun coding in Eu these days - are with globals.

> > Eu should allow you, the coder, to decide.
> Well, yes, the point was more to /force/ you to be specific.
> >I'd advocate the following extra keyzords
> >1/ generic: this would replace "global" zhen the coder allows
> >redefinition of the symbol he created.
> No idea what you mean by that. Example please.

In my ESL complex.e mpdule (guess what it is about...), I use new format
modifiers to print complex numbers, and need to extend sprint() as a
result. Obviously, it is more convenient for the user to be able to keep
using sprint() for the usual purpose, with a couple more format
modifiers. sprint() is declared as global in misc.e and can't be
redefined. It could if it was declared as generic, and that keyword
would inform that the routine may be redefined as an everywhere visible
symbol. Clearer?


> >2/ restricted: this symbol is not to be seen outside the current file
> >and the files it includes;
> I think Java uses "package". I agree this scope would add value.
> >3/ undefine: this is a request for the given outside symbol not to get
> >in the way inside the current filem and any zhich would include it.
> Ugh/Erm, why is this needed if 2/ exists?
> 

To run code that was written using global symbols only, without having
to modify that code, which may prove tricky (think of EuGTK).

> >One should be able to define any local symbol without getting any error,
> Yep, I'm about to fold to DP on that devils advocate thing...
> 
> Regards,
> Pete
> 

CChris

-- 
  
  cchris005 at fastmail.fm

-- 
http://www.fastmail.fm - One of many happy users:
  http://www.fastmail.fm/docs/quotes.html

new topic     » goto parent     » topic index » view message » categorize

22. Re: Global = root of all evil

Eu needs 2 things ot deal with global contamination.
1. more robust namespacing capabilties.
2. more robust include namespacing.

Both of these issues have been beaten to death.
IMO the best solution for namespacing is to allow arbitrary, top-level code
blocks to be namespaced. This still creates global contamination via the
namespaces themselves though. The namespaces can have their own pool however
which would reduce that greatly. If they have their own pool, then we also have a
potential problem of contamination of the qualifier pool.

We can further reduce global contamination by enhancing the include system.
My preference would be to break existing behaviour and add the ability to
declare includes as global. To access a global in an include file one would then
have to include the file as global. If the file A were nested in another include
file B, then file A would have to be globall included in file B and file B would
have to be globally included in the current file.
This is called chaining and would alleviate a huge majority of all global
conflicts on it's own.
The same thing could be achieved without breaking compatability by introducing a
new keyword. But I don't think it's as elegant.

An additional way to reduce contamination would be to allow locals (including
local namespaces) to be accessed globally by qualifying them.


Chris Bensler
~ The difference between ordinary and extraordinary is that little extra ~
http://empire.iwireweb.com - Empire for Euphoria

new topic     » goto parent     » topic index » view message » categorize

23. Re: Global = root of all evil

Pete Lomax wrote:

Hi Pete

I haven't checked this list for a few days, so that's the reason for no
response, not the the, er, 'style' of your message.

> >I think the error message would be something like 'call to undefined 
> >function y()', ie any routine without a namespace is assumed to be in 
> >the 'main' source file, as you would expect.
> My apologies, I thought I was talking to someone who had a clue.
> <cue flame war; trust me I'll dig my heels in to get my point across
> and am unlikely to pull many punches...>
> 
> DUHH! we're talking about MULTIPLE y()! The WHOLE point was that it
> should NOT */ASSUME/* a specific y(): How, in god's shit, does:
> "eg fr:f(fr:x(),y(),fr:z())  should flag the y() missing namespace,"
> NOT make that clear? Did in any bizzarre sense you imagine there was
> NO included fr:y() or something?

I don't think either of us have a clue on this subject as we're discussing
something purely theoretical, at least I was.

fr:f(fr:x(),y(),fr:z())  

says to me:

From the package known as "fr" (included with a qualifier), call the function
 'f(,,,)' with the parameters:

1, the function x() in package 'fr'
2, the function y() ...
3, the function z() in package 'fr'

Currently Euphoria will call fr:y() if it exists only in francais.e, and it will
SILENTLY call y() if it is defined in the main source file.  If it is defined in
other include files you get the error.

> 
> Did in any bizzarre sense you imagine that I felt it would be /RIGHT/
> to /ASSUME/ the local y()?
> I can tell this is going to be a serious challenge if I still have not
> made this point crystal clear... Onwards, anyway:

I think it is right to assume the local y(), but it should generate a warning. 
Better still, include files should be like Perl OO style packages and it would be
mandatory to use namespaces, as long as they could be intelligently organised...
like Perl.  That was my original point.

But hey, I can always go an use Perl if I feel like doing that sort of thing.

So I think we already agree, more or less?  I probably didn't read your message
properly before, or it was too many days in between and I've lost the plot.

> 
> >>presumably the one from the include w/o "as"
> >The above greet() would be in the source file, not the include file.
> Ugh, this is the horrid bit squared. While I am aware that this needs
> some very careful thought, particularly allowing existing libs to work
> as-is, I firmly believe that eg:
> }}}
<eucode>
> include win32lib.ew
> function create()
> </eucode>
{{{

> /SHOULD/ trigger an error (because it is a redefinition of a direct
> include). Otoh, two sub/third-party-"components" both defining eg
> abs() should not be a problem (and each use "their own").
> 
> I'm not sure how many 'old hands' would agree with me.

Ugh.  So you'd selectively generate an error based on the depth of the function
in question, or it's name??

> btw, no disrespect intended, of the undue variety anyway,
> Pete
> PS I am want to be very aggressive on these points; don't bother
> taking it /too/ personally, instead try make me look stupid using
> logic blink.
> PPS Also I would be quite keen to discuss this amicably, and would
> try, but kind of accept it is not really my style blink I'll try tho.

Hey it's up to you.  Very entertaining message :)  In the end I think it helps
to discuss this kind of thing, factual things, unemotionally--friendly or
otherwise.  You live in your dream and I live in mine; I never take anything
personally.

Please feel free to totally trash anything I say, but I'll get your point of
view a whole lot better without the extra 'window dressings'.

Gary

new topic     » goto parent     » topic index » view message » categorize

24. Re: Global = root of all evil

Derek Parnell wrote:
> If we had the situation where every name collision had to be disambiguated
> using
> namespace ids, and if one wanted to refer to a 'y()' routine that was local
> to the current file, how would one indicate that? I mean, is it possible that
> the current file can have a predefined namespace identifier ... ?
> 
>    fr:f( fr:x(), this:y(), fr:z() )

I think in Perl you can use main::y(), but there's no need because if it isn't
qualified then it's assumed to be in "main".

Gary

new topic     » goto parent     » topic index » view message » categorize

25. Re: Global = root of all evil

Pete Lomax wrote:
> 
> PS: I believe I owe an apology here, particularly to ags. It was a
> complete over-reaction, no offense meant. Sorry if any taken.

Apology accepted, none taken.  You're lucky I know the ways of the ancient
Toltec. ;)

Gary

new topic     » goto parent     » topic index » view message » categorize

26. Re: Global = root of all evil

ags wrote:
> 
> Derek Parnell wrote:
> > If we had the situation where every name collision had to be disambiguated
> > using
> > namespace ids, and if one wanted to refer to a 'y()' routine that was local
> > to the current file, how would one indicate that? I mean, is it possible
> > that
> > the current file can have a predefined namespace identifier ... ?
> > 
> >    fr:f( fr:x(), this:y(), fr:z() )
> 
> I think in Perl you can use main::y(), but there's no need because if it isn't
> qualified then it's assumed to be in "main".

"I meant to add" ...

In Perl you can export a routine or variable, so that it is seen in 'main', but
that too is considered to be contamination to be used sparingly.

I know I go on about Perl, but I really do like it's 'include' system.  It has
version control, object orientation, is based on directory structure, etc etc,
but it can still be used as a basic system like Euphoria's.

The only problem with it is that it's as unfriendly to use as some of Perl
itself.

Gary

new topic     » goto parent     » topic index » view message » categorize

27. Re: Global = root of all evil

On Mon, 06 Nov 2006 13:48:48 -0800, ags <guest at RapidEuphoria.com>
wrote:

>Apology accepted, none taken.  You're lucky I know the ways of the ancient
>Toltec. ;)

Ho hum, if it weren't for the likes of me, you'd not appreciate normal

blink

Pete

new topic     » goto parent     » topic index » view message » categorize

28. Re: Global = root of all evil

Pete Lomax wrote:
> 
> Ho hum, if it weren't for the likes of me, you'd not appreciate normal
> 
> blink

Hey, too true. :)

Did we actually decide anything in the whole "global = evil" thing??

Gary

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu