Declareing locals
- Otto
- Posts: 6416
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 35 times
- Been thanked: 2 times
- Contact:
Declareing locals
Hello,
what is the right way to declare locals.
Should we assign a value directly when declaring a local.
For example:
Function test
local aTemp := {}
or is local aTemp enough.
Can someone please explain the difference.
Thank you in advance and best regards
Otto
what is the right way to declare locals.
Should we assign a value directly when declaring a local.
For example:
Function test
local aTemp := {}
or is local aTemp enough.
Can someone please explain the difference.
Thank you in advance and best regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Enrico Maria Giordano
- Posts: 8770
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Declareing locals
This is a simple declaration:
local aTemp
while this other is a declaration with initialization:
local aTemp := {}
In the simple declaration the value of aTemp is NIL. After the initialization the type of aTemp is array and its value is an empty array.
EMG
local aTemp
while this other is a declaration with initialization:
local aTemp := {}
In the simple declaration the value of aTemp is NIL. After the initialization the type of aTemp is array and its value is an empty array.
EMG
- Otto
- Posts: 6416
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 35 times
- Been thanked: 2 times
- Contact:
Re: Declareing locals
Hello Enrico,
Thank you.
But what are the advantages and disadvantages of these two.
With kind regards
Otto
Thank you.
But what are the advantages and disadvantages of these two.
With kind regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Enrico Maria Giordano
- Posts: 8770
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Declareing locals
local aTemp := {}
is equivalent to
local aTemp
aTemp = {}
The advantage is that the first form is more compact, I presume.
EMG
is equivalent to
local aTemp
aTemp = {}
The advantage is that the first form is more compact, I presume.
EMG
- Otto
- Posts: 6416
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 35 times
- Been thanked: 2 times
- Contact:
Re: Declareing locals
Hello Enrico,
I read that declaration with initialization should be 3%-40% more speedy in executing the program.
Could this be?
Thank you in advance
Otto
I read that declaration with initialization should be 3%-40% more speedy in executing the program.
Could this be?
Thank you in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Enrico Maria Giordano
- Posts: 8770
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Declareing locals
Teoretically, yes. But I doubt it would make any visible difference in real programs.
EMG
EMG
Re: Declareing locals
Mr. Otto,
Testing:
Testing:
Code: Select all | Expand
FUNCTION Main()Local nILocal nMax:= 1000000Local nSec1, nSec2Local cSec1, cSec2nSec1:= Seconds()FOR nI:= 1 TO nMax Local1()NEXTcSec1:= Str(Seconds()- nSec1, 10, 5)nSec2:= Seconds()FOR nI:= 1 TO nMax Local2()NEXTcSec2:= Str(Seconds()- nSec2, 10, 5)MsgInfo("Mode 1: "+ cSec1+ Chr(13)+ Chr(13)+; "Mode 2:"+ cSec2, "Results")RETURN NILSTATIC FUNCTION Local1()Local a:= {}RETURN NILSTATIC FUNCTION Local2()Local aa:= {}RETURN NIL
- Enrico Maria Giordano
- Posts: 8770
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Has thanked: 1 time
- Been thanked: 7 times
- Contact:
Re: Declareing locals
This is NOT a real program, it is a sample. Anyway, it shows two identical values here.
EMG
EMG
- Otto
- Posts: 6416
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 35 times
- Been thanked: 2 times
- Contact:
Re: Declareing locals
Hello and thank you for your help.
I tested with these changes and see a difference in speed.
Not much but there is a difference.
Best regards
Otto
I tested with these changes and see a difference in speed.
Code: Select all | Expand
RETURN NILLocal nMax:= 10000000 STATIC FUNCTION Local1()Local a:= {}Local b:= {}Local c:= {}Local d:= {}Local e:= {}Local c1:= ""Local c2:= ""Local c3:= ""Local c4:= ""Local c5:= ""
Not much but there is a difference.
Best regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Otto
- Posts: 6416
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 35 times
- Been thanked: 2 times
- Contact:
Re: Declareing locals
Hello,
I did this yesterday and the results are the same. Declaration with initialization seams faster.
Enrico is right that in a real world program you would not see any differences.
In the same source I read that there is also speed differences between passing values by reference or value.
Best regards
Otto
I did this yesterday and the results are the same. Declaration with initialization seams faster.
Enrico is right that in a real world program you would not see any differences.
In the same source I read that there is also speed differences between passing values by reference or value.
Best regards
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************