Wren therefore allows overloads such as `range(stop)` and `range(start, stop)`. This is more intuitive than Python's `range(start=0, stop)`, which might be the only function in the language that has an optional parameter before a required one.
Wren therefore allows overloads such as `range(stop)` and `range(start, stop)`. This is more intuitive than Python's `range(start=0, stop)`, which might be the only function in the language that has an optional parameter before a required one.
The documentation shows it as being overloaded, rather than having default arguments:
range(stop) -> range object
range(start, stop[, step]) -> range object
There's iter which is overloaded: iter(iterable) -> iterator
iter(callable, sentinel) -> iteratorPython doesn't support overloading, and it doesn't support optional arguments before required ones, so the actual implementation in Python is a bit messy - something like:
def range(start_or_stop, optional_stop=None):
if optional_stop is None:
start = 0
stop = start_or_stop
else:
start = start_or_stop
stop = optional_stop
...it could have been implemented in pure python as well by doing args, *kwargs.
range(a) means range(start=0, end=a)
range(a, b) means range(start=a, end=b)From the call site there's no difference between Python's optional-first-argument range() function and a hypothetical overloaded one. Any perceived complexity in usage, therefore, can be fixed with better documentation.
Yep, true. Overloading is nice.