Sign in to follow this  
Followers 0
jchd

Usefulness of new feature: STATIC (local) variables decl

37 posts in this topic

Hi all,

The topic title and description almost say it all.

This is certainly a low priority thing but I'd like to have your opinions.

Do you think that the posibility to declare STATIC variables inside functions would be a useful feature?

The intended semantic would be of course that a (local) variable declared by the STATIC declarator inside a function retains the last assigned value accross this function invokations.

Just like GLOBAL, LOCAL or DIM, STATIC would accept the same syntax, including optional initialization.

I believe it could help those who find it uneasy to have tons of global scope variables clobber their programs. It would also favor better program designs by holding many variables where they belong: with the code that manipulates them.

Since re-entrancy or multi-threading are absolutely out of question, I think there are many situations which could benefit of such simple but effective feature.

As an AutoIt user, would you make use of STATIC variables?

As an AutoIt developper, would it be difficult to implement?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites



Static variables would revolutionize the UDF systems. It probably requires a major change though...

Share this post


Link to post
Share on other sites

I've thought about static variables before. I'm on the fence. One the one hand, they would be awesome. I love me some static variables because of just-in-time one-time instantiation. But I'm not sure if adding them falls into the trap of adding things for the sake of adding things. How many AutoIt users actually know what static variables are and know when and how to use them? I see static variables as more of a programmer's convenience than a scripter's feature. What I mean is, those of us who have backgrounds in other languages are sure to use them but is the average user going to take the time to learn them?

Also, static variables wouldn't affect concurrency one way or the other. Static variables would behave how global variables behave (they are a form of global variable, after all).

Share this post


Link to post
Share on other sites

How many AutoIt users actually know what static variables are and know when and how to use them? I see static variables as more of a programmer's convenience than a scripter's feature. What I mean is, those of us who have backgrounds in other languages are sure to use them but is the average user going to take the time to learn them?

Not that many I presume. However I think many people would learn them if they were to be used my a number of devs. If we take DllCall as an example. The feature uses functionality you wouldn't expect a scripter to understand and use well without C knowledge. However since people who do have C experience do some amazing things with DllCall's they look into the subject and learn it anyways. So in other words, people learn what their tools offer.

Also, static variables wouldn't affect concurrency one way or the other. Static variables would behave how global variables behave (they are a form of global variable, after all).

Eh? They wouldn't reside in the local scope? Because tha's what I thought was the great idea behind this, giving us a tool to actually clean up our much too often cluttered global scope.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Eh? They wouldn't reside in the local scope? Because tha's what I thought was the great idea behind this, giving us a tool to actually clean up our much too often cluttered global scope.

It is, kinda saying it's global is not right. Think it as a Global variable that will only be global only in the function. Other function can't access it. So it acts as a global variable but other can't access it. And yes it will clean up the UDF.

But I don't see real use in this(not that much), think of it. Most UDF is in another file even they declare Global. Users won't see it. And the chance of having the same variable name is nothing to non.

But having will clean up those Global nest.

Share this post


Link to post
Share on other sites

It is, kinda saying it's global is not right. Think it as a Global variable that will only be global only in the function. Other function can't access it. So it acts as a global variable but other can't access it. And yes it will clean up the UDF.

I'm perfectly aware of what a static variable is. I was just wondering what Valik meant by "they will behave like global variables behave".


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Like Valik, I also see static variables as more of a programmer's convenience than a scripter's feature. You can accomplish the same by using a rigid naming system, this is also why namespaces were rejected.

Share this post


Link to post
Share on other sites

Valik and others:

You're all evenly right. Given the painful understanding that many new or occasional users demonstrate, it can be seen as a pedantic addition. I don't mean those users are dumbass: most lack basic computer/language knowledge and minimal practice. We all see too many "I'm lost with my array/loop/regexp/..." on the forum.

Once again, there is no pejorative wording in the above (not that I mean, I ain't a native english speaker). People just don't know what this is about and don't know how to get started. That's a side effect of having PCs along coke cans in supermarkets: both good and evil.

I was well aware of the various facets of this topic when I posted it.

I still believe that, in the long run, it will be one among many necessary evolutions of a language like AutoIt. To see that, just compare 1985 Basica programs and todays' VBA written by more or less comparably "unskilled" persons (non power users). Laymen also evolve in their grasp of what's current: they learned to get rid of GOTOs, they are learning to use structured control statements and byrefs. They will learn the "magic" of statics too.

Most of you know how STATICs can help (or even sometimes force) to write better, clearer and easier to maintain programs. I also suspect that the average AutoIt script is getting more and more complex with the years passing by. I don't have enough knowledge of AutoIt history to have a definitive opinion but I strongly suspect that the more powerful the language becomes (with its cohorte of clean UDFs around) the more complex applications are using it in the real world. From this point of view, the said addition would certainly be beneficial, after the concept and properties get somehow widespread.

That was the purpose of this thread to gather enlighting opinions so that, eventually, the development staff could make the best decision about the opportunity of statics.

Again, this is a low-priority topic and, yes, I know that AutoIt is no democracy ;-)


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

