Jump to content

Why use Local and Global at all?


WRP
 Share

Recommended Posts

You still have to understand scope in other languages. AutoIt is kind enough to provide you keywords where you can in theory define a global variable inside a function (awful though).

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

4 hours ago, gil900 said:

This is one effort that you must do at the include stage/step. This is compared to more then one effort that you must do if you don't do it (write always Local ... in functions )

Well I generally write stuff I might use again in the future.

Link to comment
Share on other sites

On 4/10/2016 at 8:23 PM, czardas said:

If you intend to combine your scripts with those written by other people, then the available name choices for local variables will be restricted if any of the libraries contain global variables. Then there is the annoyance of having to track down the bugs that are more likely to occur. Additionally your code would be potentially unstable and therefore unsuitable for others to use for these exact same reasons. In many ways it's a non-starter, or rather badly written code.

It's not something to worry too much about when you are an absolute beginner, but as soon as you learn some basics of programming, you should start to improve the way you write code. In the long term, you will benefit more from having made the extra effort.

This seems like an example where the $g_ convention helps a lot. None of the globals will conflict with locals if the $g_ is followed.

Link to comment
Share on other sites

Yes naming conventions help the development process, but it's not enough to put trust in this method alone. Program stability comes with well thought out design and several language features exist which also act as a kind of safety net. Ignoring convention often comes at a price and should never be done without good reason. Having to do less typing is not a good enough reason to avoid declaring the scope of a variable. I can only think of one or two scenarios where doing this could be considered acceptable, and they have very little to do with writing a program for others to use: I did it myself (earlier in this thread) as an example of badly written code.

Edited by czardas
Link to comment
Share on other sites

I believe this has already been posted and reiterated on this topic, but aside from any functionality issues, it is just good coding practice.

First, if you make a mistake and declare a Global or Local variable in the wrong place it is easier to identify. Also, there is a lot less confusion in the code, especially when a code you've written is being used or modified by someone else. I mean, even if you came back to your own code after a while to add to it or modify it everything is clearer when Local and Global are used. 

I mean, lets say you took the same approach to variable names. You can name your variables anything, so functionally there is no reason to use long names. If you named all your variables a single letter in alphabetical order as you use them in your code it would function fine, but you or anyone else would have a terrible time working with it. Convention is important in coding as well as functionality.

Link to comment
Share on other sites

If this is so good, why it does not exist in C++ or other languages? According to most approaches here, this feature should be considered to be realized in other languages.
But it did not happen. maybe other languages people think that this is unnecessary or not important enough?

Edited by Guest
Link to comment
Share on other sites

Quote

Pullum argued that the fact that number of word roots for snow is similar in Eskimoan languages and English proves that there exists no difference in the breadth of their respective vocabularies to define snow.

https://en.wikipedia.org/wiki/Eskimo_words_for_snow

Edited by czardas
Link to comment
Share on other sites

Is that for Global or Local snow?

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

20 minutes ago, czardas said:

Does it matter? It's 180 different shades of white. :blink:

I have heard that book is 3.6x cleaner than 50 Shades of Grey. 

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

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...