Euphoria Ticket #565: Specify when parameters are optional in function declarations.

Not stating clearly in functions declarations that a parameter is optional only leads to confusion.

Please see regular expression related functions as an example.

Details

Type: Bug Report Severity: Normal Category: Documentation
Assigned To: unknown Status: Is Valid? Reported Release:
Fixed in SVN #: View VCS: none Milestone:

1. Comment by jeremy Dec 21, 2010

Are you refering to something such as:

include std/regex.e 
namespace regex 
public function find(regex re, string haystack, integer from = 1, 
        option_spec options = DEFAULT, 
        integer size = get_ovector_size(re, 30)) 

? If so, any parameter with a default value is thus optional. Is there a different way you would like this to appear?

2. Comment by nanochip Dec 22, 2010

I think it might not be obvious for most users that parameters with a value in the declaration of the function, are optional; not to mention when one of the default values is DEFAULT as in the example.

One alternative might be, like in most languages:

public function find(regex re, string haystack 
                     [, integer from 
                     [, option_spec options 
                     [, integer size]]] 
                    ) 
 
Default values for optional parameters: from = 1 
                                        option_spec options = DEFAULT 
                                        size = get_ovector_size(re, 30) 

May be a matter of taste but I am one of those who gets confused with such declarations.

3. Comment by Shian_Lee Dec 26, 2014

I any case using square brackets [] as in the example:

    1. public function find(regex re, string haystack [, integer from [, option_spec options [, integer size]]] )
    2. #

should be avoided in my opinion.

Unlike other languages, Euphoria normally using English words instead of punctuations; and using the same punctuation [] for different purposes (sequence index and optional parameter) is something Euphoria should avoid - keyword should be used instead, something like: , option integer from, option sequence options, option integer size

Search



Quick Links

User menu

Not signed in.

Misc Menu