monoceres, I'm sorry for not being clear. I was referring to internal storage of static variables would be like global variables. Both are persistent storage. However, the name resolution for static variables is still local. Do not fear, static variables in AutoIt would behave like the C/C++ static variables you are used to except perhaps they would not have internal linkage to a particular translation unit due to the architecture of AutoIt making it exceptionally hard to pull off (I'm referring to the fact #include inserts files inline rather than treating them as separate translation units).

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

I have been thinking of what would be involved in adding the static functionality to the interpreter. It seems pretty straight-forward; one new keyword "STATIC", no new variable stores (store everything in the Global store using special names with references in the Local stack frames), a little adjustment to the way variable lookup are done. Just hope nobody has created a UDF named Static. :D

I will post my thoughts for the details in the private developer forum.

I have a few oddly named global variables that are doing the job of a static variable in some of the scripts I have written. I could definitely use this feature.

Edited by Nutster
Add more detail and clarity (I hope)

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

David's idea is pretty simple although I disagree slightly with a couple implementation points. I don't think they are a big deal either way. As long as he's willing to write it I have no problem with it being added to AutoIt.

Share this post


Link to post
Share on other sites

I must comment and say that I 100% agree with what monoceres said. I am one of the autoit users with very little background experience in programming. I took one introduction to visual basic class my first year of college (2001), and I didn’t even do that good in it. I never really learned what dll files where and how they are used. What COM is and how that’s used.. The latest code that I have started to learn is assembly, thanks to monoceres and trancxx for there examples.

My list could go on for a while about things that I learned just because Autoit implemented it, or because I saw a great example on the forum giving me the concepts. So please don’t let some of the idiot users discourage you from implementing new ideas. There are a lot of us users on this forum with great potential and willingness to learn new things.

Share this post


Link to post
Share on other sites

I am in the middle of writing the implementation. I just didn't find any time this weekend. I have a big project out of the way, so I should have a little more time to look at this during the week after work.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

I am in the middle of writing the implementation. I just didn't find any time this weekend. I have a big project out of the way, so I should have a little more time to look at this during the week after work.

Sounds awesome! This is going to add some more fun to learning AutoIt >.<

Share this post


Link to post
Share on other sites

Sounds awesome! This is going to add some more fun to learning AutoIt >.<

I can see some headaches too.

I used Static to create a variable, but it won't change the value. Something's wrong with AutoIt! :D :D

Global $I

For $I = 1 to 10
    Static $K = $I * 2
    Msgbox(64, "My REALLY important project", $K)
Next

:D:mad2::D:ILA2::)

To which RTFM just does not do justice. :D

Well at least I am done the first draft of the docs, which will show that Static ignores its initializer on subsequent passes, so that is why you keep seeing 2.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

I can see some headaches too.

To which RTFM just does not do justice. :D

Well at least I am done the first draft of the docs, which will show that Static ignores its initializer on subsequent passes, so that is why you keep seeing 2.

AHA so true!

Wow, will this be released for the next beta then?

Share this post


Link to post
Share on other sites

It will be done when it is done. Remember we all volunteers here. I hope to finish by the end of next weekend, so it should make it in.


David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Share this post


Link to post
Share on other sites

It will be done when it is done. Remember we all volunteers here. I hope to finish by the end of next weekend, so it should make it in.

Yeah I understand.

I can see this making things a lot easier you know :D

Share this post


Link to post
Share on other sites

I'm going to say yes, unless David just completely stops working on it, it will be in the next beta. A better question is, when will the next beta be? When it's done AKA when I say "Jon, release this bitch" because I'm still not at all happy with the current state of AutoIt and have much work to do to get it into shape.

Share this post


Link to post
Share on other sites

As a noobe to autoit, I think this would be great. In Addition, Autoit is FANTASTIC, The developers have done a great job. I look forward to every release.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0