On Friday, 11 May 2018 at 14:26:21 UTC, Jonathan M Davis wrote:
On Thursday, May 10, 2018 14:15:18 Yuxuan Shui via
Digitalmars-d wrote:
So in D I can use default argument like this:
[...]
Is this a good idea?
It seems like really risky move, honestly, because it means
that the function is then affected by what is and isn't
declared within the scope where it's called. __FILE__ and
__LINE__ are well-defined as to what they mean. No can declare
them to mean something else. You don't have symbol resolution
issues or naming conflicts. And they're solving a problem that
can't actually be solved without compiler help. However, if you
just want to change what arguments get passed to foo within
your module, all you have to do is define another foo inside
the module and have it forward to the original one with
whatever arguments you want. What you're suggesting here seems
to introduce name pollution issues without solving anything
that can't easily be solved with the language as-is.
- Jonathan M Davis
I see what you're saying and I agree with you. I think a better
way would be to try and extend the `with` syntax to work with
arbitrary functions, rather than only objects. That would make it
more useful. So something like:
---
void f1(allocator alloc, ...){}
void f2(allocator alloc, ...){}
...
void fn(allocator alloc, ...){}
void main()
{
with(MyAllocator) {
f1(...);
f2(...);
...
fn(...);
}
}
---