Deathmare zadoq
Registered User
Join date: 11 Oct 2004
Posts: 15
|
11-24-2005 14:19
I saw this in a couple compiler languages and it would just be a simple addon to LSL compiler ( http://secondlife.com/vote/index.php?get_id=754 ). LSL Compiler should feature selfdefinable constants, as it is at the moment you need variables to define something similar, just to predefine a constant for one or multiple positions in the script and those need additional script memory. A constant ( kinda like "PI" ) would just be at the placeholder position where the constant name is used ! Normaly you have something like this : float Timer_Delay = 10.0; .. llSetTimerEvent( Timer_Delay ); .. Now what is this, you used a "Variable" to define one integer that is never even changed in the script, just so you didnt need to search the script for the function to change the number. Why not something more like this : C_float Timer_Delay = 10.0; .. llSetTimerEvent( Timer_Delay ); .. Now we would have a "Constant" ( actually i am not sure if we really would need to define it as Float or any other type as the following data defines the type allready ). Whats the difference : the constant is only something needet for the Compiler, he would compile the real number of "Timer_Delay" just to all positions were it is used in the script. The value of the constant isnt changeable in the running script as a Variable would be, but it wouldnt need additional memory !.
|
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
|
11-25-2005 07:49
From: Deathmare zadoq Now what is this, you used a "Variable" to define one integer that is never even changed in the script, just so you didnt to search the script for the function to change the number. From the point of view of syntax, I would suggest adding a keyword "constant" that tells the compiler the variable's value doesn't change, and to raise a flag if it sees an assignment to it. The compiler could actually perform this optimization itself, because by the end of the file it knows whether any variable is modified. Personally, I'd rather they added compile-time evaluation of constant expressions first, so you could write something like: vector omega = <0,0,PI/2>; at the top level. That would actually make defined constants semantically useful, rather than just being an optimization they could perform themselves. That would also let them quit greedy-parsing negative numbers, and using compile time constant evaluation instead, so that "a-1" would stop being a syntax error.
|
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
|
11-25-2005 08:08
I generally advocate not using constants like this. If you are reading through a piece of code and find "llSetTimerEvent( Timer_Delay );" you do not know, without having to scroll to the top of the code, whether this is a short, medium or long delay. Scrolling to the top breaks the flow-of-understanding one tries to achieve while maintaining code. Looked at from the other side, a constant named "Timer_delay" at the top of a file means very little. - If the value needs to be changed for different environments, and you are going to be giving/selling the script to others (who may not have mod rights, or scripting knowledge) consider using a configuration notecard.
- If the constant is being used in one or two places, and is unlikely to change much, or at all, insert it as a literal (llSetTimerEvent( 10.0 ); is a lot easier to grok).
- If the constatnt is going to be used in many places within the script, AND you need to change it now and then, AND you are the one who will be changing it - then define a constant up front - but give it its "business name". Call it "StandingTimeAtStation" rather than "Timer_delay"
|
Deathmare zadoq
Registered User
Join date: 11 Oct 2004
Posts: 15
|
11-25-2005 08:50
Actually the naming was just an example  personaly in my scripts i use more describing names and i comment them. For me personally i think defining a constant is alot easer then writing the numbers somewhere in a script at multiple positions, alot easer to find. However each its own, i am just wondering that this type isnt in LSL as its pretty common in Compiler languages.
|