pixelsearch Posted March 7, 2022 Share Posted March 7, 2022 Hi everybody There is something I don't understand concerning the Default keyword. Help file, topic "Language Reference - Datatypes" : Default : Only used for assigning a default value to optional arguments of a function. Help file, topic "Default" : When used in parameter passing, the behavior is specified in the corresponding AutoIt function documentation. For UDF's, it is the scripter's responsibility to check if the parameter has been set to Default and to perform the desired behavior in this situation. If used, the passed parameter will be set to the Default keyword and not to an optional parameter value, if defined. My question is : wouldn't it be much simpler to let AutoIt match the Default keyword to an optional parameter, instead of forcing the scripter to add numerous useless lines (one per optional parameter) for the same result ? For example, when I scripted SortAll.au3 UDF, it had to be created like this... Func SortAll(ByRef $aArray, $iSortCol = 0, $iType = 2, $iSense = 0, $iStable = 0) If $iSortCol = Default Then $iSortCol = 0 ; first column = 0 If $iType = Default Then $iType = 2 ; 0 = String sort, 1 = Numeric sort, 2 = Natural sort If $iSense = Default Then $iSense = 0 ; 0 = ascending, 1 = descending If $iStable = Default Then $iStable = 0 ; 0 = unstable sort, 1 = stable sort If Not IsArray($aArray) Then ... ...when it would have been much simpler to create it like that : Func SortAll(ByRef $aArray, $iSortCol = 0, $iType = 2, $iSense = 0, $iStable = 0) If Not IsArray($aArray) Then ... For the record, Valik, in this old link, was already concerned with the Default keyword, this is what he wrote : "Default should never compare true to a boolean, neither true nor false. Default should only compare true to -1, "" and Default itself." Then he immediately opened trac ticket #885, was not happy with the result ("This is not fixed in the way that I want."), had a discussion with wise @jpm then admitted "Default should only compare true to Default". This being established, after that, I don't know who forced UDF scripters to match by themselves the Default keyword to each optional parameter. And you better not forget 1 matching line in any UDF ! Link to comment Share on other sites More sharing options...
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
Already have an account? Sign in here.Sign In Now