• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Discussion [SUGGESTION] Named arguments in functions!

As we are starting to use JSDoc to document functions, to set a type/name/description to params... what about using that information to automatically naming the arguments? and even set default values!!

Code:
/// @description Function test
/// @param {string} [somebody=John Doe] - Somebody's name.
/// @param {real} [number=232] - Somebody's name.
this would make argument[0] be optional, named "somebody" (as local var), and set its default value to "John Doe" if it's missing!
this could even be done like before compiling (like macros).

the above documentation would be translated into:

Code:
var somebody = argument_count > 0 ? argument[0] : "John Doe";
var number = argument_count > 1 ? argument[1] : 232;
I could be very very very wrong but I think this is pretty easy to do... (and as the JSDoc is already interpreted by the editor... it could add the local variables to the autocomplete). even the param type real/string is there and could be used!!

Non-optional params would translate into:

Code:
var non_optional = argument[0];
just needed to add some "keywords" to represent defaults like undefined and noone.
What do you think!?!?
 
Last edited:

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
There should be at least several more topics about the subject on the sub-forum.

The suggested method is brought up the most commonly, but I don't think it's the right way, as suddenly giving "some" comments functional meaning is a bad tone.

Ideally there should be some declarative syntax for scripts (like function name(arg1, arg2 = value, ?arg3) in some other languages), but it doesn't look like things are heading this way at the moment.
 
There should be at least several more topics about the subject on the sub-forum.

The suggested method is brought up the most commonly, but I don't think it's the right way, as suddenly giving "some" comments functional meaning is a bad tone.

Ideally there should be some declarative syntax for scripts (like function name(arg1, arg2 = value, ?arg3) in some other languages), but it doesn't look like things are heading this way at the moment.
I just suggested this because the JSDoc is a standard and already has a well defined structured... and YoYo chose to use this kind of documentation for some reason.

Even an external 3rd party tool could do this... (lets call it) parsing.

The other suggestion on the forum was also made by me (if I'm not wrong) :) but in that time I got no answer at all (kinda like this time :p )
 
Last edited:
Top