czardas Posted April 15, 2017 Author Share Posted April 15, 2017 11 minutes ago, TheSaint said: Surely for beginners it is better to teach them to use Global at the top of their scripts. Then later on, they can learn the more intricate benefits of Local. I doubt it is better or worse. The distinction is not needed until you start writing functions. Using global variables will always have pitfalls regardless of the keyword used to declare them: the whole argument is swings and roundabouts. Reliance on global variables should be avoided if you want to learn to write good modular code (not only my opinion). operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheSaint Posted April 15, 2017 Share Posted April 15, 2017 I never said anything about reliance on Globals, but I believe in using the right declaration for the scope, and keeping it simple, especially for beginners. Using Local at the top of as script in my view, is misleading to beginners. And I don't see the issue with modular code. Global or Local, each have their place, and a beginner is a beginner ... who is just getting started. 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) Link to comment Share on other sites More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 1 minute ago, TheSaint said: I never said anything about reliance on Globals No you didn't, but therein lies the danger. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheSaint Posted April 15, 2017 Share Posted April 15, 2017 What danger? Coding is all about paying attention ... checks and balances. Declarations are no different to other aspects of coding. 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) Link to comment Share on other sites More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 (edited) There is a danger of becoming reliant on the use of global variables, there is also a greater chance of corruption occurring due to accidental reassignment. There is potential confusion about why all the help file examples are inconsistent with forum posts; and finally, you can't just dump all your old code inside a function without having to redeclare every variable you ever created. I think it's a fair trade. Edited April 15, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 If I remember correctly, isn't it impossible to declare Local variables outside functions? AutoIt automatically creates a global variable when declared out side a function regardless of the Keyword used to declare the variable. Local $vGlobalVariable = "foobar" Example() Func Example() MsgBox(0, $vGlobalVariable, $vGlobalVariable) EndFunc That code snippet works for me . 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 More sharing options...
TheSaint Posted April 15, 2017 Share Posted April 15, 2017 (edited) Years ago, coming from VB6, i used to declare most as Dim, then after a discussion by Valik and others, years ago now, I changed to Global. I only used Local, when I really needed to. That has served me well and still continues to do so, though I use Local a lot more often these days, after guinness's discussion about memory usage, which I took onboard. That said, I have always found that Local declaration often requires much more thought than Global. Global is easy, you just need to keep tab on what you use and stay unique. It is not that hard. Like I said, you just need to pay attention, and the same can be said about all other aspects of coding. EDIT By pay attention, I mean be organized, structured and methodical in the way you do things. Don't create unnecessary extra work for yourself, making it harder to keep tabs on things or find them. There should always be a sensible method in your madness. I for instance, always place my Globals at the start of my script, usually in two main sections (Controls, General), and unless it is a simple script, I never assign with a declaration. I keep things simple and alphabetical, which makes for quick checking. I favor clarity, separation and readability over cleverish shortcuts with coding. I rarely make a mistake with declarations, and in recent times it has been more with Local than Global. Edited April 15, 2017 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) Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 41 minutes ago, iamtheky said: Probably just a gist rather than a full repo, no? nope, gists are hard to manage and they have limited version control. Also, gist isn't really suited for multiple files, hard to navigate and download the required bits link to the raw code or linking to specific lines of code in a file. 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 More sharing options...
iamtheky Posted April 15, 2017 Share Posted April 15, 2017 ahh, so you have delusions of grandeur about how this will be maintained and used? proceed. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 (edited) Quite funny . I prefer to do it right when I do it, no matter how small "it" is . Edited April 15, 2017 by TheDcoder TheSaint 1 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 More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 23 minutes ago, TheDcoder said: If I remember correctly, isn't it impossible to declare Local variables outside functions? AutoIt automatically creates a global variable when declared out side a function regardless of the Keyword used to declare the variable. Local $vGlobalVariable = "foobar" Example() Func Example() MsgBox(0, $vGlobalVariable, $vGlobalVariable) EndFunc That code snippet works for me . And a good example too. Here we encounter no issues. You can also create a second (local) instance of $vGlobalVariable inside the function without encountering issues. You can't simply just use the Global keyword anywhere you want and remain within accepted norms. That's why I think that using Local gives beginners less to worry about: if anything using Global is the more complicated. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 1 minute ago, czardas said: That's why I think that using Local gives beginners less to worry about I think it would create more confusion for beginners , why encourage them to use which is not the way it works just to make sure that they use Local inside functions? The newbies use global variables, which are very easy to understand, as the newbies progress in their programming adventure, they will eventually recognize that Local variables are used inside functions... I see no problem here with using Global variables . 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 More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 (edited) It is a global variable already, but it shouldn't be: and that is the main point. Unfortunately there is no alternative other than to make the exercise more advanced. Edited April 15, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 Just now, czardas said: It is a global variable already, but it shouldn't be: and that is the main point. So are we talking about Local variables at the scope of "outside functions"? 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 More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 (edited) Yes and no! The variable is temporary and isn't needed more than once. It has no right being declared as a global variable. Edited April 15, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheSaint Posted April 15, 2017 Share Posted April 15, 2017 It's all in the name. Global means available to everything ... within or without. Local means within only. It's not rocket science, but for beginners at least, Local requires more thought. Start simple and expand your horizons. 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) Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 Just now, czardas said: The variable is temporary and isn't needed more than once. Something like this?: Global Volatile $vOneTimeUseOnly 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 More sharing options...
Moderators Melba23 Posted April 15, 2017 Moderators Share Posted April 15, 2017 TheDcoder, Volatile is only applicable to functions (as clearly stated in the Help file) and has no effect on variables. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted April 15, 2017 Author Share Posted April 15, 2017 Why do I get that funny feeling that someone's thinking of completely redrafting the Help File. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
TheDcoder Posted April 15, 2017 Share Posted April 15, 2017 (edited) Looks like you have misunderstood me Melba, I was trying to propose that as an idea, not to actually use Volatile to do what @czardas wanted Edited April 15, 2017 by TheDcoder 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now