Jump to content

Not understanding the wiki with regards to Const


Recommended Posts

Came across this in the coding practices wiki:

B2067ABA-D73A-4956-B3A9-82213EE80E5D.thumb.jpeg.9a8a7f86097cd8c47e9abf30882986b2.jpeg

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 post
Share on other sites
  • Moderators

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 post
Share on other sites

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.

Link to post
Share on other sites
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 post
Share on other sites
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 post
Share on other sites
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 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 post
Share on other sites
  • Moderators
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 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 post
Share on other sites

I added some text to the example and replaced $iMyAge with $fPi as recommended :)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...