gil900

What is the point of the key "Default" if it have 0 effect?

3 posts in this topic

#1 ·  Posted (edited)

 

This

Test(Default)

Func Test($var = 10)
    ConsoleWrite($var & @CRLF)
EndFunc

 

Will print "Default" and not 10.

Due to this, There is no any logic why make it look "special". Unless it will realy actually prints 10 without any additional code.

Otherwise it's just like any regular string.

Why you did not make it so it will naturally get the Default value?

Edited by gil900

Share this post


Link to post
Share on other sites



gil900,

Of course it prints "10" - there is a big difference between the Default keyword as a parameter and a default parameter in a function definition.

The Default keyword as a parameter tells the function that the user wishes the parameter to use whatever the function defines internally as a default value, which must be set programmatically within the function. A default parameter in a function definition tells the function what to use if that parameter is omitted when the function is called. So in the example you give, the parameter is set to Default keyword - and that is what the function receives to do with as it sees fit. If you omit the parameter when calling the function it will use the default value for that parameter which is defined as 10.

To me the difference between these two behaviours is so obvious that I am struggling to see how it can possibly be unclear to others.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Agreed.  As per the help file,
" 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. "

Share this post


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