Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Linda Walsh Newsgroups: gnu.bash.bug Subject: Re: language inconsistency(wart) & RFE Date: Sat, 17 Oct 2015 08:55:31 -0700 Lines: 58 Approved: bug-bash@gnu.org Message-ID: References: <5621A1DD.90205@tlinx.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1445097346 21084 208.118.235.17 (17 Oct 2015 15:55:46 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: isabella parakiss Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11682 isabella parakiss wrote: > Maybe you can just use this? alias declare='declare -g' ---- If I needed a way to declare something global, yes... But what I am wanting is a way to allow changing the defaults of the implicit variable creation (which could still be explicitly declared with "-g" if one wanted their result to be made global. For example, I use some aliases in documenting the intended usage of vars... especially with respect to integers, arrays and hashes. Declaring a hash by calling it a 'hash' is somewhat generic, but if I call it a 'map', it is more clear from a documentation standpoint that I am trying to use something as a way to map names to a value. So I will tend to pre-declare many of my vars, but some are just an annoyance to predeclare. Like readarray -t config <~/.toolrc -- read a config file into an array, and then parse it for relevant options && then throw the "config array" out when done parsing it. Having to "declare" a temporary, _first_, before usage is a bit backwards... Obvious example is using throw-away names as index or iterator vars. I believe it to be rare, that people use "for nam in "${names[@]}"; or "for ((i=0;i<10;++i));" as a means to declare nam or 'i' as "global variables. They are too meaningless for use as a global, and much more likely to collide with usage of such 'tmp' names in other functions that may be called in a nested fashion. Allowing the option to default to private state, would take care of accident collisions where one loop uses 'i', but calls some util function elsewhere that also uses 'i' and ending up with strange side-effects. It removes default behavior to suppress accidental "spooky actions at a distance", where one or both functions didn't pre-declare 'i' in a func. It seems to me, that pre-declaring a variable draws attention to it -- which is more wanted if it is a global, but drawing attention to 'i' in a forloop by pre-declaring it makes the code more confusing, as you are drawing attention to a temporary who's value you usually won't care about after the function has exit'ed. Allowing an option to change this default, allows for more portable, more reliable and less confusing code to be written, which would seem like a desirable goal.