JockoDundee Posted October 28, 2020 Share Posted October 28, 2020 Came across this in the coding practices wiki: The first example is not recommended apparently because you should choose “values that won’t change regardless of the invocation of the program.” Why is this important? Isn’t it enough that the Const won’t change during the lifetime of the variable? Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 28, 2020 Moderators Share Posted October 28, 2020 It is basically stating that, as the first example's handle can change, calling it a Const in the traditional sense is a misnomer. And thus, marking it as a Const in your script brings little to no value. As opposed to something that will definitely never change, regardless of the PC you run it on, like the second example. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Nine Posted October 28, 2020 Share Posted October 28, 2020 I think it is more of a question of understanding the code you have programmed for other ppl looking at it, or in the somehow far future for yourself. Stating whatever way of a Const, says that it should not be modified in any way within the script. I encourage usage of all the restrictions given in AutoIt to ensure proper usage of the variable definition. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
JockoDundee Posted October 28, 2020 Author Share Posted October 28, 2020 1 hour ago, JLogan3o13 said: And thus, marking it as a Const in your script brings little to no value. But isn’t the “value” of declaring something Const the immutability of the variable during execution? If the GUI is created once during the program, why not declare it Const? Its easy enough to accidentally set something to “” thru a typo, or put it on the left hand side of an expression instead of the right. These, possibly hard to debug, errors are stopped. I declare everything Const that I don’t expect to change during execution. Also what say you about the recommended usage in functions of Const By Ref when passing read only args? Are those only for arrays of literals? 2 hours ago, JLogan3o13 said: As opposed to something that will definitely never change, regardless of the PC you run it on, like the second example. Since the second example is actually something that could change, (even during execution), it may not be the best counter example. Perhaps Const $fPI=3.141592654 might be better. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
JockoDundee Posted October 28, 2020 Author Share Posted October 28, 2020 46 minutes ago, Nine said: I think it is more of a question of understanding the code you have programmed for other ppl looking at it, or in the somehow far future for yourself. That’s a fair point. And since, IMHO, the common understanding of Const is something that doesn’t change during execution, I think my usage is defensible. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
jchd Posted October 28, 2020 Share Posted October 28, 2020 1 minute ago, JockoDundee said: I think my usage is defensible. 100% 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Moderators JLogan3o13 Posted October 29, 2020 Moderators Share Posted October 29, 2020 (edited) 3 hours ago, JockoDundee said: Since the second example is actually something that could change, (even during execution), it may not be the best counter example. Perhaps Const $fPI=3.141592654 might be better. I agree wholeheartedly the second example is not one I would use. Give me the speed of light or something a true constant. I didn't write that entry, however Edited October 29, 2020 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
water Posted October 29, 2020 Share Posted October 29, 2020 I added some text to the example and replaced $iMyAge with $fPi as recommended My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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