Jump to content

Should Au3Check Count Global Variables Declared Inside Functions?


TheDcoder
 Share

Recommended Posts

20 minutes ago, iamtheky said:

Booo, I was hoping you would have a decent defense for declaring global within functions.  

I don't really have any defence ready for that :blink:. I just follow the herd... of sheep :P

21 minutes ago, iamtheky said:

Concessions when I am trying to be provocative make me look even more like a d**k than I already am.

Happens :>

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Close call this one, bug or not.

I'd lean toward bug in au3check, if the info in this thread is true, then au3check parses and checks the code from top to bottom, but autoit3 does not interpret the code that way. 

As I recall, autoit3 parses the functions first no matter where they are, so for me, as a checker of code, au3check should follow the same pattern, so bug from me.

Good code or standard sense should render moot, this issue of course, and the fact it is only a warning brings credence.

And as an aside, it makes me sad when people are offended when their work is commented on, good or bad, especially if in such an innocuous manner.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Developers

AutoIt3 initially parses the code and will give any syntax errors, but doesn't do more than that. It gives errors during execution when encountered.

Au3Check will parse the code and do more interpretation during a single pass, hence is able to give more warnings and error notification upfront, but obviously doesn't do execution, so can't report on any of those type of errors.

Either way, when somebody has a brilliant idea and skills to update au3check then let us know.

Jos  

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

2 hours ago, Jos said:

Either way, when somebody has a brilliant idea and skills to update au3check then let us know.

Is Au3Check's source code available?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

16 minutes ago, Jos said:

No, It is not generally available.

I see... so you are looking for people who would like to start fresh? or will you be providing the source to the interested candidates? I personally wanted to have a look at it :D.

On a side note: Au3Check is made with AutoIt, am I right? or is it all C++? I am not good at C++ at all

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • Developers
10 hours ago, TheDcoder said:

On a side note: Au3Check is made with AutoIt, am I right? or is it all C++? I am not good at C++ at all

Nope, a simple search gave me this one that sort of tells you the story:

Jos :-)

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Only aliens with 350+ years of contributing here have this kind of clearance, meaning you're not yet there :lol:

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)

Link to comment
Share on other sites

  • Developers

Ah ...  that's right ...  this is only readable for the old farts that are here long enough. Sorry about that.

This is what I wrote in that thread over 3 years ago: 

Quote

Well, it is pretty clear what needs to be changed here: :unsure:

declarator
    : VARIABLE          { m_varDefList.push_back(insertVar(m_varSpecScope, $1, Au3Ident::V_DECLARE)); }
    | VARIABLE '=' expression   { m_varDefList.push_back(insertVar(m_varSpecScope, $1, Au3Ident::V_DECLARE | ($3.eType==E_FUNC ? Au3Ident::V_MARKUSED : 0))); }
    | VARIABLE array_init       { m_varDefList.push_back(insertVar(m_varSpecScope, $1, ($2==E_FUNC ? Au3Ident::V_MARKUSED : 0))); } // DIM is not only declaration
    ;

array_init
    : '=' '[' array_init1 ']'
    | '=' '[' array_init2 ']'
    | '=' '[' array_init3 ']'
    | '=' '[' array_init4 ']'
    | subscript_list_init { if ($1.nEmptyDecl == 0) yyerror("array initializer badly formatted."); }
    | subscript_list_init '=' '[' array_init1 ']'   { if ($1.nSubscripts != 1) yyerror("wrong nesting in initializer."); }
    | subscript_list_init '=' '[' array_init2 ']'   { if ($1.nSubscripts != 2) yyerror("wrong nesting in initializer."); }
    | subscript_list_init '=' '[' array_init3 ']'   { if ($1.nSubscripts != 3) yyerror("wrong nesting in initializer."); }
    | subscript_list_init '=' '[' array_init4 ']'   { if ($1.nSubscripts != 4) yyerror("wrong nesting in initializer."); }
    ;
array_init1
    : { $$ = E_EXP; }
    | expression                {$$ = ($1.eType==E_FUNC) ? E_FUNC : E_EXP; }
    | array_init1 ',' expression        { $$ = ($1==E_FUNC || $3.eType==E_FUNC) ? E_FUNC : E_EXP; }
    ;
array_init2
    : '[' array_init1 ']'           { $$ = $2; }
    | array_init2 ',' '[' array_init1 ']'   { $$ = ($1==E_FUNC || $4==E_FUNC) ? E_FUNC : E_EXP; }
    ;
array_init3
    : '[' array_init2 ']'           { $$ = $2; }
    | array_init3 ',' '[' array_init2 ']'   { $$ = ($1==E_FUNC || $4==E_FUNC) ? E_FUNC : E_EXP; }
    ;
array_init4
    : '[' array_init3 ']'           { $$ = $2; }
    | array_init4 ',' '[' array_init3 ']'   { $$ = ($1==E_FUNC || $4==E_FUNC) ? E_FUNC : E_EXP; }
    ;

Need some sleep first...

Jos

