Jump to content

Recommended Posts

Posted (edited)

I just thought of this... Do Constants and Variables have any differences other than Constants cannot be changed? I know that Python does not have such things like Constants... But is there a difference between them? any advantages when using Constants whenever we can?

The uses of Constants which I have discovered so far are:

  1. Coding practices (You know what things are not supposed to be changed while the program is running).
  2. Preventing code from modifying their value.

So, is there anything more than what meets the eye? I think the developers of AutoIt can answer this question.

Edited by TheDcoder
Minor Sentence Edit

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

Posted
  On 6/2/2016 at 2:22 PM, TheDcoder said:
  • Coding practices (You know what things are not supposed to be changed while the program is running).
  • Coding practices - Magic Number prevention + readability
  • Creating a more agile code, easy to change management/development concept.
  • Preventing code from modifying their value.
Expand  

just my 2c

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

A smart compiler can optimise memory storage better if it knows in advance that a particular subset of variables will not ever be resized. This can reduce fragmentation of virtual memory.

Posted

@RTFC I'ts interesting.
 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/3/2016 at 7:41 AM, JohnOne said:

Those 2 are no different than variables.

Expand  

Yes but 2 can be used secure only with 4.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/3/2016 at 8:39 AM, RTFC said:

A smart compiler can optimise memory storage better if it knows in advance that a particular subset of variables will not ever be resized. This can reduce fragmentation of virtual memory.

Expand  

I know that those compilers convert the code to native machine code.... I know that our aut2exe does not do that :o. But AutoIt3Wrapper made by @Jos has an option to replace constants with their actual value... That might be somewhat of an advantage but its very useless if that constant is not hard coded in the script! (Like Control IDs of Controls in a GUI).

  On 6/3/2016 at 8:48 AM, mLipok said:

Yes but 2 can be used secure only with 4.

Expand  

I don't get what you are trying to say :unsure:.

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

Posted

Yeah, Jos based the idea on PreExpand.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

From my perspective there are two types of constant: artificial constants and real constants. Real constants are things like Pi, and artificial constants are based on design choices - for example magic numbers by Microsoft. @RTFC makes a good point which I hadn't considered. Although it appears to make sense. I'm not sure if this is the case with AutoIt. It may well be that using the Const keyword actually slows down the script by a very tiny amount, although you would hardly notice any difference. Hard coded values will probably always have a slight edge over variables, which is why @guinness created PreExpand. You should always use the Const keyword for constants. It's good style and prevents corruption.

Edited by czardas
Posted
  On 6/4/2016 at 10:14 AM, czardas said:

It may well be that using the Const keyword actually slows down the script by a very tiny amount, although you would hardly notice any difference.

Expand  

Its the same case when we declare a variable too I think.

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

Posted
  On 6/4/2016 at 5:42 AM, TheDcoder said:

@guinness Do you have access to AutoIt's code? If yes, how does AutoIt handle constants?

Expand  

Yes, though I haven't really looked in that code if I am honest.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  On 6/5/2016 at 4:03 AM, TheDcoder said:

Oh :o

Expand  

Even if I did, I don't know how much I can divulge about the internals.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
  Quote

Hard coded values will probably always have a slight edge over variables

Expand  
  Quote

It may well be that using the Const keyword actually slows down the script by a very tiny amount

Expand  

 

So, in conclusion, magic numbers save milliseconds. :)

  Reveal hidden contents

Posted

Seems this is all speculation right now. I prefer benchmarking over rumours.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
×
×
  • Create New...