Re: Variables and Procedures scope
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.tcl archive

Re: Variables and Procedures scope

From: Robert Heller <heller@deepsoft.com>
Date: Sun Jul 31 2005 - 17:19:48 CEST

  "Silas Justiniano" <silasju@gmail.com>,
  In a message on 31 Jul 2005 08:00:25 -0700, wrote :

"J> Hi all! In this topic, I'm planning to talk about Variables and
"J> Procedure scope in Tcl/Tk. I see Tcl/Tk is a wonderful tool, one of the
"J> best tools I tried.
"J>
"J> (first, apologies for my bad English...)
"J>
"J> Well... Tcl/Tk is very good, but I don't like so much scope scheme.
"J> There is just to kinds of variables: extremaly locals and extremaly
"J> globals, not something between them. With GUI applications, I need to
"J> conect widgets to some variables, as:
"J>
"J> proc callMyToplevel {} {
"J> toplevel .mytop
"J> entry .mytop.myentry -variable myvar
"J> }
"J>
"J> myvar is local, but suppose I have to use it in another procedure... I
"J> have to make it global:
"J>
"J> entry .mytop.myentry -variable ::myvar
"J>
"J> or put the variable in some namespace (I prefer this):
"J>
"J> entry .mytop.myentry -variable globals::myvar
"J>
"J> There are procedures are valid just for some toplevel, but procedures
"J> are always globals in Tcl, so write a proc inside another proc is
"J> unnecessary. My idea of a ideal language is something like that:
"J>
"J> (I invented some syntax now)
"J>
"J> function f1 (args...) {
"J> var v2 #valid to all scopes below
"J>
"J> function f2 { #this functions is not valid out f1
"J> var v2 #valid to all scopes below, but not for f1 and outside that
"J> }
"J> }
"J>

This is effectively similar to a namespace.

"J> I don't know anything about Tcl history, but I think scope scheme in a
"J> GUI application would be better with my way. There are a lot of
"J> procedures and variables that are valid just inside some procedures,
"J> but I HAVE to make it all global, because it's the only way to use it
"J> in another place.
"J>
"J> I think it makes big programs development with Tcl, and another
"J> languages that have the same scope form difficult, to develop.
"J> Polluting the code with a lot of global variables, global procedures.
"J> And, the worst thing for me: Taking a lot of RAM.

The amount of RAM used is the same no matter what the variable scoping is.

"J>
"J> (big program use a lot of variables)
"J>
"J> What do you think?

Have you looked at Tix?

"J>
"J> See ya! Bye!
"J>
"J>

                                     \/
Robert Heller ||InterNet: heller@cs.umass.edu
http://vis-www.cs.umass.edu/~heller || heller@deepsoft.com
http://www.deepsoft.com /\FidoNet: 1:321/153

                                                
Received on Thu Sep 29 14:28:07 2005