It was about an issue with au3check and my brains have a high resistance level against opening that source code. :)

 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I am finding an issue with the mindset of both requiring the user to offer changes and restricting access to that which needs changed.  Its an odd blend of putting out fliers to 'weed and edge my lawn if you have the skills' and subsequently yelling 'get off my lawn'.  I understand why but generally pull requests are mocked after the fact.

Not that I have will or want as I turn that noise off after the first time F5 works.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

If I were the author of such a program, I would not bother to make any changes, even if I'd accept it as a bug it is not broken.

I'd probably only address it if I were fixing or adding other features.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Developers

It is actually a pretty structured way of coding but it requires a totally different way of thinking.
Some reading food in case one is interested: http://dinosaur.compilertools.net/yacc/

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

As a sidenote, for those seriously interessed, I have the "dragon" book "Compilateurs : Principes, techniques et outils" by Alfred Aho, Ravi Sethi & Jeffrey Ullman (in French) for sale, ISBN 2 7296 0295 X, mint condition.

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)

Link to comment
Share on other sites

15 hours ago, Jos said:

It was about an issue with au3check and my brains have a high resistance level against opening that source code. :)

I... I don't even understand the sample code in that quote O_o

38 minutes ago, jchd said:

As a sidenote, for those seriously interessed, I have the "dragon" book "Compilateurs : Principes, techniques et outils" by Alfred Aho, Ravi Sethi & Jeffrey Ullman (in French) for sale, ISBN 2 7296 0295 X, mint condition.

 

How much $$$?

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Or you could always look at the situation as not encouraging bad coding, so not a bug in my eyes ... it returns the correct result ... a reminder.

Unless you can explain why a user should be encouraged (or needs) to declare Globals in a function ... rather than at the start of their script?

Aside from where necessary in an Include file ... which the user has no control over ... without meddling.
(obviously I am not referring to user or non standard AutoIt included UDF's, which can be modified at will)

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Every time I thought I needed a better understanding of au3check, I really needed a better understanding AutoIt.

It's still an odd dynamic, I would almost call it territorial if I didn't already know it was crotchety senior citizens :)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

@TheDcoder,

You would be happier with an edition in english, which you can buy used and delivered to India for really cheap. For instance: https://www.abebooks.com/book-search/isbn/0201100886/used/

The very first 1977 edition (the [english only] "Green dragon") is significantly outdated, but the next 198x edition ("Red dragon", like mine) is still very valuable for starters albeit I suspect the text in French of my "Red dragon" will be much harder for you to digest.

The last edition "Purple dragon" goes deeper and brings advanced techniques to the scene, but it's a much harder reading for starters and the price is at least 10-fold.

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)

Link to comment
Share on other sites

Thanks for the suggestion @jchd, I have added Red Dragon to my wishlist... I will try reading it one day when I become a C programmer with a beard :P.
I do not want to mess my brain up by reading about compilers, interpreters alone are complex enough for me :blink:

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • 4 months later...

I read the comments here .. I see that everyone claims there is no reason why declaring a global variable within a function.

I want to say something about it.
 

There is, indeed, a use-case that doing just this ("poor coding" ) is giving you advantage.


The use-case is when you have group of variables that storing some big data (such as big strings, arrays, images and anything that take more RAM), and these variables can grow (take more RAM) over time.
And In certain situations  you want to clean the memory that these variables using.
So you need a function like VariablesOfSomething_FreeRAM() and this function will free the RAM and reset
these variables.

Here is the point -

If you declare them outside of function, your only option is to type each variable twice! - at the top of the script and inside VariablesOfSomething_FreeRAM()
And be careful with this!  If you have many of these variables, don't forget any of them. typing the same thing twice is a dor for potential human error..  You should know that .. that's why there is such a thing "Function" - avoid typing the same code more then once (so no this kind of human error).

In this use-case, a better option  is doing this "poor coding" / "bad practice" - declaring these variables as globals inside the function. I will not call the function with this name. but with this name for example VariablesOfSomething_ReAllocate()

and inside the function I will write only declarations and nothing else.. for example:
 

Func VariablesOfSomething_ReAllocate()
    Global $g_sBigString = 0, $g_aBigArray[0]
EndFunc

And now I will call this function not only to declare these variables, but only to free the RAM that they using.
This example is not the best.. think of case that you dont have 2
variables but much more.. then this way it is more safe to do this

And of course, you are supposed to call this function at the top of the script. but after that you can use this funcion also as function to free the RAM. one function doing 2 things - declare the global variables and free their memory. and one more thing - more safe since you do not have to write the same thing twice.

Func VariablesOfSomething_ReAllocate()
    Global $g_sBigString, $g_aBigArray[0]
EndFunc


VariablesOfSomething_ReAllocate() ; This time we use it to declare the variables



ReDim $g_aBigArray[6500000]

MsgBox(0,'','') ; Open task manager and see how much RAM it takes

VariablesOfSomething_ReAllocate() ;  Used also as a memory cleaning function

MsgBox(0,'','') ; Look again how much rame it takes. much less!

 

Edited by Guest
Link to comment
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
 Share

×
×
  • Create New...